Skip to content

Commit

Permalink
Changed thread_local to ZX_THREAD_LOCAL (zxing-cpp#889)
Browse files Browse the repository at this point in the history
Change `thread_local` to `ZX_THREAD_LOCAL` so it can be disabled centrally (as it used to).
  • Loading branch information
MonkeybreadSoftware authored Jan 10, 2025
1 parent dff7da1 commit 149c40a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/src/GlobalHistogramBinarizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "BitMatrix.h"
#include "Pattern.h"
#include "ZXConfig.h"

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -115,7 +116,7 @@ bool GlobalHistogramBinarizer::getPatternRow(int row, int rotation, PatternRow&
// during the histogram calculation and during the sharpen+threshold operation. Additionally, if we
// perform the ThresholdSharpened function on pixStride==1 data, the auto-vectorizer makes that part
// 8x faster on an AVX2 cpu which easily recovers the extra cost that we pay for the copying.
thread_local std::vector<uint8_t> line;
ZX_THREAD_LOCAL std::vector<uint8_t> line;
if (std::abs(buffer.pixStride()) > 4) {
line.resize(lineView.size());
std::copy(lineView.begin(), lineView.end(), line.begin());
Expand All @@ -127,7 +128,7 @@ bool GlobalHistogramBinarizer::getPatternRow(int row, int rotation, PatternRow&
if (threshold <= 0)
return false;

thread_local std::vector<uint8_t> binarized;
ZX_THREAD_LOCAL std::vector<uint8_t> binarized;
// the optimizer can generate a specialized version for pixStride==1 (non-rotated input) that is about 8x faster on AVX2 hardware
if (lineView.begin().stride == 1)
ThresholdSharpened(lineView, threshold, binarized);
Expand Down
1 change: 1 addition & 0 deletions core/src/ZXConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// in e.g. the ReedSolomonDecoder. It is disabled by default. It can be enabled by modifying the following define.
// Note: The Apple clang compiler until XCode 8 does not support c++11's thread_local.
// The alternative 'static' makes the code thread unsafe.
// for Windows in Visual Studio 2019 on Intel 64-bit using thread_local causes a dependency to VCRUNTIME140_1.dll, so you need 2019 runtime DLLs instead of only 2015 version.
#define ZX_THREAD_LOCAL thread_local // '' (nothing), 'thread_local' or 'static'

// The Galoir Field abstractions used in Reed-Solomon error correction code can use more memory to eliminate a modulo
Expand Down
3 changes: 2 additions & 1 deletion core/src/ZXingC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ZXingC.h"

#include "ZXingCpp.h"
#include "ZXConfig.h"

#if __has_include("Version.h")
#include "Version.h"
Expand All @@ -22,7 +23,7 @@

using namespace ZXing;

static thread_local std::string lastErrorMsg;
static ZX_THREAD_LOCAL std::string lastErrorMsg;
static Barcodes emptyBarcodes{}; // used to prevent new heap allocation for each empty result

template<typename R, typename T> R transmute_cast(const T& v) noexcept
Expand Down

0 comments on commit 149c40a

Please sign in to comment.