This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch clucene in repository https://gitbox.apache.org/repos/asf/doris-thirdparty.git
The following commit(s) were added to refs/heads/clucene by this push: new b7e3279 [Fix](clucene) fix some problems finding in multi-thread enviroment (#31) b7e3279 is described below commit b7e327911033428d49f74554d49865a9a92ced3f Author: airborne12 <airborn...@gmail.com> AuthorDate: Fri Feb 17 21:15:20 2023 +0800 [Fix](clucene) fix some problems finding in multi-thread enviroment (#31) 1. fix thread-local problem to adapt bthread-context 2. fix multi-thread global variable conflicts problem. 3. enhance chinese analyzer --- src/contribs-lib/CMakeLists.txt | 6 +- src/core/CLucene/index/IndexFileNameFilter.cpp | 21 +++--- src/core/CLucene/index/IndexFileNames.cpp | 16 ++--- src/core/CLucene/index/SegmentInfos.cpp | 6 +- src/core/CLucene/index/SegmentMerger.cpp | 10 +-- src/core/CLucene/index/_IndexFileNameFilter.h | 2 +- src/core/CLucene/index/_IndexFileNames.h | 92 ++++++++++++++------------ src/core/CLucene/util/ThreadLocal.cpp | 90 ++++++++++++++++++++++--- src/core/CMakeLists.txt | 14 +++- src/shared/CLucene/LuceneThreads.h | 13 +++- src/shared/CLucene/config/_threads.h | 2 +- src/shared/CLucene/config/threads.cpp | 10 ++- src/shared/CMakeLists.txt | 14 +++- 13 files changed, 210 insertions(+), 86 deletions(-) diff --git a/src/contribs-lib/CMakeLists.txt b/src/contribs-lib/CMakeLists.txt index d61a436..df959fe 100644 --- a/src/contribs-lib/CMakeLists.txt +++ b/src/contribs-lib/CMakeLists.txt @@ -78,7 +78,11 @@ SET(clucene_contribs_Files ./CLucene/snowball/src_c/stem_UTF_8_swedish.c ./CLucene/analysis/jieba/ChineseTokenizer.cpp ) -SET ( clucene_contrib_extra_libs clucene-core clucene-shared ${EXTRA_LIBS}) +IF (BUILD_STATIC_LIBRARIES) + SET ( clucene_contrib_extra_libs clucene-core-static clucene-shared-static ${EXTRA_LIBS}) +ELSE() + SET ( clucene_contrib_extra_libs clucene-core clucene-shared ${EXTRA_LIBS}) +ENDIF() #find our headers file(GLOB_RECURSE HEADERS ${clucene-contribs-lib_SOURCE_DIR}/*.h) diff --git a/src/core/CLucene/index/IndexFileNameFilter.cpp b/src/core/CLucene/index/IndexFileNameFilter.cpp index 6dec143..3a2f568 100644 --- a/src/core/CLucene/index/IndexFileNameFilter.cpp +++ b/src/core/CLucene/index/IndexFileNameFilter.cpp @@ -13,24 +13,25 @@ CL_NS_DEF(index) FilenameFilter::~FilenameFilter(){ } -IndexFileNameFilter* IndexFileNameFilter::_singleton = NULL; -IndexFileNameFilter* IndexFileNameFilter::singleton(){ - if ( _singleton == NULL ) - _singleton = _CLNEW IndexFileNameFilter(); - return _singleton; +//IndexFileNameFilter* IndexFileNameFilter::_singleton = NULL; +IndexFileNameFilter *IndexFileNameFilter::singleton() { + static IndexFileNameFilter _singleton = IndexFileNameFilter(); + //if ( _singleton == NULL ) + // _singleton = _CLNEW IndexFileNameFilter(); + return &_singleton; } void IndexFileNameFilter::_shutdown(){ - _CLDELETE(_singleton); + //_CLDELETE(_singleton); } IndexFileNameFilter::IndexFileNameFilter() { size_t i; - for ( i = 0; i < IndexFileNames::INDEX_EXTENSIONS().length; ++i) { - extensions.insert(IndexFileNames::INDEX_EXTENSIONS()[i]); + for ( i = 0; i < IndexFileNames::GetInstance().INDEX_EXTENSIONS().length; ++i) { + extensions.insert(IndexFileNames::GetInstance().INDEX_EXTENSIONS()[i]); } - for ( i = 0; i < IndexFileNames::INDEX_EXTENSIONS_IN_COMPOUND_FILE().length; ++i) { - extensionsInCFS.insert(IndexFileNames::INDEX_EXTENSIONS_IN_COMPOUND_FILE()[i]); + for ( i = 0; i < IndexFileNames::GetInstance().INDEX_EXTENSIONS_IN_COMPOUND_FILE().length; ++i) { + extensionsInCFS.insert(IndexFileNames::GetInstance().INDEX_EXTENSIONS_IN_COMPOUND_FILE()[i]); } } IndexFileNameFilter::~IndexFileNameFilter(){ diff --git a/src/core/CLucene/index/IndexFileNames.cpp b/src/core/CLucene/index/IndexFileNames.cpp index 4217240..a2c736b 100644 --- a/src/core/CLucene/index/IndexFileNames.cpp +++ b/src/core/CLucene/index/IndexFileNames.cpp @@ -54,7 +54,7 @@ CL_NS_DEF(index) }; CL_NS(util)::ConstValueArray<const char*> IndexFileNames::_INDEX_EXTENSIONS; - CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::INDEX_EXTENSIONS(){ + const CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::INDEX_EXTENSIONS(){ if ( _INDEX_EXTENSIONS.length == 0 ){ _INDEX_EXTENSIONS.values = IndexFileNames_INDEX_EXTENSIONS_s; _INDEX_EXTENSIONS.length = 15; @@ -76,7 +76,7 @@ CL_NS_DEF(index) IndexFileNames::NORMS_EXTENSION }; CL_NS(util)::ConstValueArray<const char*> IndexFileNames::_INDEX_EXTENSIONS_IN_COMPOUND_FILE; - CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::INDEX_EXTENSIONS_IN_COMPOUND_FILE(){ + const CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::INDEX_EXTENSIONS_IN_COMPOUND_FILE(){ if ( _INDEX_EXTENSIONS_IN_COMPOUND_FILE.length == 0 ){ _INDEX_EXTENSIONS_IN_COMPOUND_FILE.values = IndexFileNames_INDEX_EXTENSIONS_IN_COMPOUND_FILE_s; _INDEX_EXTENSIONS_IN_COMPOUND_FILE.length = 11; @@ -92,7 +92,7 @@ CL_NS_DEF(index) IndexFileNames::FIELDS_EXTENSION }; CL_NS(util)::ConstValueArray<const char*> IndexFileNames::_STORE_INDEX_EXTENSIONS; - CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::STORE_INDEX_EXTENSIONS(){ + const CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::STORE_INDEX_EXTENSIONS(){ if ( _STORE_INDEX_EXTENSIONS.length == 0 ){ _STORE_INDEX_EXTENSIONS.values = IndexFileNames_STORE_INDEX_EXTENSIONS_s; _STORE_INDEX_EXTENSIONS.length = 5; @@ -109,7 +109,7 @@ CL_NS_DEF(index) IndexFileNames::NORMS_EXTENSION }; CL_NS(util)::ConstValueArray<const char*> IndexFileNames::_NON_STORE_INDEX_EXTENSIONS; - CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::NON_STORE_INDEX_EXTENSIONS(){ + const CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::NON_STORE_INDEX_EXTENSIONS(){ if ( _NON_STORE_INDEX_EXTENSIONS.length == 0 ){ _NON_STORE_INDEX_EXTENSIONS.values = IndexFileNames_NON_STORE_INDEX_EXTENSIONS_s; _NON_STORE_INDEX_EXTENSIONS.length = 6; @@ -127,7 +127,7 @@ CL_NS_DEF(index) IndexFileNames::TERMS_EXTENSION }; CL_NS(util)::ConstValueArray<const char*> IndexFileNames::_COMPOUND_EXTENSIONS; - CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::COMPOUND_EXTENSIONS(){ + const CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::COMPOUND_EXTENSIONS(){ if ( _COMPOUND_EXTENSIONS.length == 0 ){ _COMPOUND_EXTENSIONS.values = IndexFileNames_COMPOUND_EXTENSIONS_s; _COMPOUND_EXTENSIONS.length = 7; @@ -141,7 +141,7 @@ CL_NS_DEF(index) IndexFileNames::VECTORS_FIELDS_EXTENSION }; CL_NS(util)::ConstValueArray<const char*> IndexFileNames::_VECTOR_EXTENSIONS; - CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::VECTOR_EXTENSIONS(){ + const CL_NS(util)::ConstValueArray<const char*>& IndexFileNames::VECTOR_EXTENSIONS(){ if ( _VECTOR_EXTENSIONS.length == 0 ){ _VECTOR_EXTENSIONS.values = IndexFileNames_VECTOR_EXTENSIONS_s; _VECTOR_EXTENSIONS.length = 3; @@ -168,8 +168,8 @@ CL_NS_DEF(index) if ( p != NULL && strcmp( p+1, COMPOUND_FILE_STORE_EXTENSION ) == 0 ) { return true; } - for ( int32_t i = 0; i < STORE_INDEX_EXTENSIONS().length; i++ ) { - if ( p != NULL && strcmp( p+1, STORE_INDEX_EXTENSIONS()[i] ) == 0 ) { + for ( int32_t i = 0; i < GetInstance().STORE_INDEX_EXTENSIONS().length; i++ ) { + if ( p != NULL && strcmp( p+1, GetInstance().STORE_INDEX_EXTENSIONS()[i] ) == 0 ) { return true; } } diff --git a/src/core/CLucene/index/SegmentInfos.cpp b/src/core/CLucene/index/SegmentInfos.cpp index 00ae628..6d1f52d 100644 --- a/src/core/CLucene/index/SegmentInfos.cpp +++ b/src/core/CLucene/index/SegmentInfos.cpp @@ -206,7 +206,7 @@ string SegmentInfo::segString(Directory* dir) { if (useCompoundFile) { _files.push_back( string(name) + "." + IndexFileNames::COMPOUND_FILE_EXTENSION); } else { - ConstValueArray<const char*>& exts = IndexFileNames::NON_STORE_INDEX_EXTENSIONS(); + const ConstValueArray<const char*>& exts = IndexFileNames::GetInstance().NON_STORE_INDEX_EXTENSIONS(); for(size_t i=0;i<exts.length;i++){ addIfExists(_files, name + "." + exts[i]); } @@ -220,14 +220,14 @@ string SegmentInfo::segString(Directory* dir) { if (docStoreIsCompoundFile) { _files.push_back(docStoreSegment + "." + IndexFileNames::COMPOUND_FILE_STORE_EXTENSION); } else { - ConstValueArray<const char *> &exts = IndexFileNames::STORE_INDEX_EXTENSIONS(); + const ConstValueArray<const char *> &exts = IndexFileNames::GetInstance().STORE_INDEX_EXTENSIONS(); for (size_t i = 0; i < exts.length; i++) addIfExists(_files, docStoreSegment + "." + exts[i]); } } else if (!useCompoundFile) { // We are not sharing, and, these files were not // included in the compound file - ConstValueArray<const char *> &exts = IndexFileNames::STORE_INDEX_EXTENSIONS(); + const ConstValueArray<const char *> &exts = IndexFileNames::GetInstance().STORE_INDEX_EXTENSIONS(); for (size_t i = 0; i < exts.length; i++) addIfExists(_files, name + "." + exts[i]); } diff --git a/src/core/CLucene/index/SegmentMerger.cpp b/src/core/CLucene/index/SegmentMerger.cpp index 284ee26..cc910b0 100644 --- a/src/core/CLucene/index/SegmentMerger.cpp +++ b/src/core/CLucene/index/SegmentMerger.cpp @@ -150,13 +150,13 @@ void SegmentMerger::createCompoundFile(const char* filename, std::vector<std::st bool ownFiles = false; if ( files == NULL ){ files = new vector<string>; - files->reserve(IndexFileNames::COMPOUND_EXTENSIONS().length + 1); + files->reserve(IndexFileNames::GetInstance().COMPOUND_EXTENSIONS().length + 1); ownFiles = true; } // Basic files - for (int32_t i = 0; i < IndexFileNames::COMPOUND_EXTENSIONS().length; i++) { - const char* ext = IndexFileNames::COMPOUND_EXTENSIONS()[i]; + for (int32_t i = 0; i < IndexFileNames::GetInstance().COMPOUND_EXTENSIONS().length; i++) { + const char* ext = IndexFileNames::GetInstance().COMPOUND_EXTENSIONS()[i]; if (mergeDocStores || (strcmp(ext,IndexFileNames::FIELDS_EXTENSION) != 0 && strcmp(ext,IndexFileNames::FIELDS_INDEX_EXTENSION) != 0 ) ){ files->push_back ( string(segment) + "." + ext ); @@ -174,8 +174,8 @@ void SegmentMerger::createCompoundFile(const char* filename, std::vector<std::st // Vector files if ( mergeDocStores && fieldInfos->hasVectors()) { - for (int32_t i = 0; i < IndexFileNames::VECTOR_EXTENSIONS().length; i++) { - files->push_back ( segment + "." + IndexFileNames::VECTOR_EXTENSIONS()[i] ); + for (int32_t i = 0; i < IndexFileNames::GetInstance().VECTOR_EXTENSIONS().length; i++) { + files->push_back ( segment + "." + IndexFileNames::GetInstance().VECTOR_EXTENSIONS()[i] ); } } diff --git a/src/core/CLucene/index/_IndexFileNameFilter.h b/src/core/CLucene/index/_IndexFileNameFilter.h index c825e6a..0da8fb4 100644 --- a/src/core/CLucene/index/_IndexFileNameFilter.h +++ b/src/core/CLucene/index/_IndexFileNameFilter.h @@ -24,7 +24,7 @@ public: * @version $rcs = ' $Id: Exp $ ' ; */ class IndexFileNameFilter: public FilenameFilter { - static IndexFileNameFilter* _singleton; + //static IndexFileNameFilter* _singleton; static IndexFileNameFilter* singleton(); CL_NS(util)::CLHashSet<const char*, CL_NS(util)::Compare::Char> extensions; CL_NS(util)::CLHashSet<const char*, CL_NS(util)::Compare::Char> extensionsInCFS; diff --git a/src/core/CLucene/index/_IndexFileNames.h b/src/core/CLucene/index/_IndexFileNames.h index e93687e..7838976 100644 --- a/src/core/CLucene/index/_IndexFileNames.h +++ b/src/core/CLucene/index/_IndexFileNames.h @@ -7,48 +7,58 @@ CL_NS_DEF(index) class CLUCENE_EXPORT IndexFileNames { - static CL_NS(util)::ConstValueArray<const char*> _INDEX_EXTENSIONS; - static CL_NS(util)::ConstValueArray<const char*> _INDEX_EXTENSIONS_IN_COMPOUND_FILE; - static CL_NS(util)::ConstValueArray<const char*> _STORE_INDEX_EXTENSIONS; - static CL_NS(util)::ConstValueArray<const char*> _NON_STORE_INDEX_EXTENSIONS; - static CL_NS(util)::ConstValueArray<const char*> _COMPOUND_EXTENSIONS; - static CL_NS(util)::ConstValueArray<const char*> _VECTOR_EXTENSIONS; public: - static const char* SEGMENTS; - static const char* SEGMENTS_GEN; - static const char* DELETABLE; - static const char* NORMS_EXTENSION; - static const char* FREQ_EXTENSION; - static const char* PROX_EXTENSION; - static const char* TERMS_EXTENSION; - static const char* TERMS_INDEX_EXTENSION; - static const char* FIELDS_INDEX_EXTENSION; - static const char* FIELDS_EXTENSION; - static const char* VECTORS_FIELDS_EXTENSION; - static const char* VECTORS_DOCUMENTS_EXTENSION; - static const char* VECTORS_INDEX_EXTENSION; - static const char* COMPOUND_FILE_EXTENSION; - static const char* COMPOUND_FILE_STORE_EXTENSION; - static const char* DELETES_EXTENSION; - static const char* FIELD_INFOS_EXTENSION; - static const char* PLAIN_NORMS_EXTENSION; - static const char* SEPARATE_NORMS_EXTENSION; - static const char* GEN_EXTENSION; - - LUCENE_STATIC_CONSTANT(int32_t,COMPOUND_EXTENSIONS_LENGTH=7); - LUCENE_STATIC_CONSTANT(int32_t,VECTOR_EXTENSIONS_LENGTH=3); - LUCENE_STATIC_CONSTANT(int32_t,STORE_INDEX_EXTENSIONS_LENGTH=5); - - static CL_NS(util)::ConstValueArray<const char*>& INDEX_EXTENSIONS(); - static CL_NS(util)::ConstValueArray<const char*>& INDEX_EXTENSIONS_IN_COMPOUND_FILE(); - static CL_NS(util)::ConstValueArray<const char*>& STORE_INDEX_EXTENSIONS(); - static CL_NS(util)::ConstValueArray<const char*>& NON_STORE_INDEX_EXTENSIONS(); - static CL_NS(util)::ConstValueArray<const char*>& COMPOUND_EXTENSIONS(); - static CL_NS(util)::ConstValueArray<const char*>& VECTOR_EXTENSIONS(); - - static std::string fileNameFromGeneration( const char* base, const char* extension, int64_t gen ); - static bool isDocStoreFile( const char* fileName ); - + static IndexFileNames &GetInstance() { + static IndexFileNames instance; + return instance; + } + IndexFileNames() = default; + IndexFileNames(const IndexFileNames &) = delete; + IndexFileNames &operator=(const IndexFileNames &) = delete; + +public: + static CL_NS(util)::ConstValueArray<const char *> _INDEX_EXTENSIONS; + static CL_NS(util)::ConstValueArray<const char *> _INDEX_EXTENSIONS_IN_COMPOUND_FILE; + static CL_NS(util)::ConstValueArray<const char *> _STORE_INDEX_EXTENSIONS; + static CL_NS(util)::ConstValueArray<const char *> _NON_STORE_INDEX_EXTENSIONS; + static CL_NS(util)::ConstValueArray<const char *> _COMPOUND_EXTENSIONS; + static CL_NS(util)::ConstValueArray<const char *> _VECTOR_EXTENSIONS; + +public: + static const char *SEGMENTS; + static const char *SEGMENTS_GEN; + static const char *DELETABLE; + static const char *NORMS_EXTENSION; + static const char *FREQ_EXTENSION; + static const char *PROX_EXTENSION; + static const char *TERMS_EXTENSION; + static const char *TERMS_INDEX_EXTENSION; + static const char *FIELDS_INDEX_EXTENSION; + static const char *FIELDS_EXTENSION; + static const char *VECTORS_FIELDS_EXTENSION; + static const char *VECTORS_DOCUMENTS_EXTENSION; + static const char *VECTORS_INDEX_EXTENSION; + static const char *COMPOUND_FILE_EXTENSION; + static const char *COMPOUND_FILE_STORE_EXTENSION; + static const char *DELETES_EXTENSION; + static const char *FIELD_INFOS_EXTENSION; + static const char *PLAIN_NORMS_EXTENSION; + static const char *SEPARATE_NORMS_EXTENSION; + static const char *GEN_EXTENSION; + + LUCENE_STATIC_CONSTANT(int32_t, COMPOUND_EXTENSIONS_LENGTH = 7); + LUCENE_STATIC_CONSTANT(int32_t, VECTOR_EXTENSIONS_LENGTH = 3); + LUCENE_STATIC_CONSTANT(int32_t, STORE_INDEX_EXTENSIONS_LENGTH = 5); + + const CL_NS(util)::ConstValueArray<const char *> &INDEX_EXTENSIONS(); + const CL_NS(util)::ConstValueArray<const char *> &INDEX_EXTENSIONS_IN_COMPOUND_FILE(); + const CL_NS(util)::ConstValueArray<const char *> &STORE_INDEX_EXTENSIONS(); + const CL_NS(util)::ConstValueArray<const char *> &NON_STORE_INDEX_EXTENSIONS(); + const CL_NS(util)::ConstValueArray<const char *> &COMPOUND_EXTENSIONS(); + const CL_NS(util)::ConstValueArray<const char *> &VECTOR_EXTENSIONS(); + + static std::string fileNameFromGeneration(const char *base, const char *extension, int64_t gen); + static bool isDocStoreFile(const char *fileName); }; CL_NS_END diff --git a/src/core/CLucene/util/ThreadLocal.cpp b/src/core/CLucene/util/ThreadLocal.cpp index ed1b0eb..66ad317 100644 --- a/src/core/CLucene/util/ThreadLocal.cpp +++ b/src/core/CLucene/util/ThreadLocal.cpp @@ -11,6 +11,9 @@ #include "_ThreadLocal.h" #include "CLucene/config/_threads.h" #include <assert.h> +#if defined(USE_BTHREAD) +#include <bthread/bthread.h> +#endif CL_NS_DEF ( util ) @@ -23,6 +26,12 @@ CL_NS_DEF ( util ) */ +#if defined(USE_BTHREAD) +#define IS_BTHREAD (bthread_self() != 0) +#else +#define IS_BTHREAD 0 +#endif + //predefine for the shared code... #if defined(_CL_HAVE_WIN32_THREADS) #define INIT_THREAD(ret) ret=true @@ -40,6 +49,25 @@ CL_NS_DEF ( util ) } } #elif defined(_CL_HAVE_PTHREAD) + +#if defined(USE_BTHREAD) + bthread_key_t bthread_threadlocal_key; + pthread_once_t bthread_threadlocal_key_once = PTHREAD_ONCE_INIT; + #define INIT_BTHREAD(ret) \ + pthread_once(&bthread_threadlocal_key_once, bthread_threadlocal_make_key); \ + if (bthread_getspecific(bthread_threadlocal_key) == NULL) { bthread_setspecific(bthread_threadlocal_key, (void*)1); } \ + ret = true; + + //the function that is called when the thread shutsdown + void bthread_threadlocal_destructor(void* /*_holder*/){ + _ThreadLocal::UnregisterCurrentThread(); + } + //the key initialiser function + void bthread_threadlocal_make_key() + { + (void) bthread_key_create(&bthread_threadlocal_key, &bthread_threadlocal_destructor); + } +#endif pthread_key_t pthread_threadlocal_key; pthread_once_t pthread_threadlocal_key_once = PTHREAD_ONCE_INIT; #define INIT_THREAD(ret) \ @@ -135,14 +163,31 @@ _ThreadLocal::~_ThreadLocal() void* _ThreadLocal::get() { SCOPED_LOCK_MUTEX(_internal->locals_LOCK) - return _internal->locals.get ( _LUCENE_CURRTHREADID ); +#if defined(USE_BTHREAD) + if (IS_BTHREAD) { + return _internal->locals.get ( _LUCENE_CURRBTHREADID ); + } else { + return _internal->locals.get ( _LUCENE_CURRTHREADID ); + } +#else + return _internal->locals.get ( _LUCENE_CURRTHREADID ); +#endif } void _ThreadLocal::setNull() { //just delete this thread from the locals list - _LUCENE_THREADID_TYPE id = _LUCENE_CURRTHREADID; - SCOPED_LOCK_MUTEX(_internal->locals_LOCK) + _LUCENE_THREADID_TYPE id; +#if defined(USE_BTHREAD) + if (IS_BTHREAD) { + id = _LUCENE_CURRBTHREADID; + } else { + id = _LUCENE_CURRTHREADID; + } +#else + id = _LUCENE_CURRTHREADID; +#endif + SCOPED_LOCK_MUTEX(_internal->locals_LOCK) Internal::LocalsType::iterator itr = _internal->locals.find ( id ); if ( itr != _internal->locals.end() ) { @@ -160,11 +205,27 @@ void _ThreadLocal::set ( void* t ) } //make sure we have a threadlocal context (for cleanup) bool ret; - INIT_THREAD(ret); - assert(ret); - - _LUCENE_THREADID_TYPE id = _LUCENE_CURRTHREADID; - +#if defined(USE_BTHREAD) + if (IS_BTHREAD) { + INIT_BTHREAD(ret); + } else { + INIT_THREAD(ret); + } +#else + INIT_THREAD(ret); +#endif + assert(ret); + + _LUCENE_THREADID_TYPE id; +#if defined(USE_BTHREAD) + if (IS_BTHREAD) { + id = _LUCENE_CURRBTHREADID; + } else { + id = _LUCENE_CURRTHREADID; + } +#else + id = _LUCENE_CURRTHREADID; +#endif //drop a reference to this ThreadLocal in ThreadData { #ifndef _CL_DISABLE_MULTITHREADING @@ -206,8 +267,17 @@ void _ThreadLocal::UnregisterCurrentThread() { if ( threadData == NULL ) return; - _LUCENE_THREADID_TYPE id = _LUCENE_CURRTHREADID; - SCOPED_LOCK_MUTEX ( *threadData_LOCK ); + _LUCENE_THREADID_TYPE id; +#if defined(USE_BTHREAD) + if (IS_BTHREAD) { + id = _LUCENE_CURRBTHREADID; + } else { + id = _LUCENE_CURRTHREADID; + } +#else + id = _LUCENE_CURRTHREADID; +#endif + SCOPED_LOCK_MUTEX ( *threadData_LOCK ); ThreadDataType::iterator itr = threadData->find(id); if ( itr != threadData->end() ){ diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 6a62fc6..8315979 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -217,6 +217,12 @@ IF (BUILD_SHARED_LIBRARIES) add_library(clucene-core SHARED ${clucene_core_Files} ${clucene_shared_Files} ${HEADERS} ) + IF (USE_BTHREAD) + target_include_directories(clucene-core PUBLIC + $<BUILD_INTERFACE:${BRPC_DIR}> + ) + TARGET_LINK_LIBRARIES(clucene-core ssl crypto ${BRPC_LIB} ${GLOG_LIB} ${GFLAG_LIB} ${PROTOBUF_LIB}) + ENDIF (USE_BTHREAD) #set properties on the libraries SET_TARGET_PROPERTIES(clucene-core PROPERTIES VERSION ${CLUCENE_VERSION} @@ -234,13 +240,17 @@ IF (BUILD_STATIC_LIBRARIES) add_library(clucene-core-static STATIC ${clucene_core_Files} ${clucene_shared_Files} ${HEADERS} ) - + IF (USE_BTHREAD) + target_include_directories(clucene-core-static PUBLIC + $<BUILD_INTERFACE:${BRPC_DIR}> + ) + TARGET_LINK_LIBRARIES(clucene-core-static ssl crypto ${BRPC_LIB} ${GLOG_LIB} ${GFLAG_LIB} ${PROTOBUF_LIB}) + ENDIF (USE_BTHREAD) SET_TARGET_PROPERTIES(clucene-core-static PROPERTIES VERSION ${CLUCENE_VERSION} SOVERSION ${CLUCENE_SOVERSION} COMPILE_DEFINITIONS_DEBUG _DEBUG ) - #and install library install(TARGETS clucene-core-static DESTINATION ${LIB_DESTINATION} diff --git a/src/shared/CLucene/LuceneThreads.h b/src/shared/CLucene/LuceneThreads.h index 97072ee..4ac7f4c 100644 --- a/src/shared/CLucene/LuceneThreads.h +++ b/src/shared/CLucene/LuceneThreads.h @@ -37,7 +37,7 @@ class CLuceneThreadIdCompare; class mutexGuard; #if defined(_CL_HAVE_PTHREAD) - #define _LUCENE_THREADID_TYPE pthread_t + #define _LUCENE_THREADID_TYPE uint64_t #define _LUCENE_THREAD_FUNC(name, argName) void* name(void* argName) //< use this macro to correctly define the thread start routine #define _LUCENE_THREAD_FUNC_RETURN(val) return (void*)val; typedef void* (luceneThreadStartRoutine)(void* lpThreadParameter ); @@ -53,13 +53,16 @@ class CLuceneThreadIdCompare; ~mutex_thread(); void lock(); void unlock(); +#if defined(USE_BTHREAD) + static _LUCENE_THREADID_TYPE _GetCurrentBThreadId(); +#endif static _LUCENE_THREADID_TYPE _GetCurrentThreadId(); static _LUCENE_THREADID_TYPE CreateThread(luceneThreadStartRoutine* func, void* arg); static void JoinThread(_LUCENE_THREADID_TYPE id); void Wait(mutex_thread* shared_lock); void NotifyAll(); }; - class CLUCENE_SHARED_EXPORT shared_condition{ + class CLUCENE_SHARED_EXPORT shared_condition{ private: class Internal; Internal* _internal; @@ -123,6 +126,9 @@ class CLuceneThreadIdCompare; void unlock(); static void _exitThread(int ret); static _LUCENE_THREADID_TYPE _GetCurrentThreadId(); +#if defined(USE_BTHREAD) +#define _LUCENE_CURRBTHREADID CL_NS(util)::mutex_thread::_GetCurrentBThreadId() +#endif static _LUCENE_THREADID_TYPE CreateThread(luceneThreadStartRoutine* func, void* arg); static void JoinThread(_LUCENE_THREADID_TYPE id); @@ -145,6 +151,9 @@ class CLuceneThreadIdCompare; #define _LUCENE_THREAD_CREATE(func, arg) CL_NS(util)::mutex_thread::CreateThread(func,arg) #define _LUCENE_THREAD_JOIN(id) CL_NS(util)::mutex_thread::JoinThread(id) +#if defined(USE_BTHREAD) + #define _LUCENE_CURRBTHREADID CL_NS(util)::mutex_thread::_GetCurrentBThreadId() +#endif #define _LUCENE_CURRTHREADID CL_NS(util)::mutex_thread::_GetCurrentThreadId() #define _LUCENE_THREADMUTEX CL_NS(util)::mutex_thread #define _LUCENE_THREADCOND CL_NS(util)::shared_condition diff --git a/src/shared/CLucene/config/_threads.h b/src/shared/CLucene/config/_threads.h index b86dd24..80cb3b6 100644 --- a/src/shared/CLucene/config/_threads.h +++ b/src/shared/CLucene/config/_threads.h @@ -94,7 +94,7 @@ CL_NS_DEF(util) min_buckets = 8 }; // min_buckets = 2 ^^ N, 0 < N - bool operator()( pthread_t t1, pthread_t t2 ) const{ + bool operator()( uint64_t t1, uint64_t t2 ) const{ //pthread_equal should be used, but it returns only non-zero if equal, so we can't use it for order compare return t1 < t2; } diff --git a/src/shared/CLucene/config/threads.cpp b/src/shared/CLucene/config/threads.cpp index 0b5f30a..936ab6b 100644 --- a/src/shared/CLucene/config/threads.cpp +++ b/src/shared/CLucene/config/threads.cpp @@ -8,7 +8,9 @@ #include "CLucene/LuceneThreads.h" #include "_threads.h" #include <assert.h> - +#if defined(USE_BTHREAD) +#include <bthread/bthread.h> +#endif CL_NS_DEF(util) #ifndef _CL_DISABLE_MULTITHREADING @@ -180,6 +182,12 @@ CL_NS_DEF(util) delete _internal; } +#if defined(USE_BTHREAD) + bthread_t mutex_thread::_GetCurrentBThreadId(){ + return bthread_self(); + } +#endif + _LUCENE_THREADID_TYPE mutex_thread::_GetCurrentThreadId(){ return pthread_self(); } diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 8da2393..2d9f1ba 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -332,6 +332,13 @@ IF (BUILD_SHARED_LIBRARIES) add_library(clucene-shared SHARED ${clucene_shared_Files} ${HEADERS} ) + IF (USE_BTHREAD) + target_include_directories(clucene-shared PUBLIC + $<BUILD_INTERFACE:${BRPC_DIR}> + ) + TARGET_LINK_LIBRARIES(clucene-shared ssl crypto ${BRPC_LIB} ${GLOG_LIB} ${GFLAG_LIB} ${PROTOBUF_LIB}) + + ENDIF (USE_BTHREAD) #set properties on the libraries SET_TARGET_PROPERTIES(clucene-shared PROPERTIES VERSION ${CLUCENE_VERSION} @@ -352,7 +359,12 @@ IF (BUILD_STATIC_LIBRARIES) add_library(clucene-shared-static STATIC ${clucene_shared_Files} ${HEADERS} ) - + IF (USE_BTHREAD) + target_include_directories(clucene-shared-static PUBLIC + $<BUILD_INTERFACE:${BRPC_DIR}> + ) + TARGET_LINK_LIBRARIES(clucene-shared-static ssl crypto ${BRPC_LIB} ${GLOG_LIB} ${GFLAG_LIB} ${PROTOBUF_LIB}) + ENDIF (USE_BTHREAD) SET_TARGET_PROPERTIES(clucene-shared-static PROPERTIES VERSION ${CLUCENE_VERSION} SOVERSION ${CLUCENE_SOVERSION} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org