Skip to content

Commit 86cfacc

Browse files
committed
Deprecates SPM_NO_THREADLOCAL mode
1 parent 575326a commit 86cfacc

File tree

4 files changed

+2
-40
lines changed

4 files changed

+2
-40
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ option(SPM_ENABLE_SHARED "Builds shared libaries in addition to static libraries
2727
option(SPM_BUILD_TEST "Builds test binaries." OFF)
2828
option(SPM_ENABLE_TCMALLOC "Enable TCMalloc if available." ON)
2929
option(SPM_TCMALLOC_STATIC "Link static library of TCMALLOC." OFF)
30-
option(SPM_NO_THREADLOCAL "Disable thread_local operator" OFF)
3130
option(SPM_ENABLE_MSVC_MT_BUILD, "Use /MT flag in MSVC build" OFF)
3231
option(SPM_CROSS_SYSTEM_PROCESSOR, "Override system processor" "")
3332
option(SPM_DISABLE_EMBEDDED_DATA, "Disable to embed pre-compiled data." OFF)

src/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ set_target_properties(sentencepiece_train-static PROPERTIES OUTPUT_NAME "sentenc
251251

252252
if (NOT MSVC)
253253
set(CMAKE_CXX_FLAGS "-O3 -Wall -fPIC ${CMAKE_CXX_FLAGS}")
254-
if (SPM_NO_THREADLOCAL)
255-
add_definitions(-DSPM_NO_THREADLOCAL=1)
256-
add_definitions(-DGOOGLE_PROTOBUF_NO_THREADLOCAL=1)
257-
endif()
258254
set_source_files_properties(
259255
sentencepiece.pb.cc sentencepiece_model.pb.cc
260256
PROPERTIES COMPILE_FLAGS "-Wno-misleading-indentation")

src/util.cc

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -179,35 +179,6 @@ std::string UnicodeTextToUTF8(const UnicodeText &utext) {
179179
} // namespace string_util
180180

181181
namespace random {
182-
#ifdef SPM_NO_THREADLOCAL
183-
namespace {
184-
class RandomGeneratorStorage {
185-
public:
186-
RandomGeneratorStorage() {
187-
pthread_key_create(&key_, &RandomGeneratorStorage::Delete);
188-
}
189-
virtual ~RandomGeneratorStorage() { pthread_key_delete(key_); }
190-
191-
std::mt19937 *Get() {
192-
auto *result = static_cast<std::mt19937 *>(pthread_getspecific(key_));
193-
if (result == nullptr) {
194-
result = new std::mt19937(GetRandomGeneratorSeed());
195-
pthread_setspecific(key_, result);
196-
}
197-
return result;
198-
}
199-
200-
private:
201-
static void Delete(void *value) { delete static_cast<std::mt19937 *>(value); }
202-
pthread_key_t key_;
203-
};
204-
} // namespace
205-
206-
std::mt19937 *GetRandomGenerator() {
207-
static RandomGeneratorStorage *storage = new RandomGeneratorStorage;
208-
return storage->Get();
209-
}
210-
#else
211182
std::mt19937 *GetRandomGenerator() {
212183
// Thread-locals occupy stack space in every thread ever created by the
213184
// program, even if that thread never uses the thread-local variable.
@@ -222,7 +193,6 @@ std::mt19937 *GetRandomGenerator() {
222193
std::make_unique<std::mt19937>(GetRandomGeneratorSeed());
223194
return mt.get();
224195
}
225-
#endif
226196
} // namespace random
227197

228198
namespace util {

src/util.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
#include "sentencepiece_processor.h"
3333
#include "third_party/absl/strings/string_view.h"
3434

35-
#ifdef SPM_NO_THREADLOCAL
36-
#include <pthread.h>
37-
#endif
38-
3935
namespace sentencepiece {
4036
template <typename T>
4137
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
@@ -314,7 +310,8 @@ class ReservoirSampler {
314310
public:
315311
explicit ReservoirSampler(std::vector<T> *sampled, uint64_t size)
316312
: sampled_(sampled), size_(size), engine_(GetRandomGeneratorSeed()) {}
317-
explicit ReservoirSampler(std::vector<T> *sampled, uint64_t size, uint64_t seed)
313+
explicit ReservoirSampler(std::vector<T> *sampled, uint64_t size,
314+
uint64_t seed)
318315
: sampled_(sampled), size_(size), engine_(seed) {}
319316
virtual ~ReservoirSampler() {}
320317

0 commit comments

Comments
 (0)