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 e6e9da1 [Fix](thread) fix thread compatibility in diffrent
compilation enviroment (#39)
e6e9da1 is described below
commit e6e9da1681ba9ba1abd949ea7368fcab11f6ffa3
Author: airborne12 <[email protected]>
AuthorDate: Tue Feb 21 14:06:37 2023 +0800
[Fix](thread) fix thread compatibility in diffrent compilation enviroment
(#39)
fix compatible problem find in macos build.
---
src/shared/CLucene/LuceneThreads.h | 14 ++-
src/shared/CLucene/config/_threads.h | 175 +++++++++++++++++------------------
2 files changed, 93 insertions(+), 96 deletions(-)
diff --git a/src/shared/CLucene/LuceneThreads.h
b/src/shared/CLucene/LuceneThreads.h
index 4ac7f4c..460c407 100644
--- a/src/shared/CLucene/LuceneThreads.h
+++ b/src/shared/CLucene/LuceneThreads.h
@@ -7,7 +7,9 @@
#ifndef _LuceneThreads_h
#define _LuceneThreads_h
-
+#if defined(USE_BTHREAD)
+#include <bthread/bthread.h>
+#endif
CL_NS_DEF(util)
class CLuceneThreadIdCompare;
@@ -37,9 +39,13 @@ class CLuceneThreadIdCompare;
class mutexGuard;
#if defined(_CL_HAVE_PTHREAD)
- #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;
+#if defined(USE_BTHREAD)
+#define _LUCENE_THREADID_TYPE bthread_t
+#else
+#define _LUCENE_THREADID_TYPE pthread_t
+#endif
+#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 );
class CLUCENE_SHARED_EXPORT mutex_thread
diff --git a/src/shared/CLucene/config/_threads.h
b/src/shared/CLucene/config/_threads.h
index 80cb3b6..a47a984 100644
--- a/src/shared/CLucene/config/_threads.h
+++ b/src/shared/CLucene/config/_threads.h
@@ -8,56 +8,54 @@
#define _config_threads_h
#ifndef _CL_DISABLE_MULTITHREADING
- #if defined(_LUCENE_DONTIMPLEMENT_THREADMUTEX)
- //do nothing
- #elif defined(_CL_HAVE_WIN32_THREADS)
- //we have not explicity included windows.h and windows.h has
- //not been included (check _WINBASE_), then we must define
- //our own definitions to the thread locking functions:
- #ifndef _WINBASE_
- extern "C"{
- struct CRITICAL_SECTION
- {
- struct critical_section_debug * DebugInfo;
- long LockCount;
- long RecursionCount;
- void * OwningThread;
- void * LockSemaphore;
- _cl_dword_t SpinCount;
- };
-
- __declspec(dllimport) void __stdcall
InitializeCriticalSection(CRITICAL_SECTION *);
- __declspec(dllimport) void __stdcall
EnterCriticalSection(CRITICAL_SECTION *);
- __declspec(dllimport) void __stdcall
LeaveCriticalSection(CRITICAL_SECTION *);
- __declspec(dllimport) void __stdcall
DeleteCriticalSection(CRITICAL_SECTION *);
- __declspec(dllimport) void __stdcall
ExitThread(_cl_dword_t);
-
- __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
+#if defined(_LUCENE_DONTIMPLEMENT_THREADMUTEX)
+//do nothing
+#elif defined(_CL_HAVE_WIN32_THREADS)
+//we have not explicity included windows.h and windows.h has
+//not been included (check _WINBASE_), then we must define
+//our own definitions to the thread locking functions:
+#ifndef _WINBASE_
+extern "C" {
+struct CRITICAL_SECTION {
+ struct critical_section_debug *DebugInfo;
+ long LockCount;
+ long RecursionCount;
+ void *OwningThread;
+ void *LockSemaphore;
+ _cl_dword_t SpinCount;
+};
+
+__declspec(dllimport) void __stdcall
InitializeCriticalSection(CRITICAL_SECTION *);
+__declspec(dllimport) void __stdcall EnterCriticalSection(CRITICAL_SECTION *);
+__declspec(dllimport) void __stdcall LeaveCriticalSection(CRITICAL_SECTION *);
+__declspec(dllimport) void __stdcall DeleteCriticalSection(CRITICAL_SECTION *);
+__declspec(dllimport) void __stdcall ExitThread(_cl_dword_t);
+
+__declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
#ifdef _M_X64
- __declspec(dllimport) long long __stdcall
_InterlockedIncrement64(__inout long long volatile*);
- __declspec(dllimport) long long __stdcall
_InterlockedDecrement64(__inout long long volatile*);
+__declspec(dllimport) long long __stdcall _InterlockedIncrement64(__inout long
long volatile *);
+__declspec(dllimport) long long __stdcall _InterlockedDecrement64(__inout long
long volatile *);
#else
- __declspec(dllimport) long __stdcall InterlockedIncrement(long
volatile*);
- __declspec(dllimport) long __stdcall InterlockedDecrement(long
volatile*);
+__declspec(dllimport) long __stdcall InterlockedIncrement(long volatile *);
+__declspec(dllimport) long __stdcall InterlockedDecrement(long volatile *);
+#endif
+typedef struct _SECURITY_ATTRIBUTES {
+ _cl_dword_t nLength;
+ void *lpSecurityDescriptor;
+ bool bInheritHandle;
+} SECURITY_ATTRIBUTES;
+__declspec(dllimport) _cl_dword_t __stdcall WaitForSingleObject(void *hHandle,
_cl_dword_t dwMilliseconds);
+__declspec(dllimport) void *__stdcall CreateEventA(SECURITY_ATTRIBUTES
*lpEventAttributes,
+ bool bManualReset, bool
bInitialState, char *lpName);
+__declspec(dllimport) bool __stdcall SetEvent(void *hEvent);
+__declspec(dllimport) bool __stdcall CloseHandle(void *hObject);
+void *_beginthread(void(__stdcall *start_address)(void *), unsigned
stack_size, void *arglist);
+}
+#endif//_WINBASE_
+#elif defined(_CL_HAVE_PTHREAD)
+#include <pthread.h>
#endif
- typedef struct _SECURITY_ATTRIBUTES
- {
- _cl_dword_t nLength;
- void* lpSecurityDescriptor;
- bool bInheritHandle;
- } SECURITY_ATTRIBUTES;
- __declspec(dllimport) _cl_dword_t __stdcall WaitForSingleObject(
void* hHandle, _cl_dword_t dwMilliseconds );
- __declspec(dllimport) void* __stdcall CreateEventA(
SECURITY_ATTRIBUTES* lpEventAttributes,
- bool bManualReset, bool bInitialState, char* lpName );
- __declspec(dllimport) bool __stdcall SetEvent(void* hEvent);
- __declspec(dllimport) bool __stdcall CloseHandle(void*
hObject);
- void* _beginthread( void( __stdcall *start_address )( void *
), unsigned stack_size, void *arglist );
- }
- #endif //_WINBASE_
- #elif defined(_CL_HAVE_PTHREAD)
- #include <pthread.h>
- #endif
#endif
CL_NS_DEF(util)
@@ -67,59 +65,52 @@ CL_NS_DEF(util)
#if defined(_LUCENE_DONTIMPLEMENT_THREADMUTEX)
#elif defined(_CL_HAVE_WIN32_THREADS)
- class CLuceneThreadIdCompare
- {
- public:
-
- enum
- { // parameters for hash table
- bucket_size = 4, // 0 < bucket_size
- min_buckets = 8
- }; // min_buckets = 2 ^^ N, 0 < N
-
- bool operator()( uint64_t t1, uint64_t t2 ) const{
- return t1 < t2;
- }
- };
-
+class CLuceneThreadIdCompare {
+public:
+ enum { // parameters for hash table
+ bucket_size = 4,// 0 < bucket_size
+ min_buckets = 8
+ };// min_buckets = 2 ^^ N, 0 < N
+
+ bool operator()(uint64_t t1, uint64_t t2) const {
+ return t1 < t2;
+ }
+};
+
#elif defined(_CL_HAVE_PTHREAD)
- class CLuceneThreadIdCompare
- {
- public:
- enum
- { // parameters for hash table
- bucket_size = 4, // 0 < bucket_size
- min_buckets = 8
- }; // min_buckets = 2 ^^ N, 0 < N
-
- 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;
- }
- };
-
-#endif //thread impl choice
+class CLuceneThreadIdCompare {
+public:
+ enum { // parameters for hash table
+ bucket_size = 4,// 0 < bucket_size
+ min_buckets = 8
+ };// min_buckets = 2 ^^ N, 0 < N
+
+ bool operator()(_LUCENE_THREADID_TYPE t1, _LUCENE_THREADID_TYPE 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;
+ }
+};
+
+#endif//thread impl choice
#else //!_CL_DISABLE_MULTITHREADING
- class CLuceneThreadIdCompare
- {
- public:
- enum
- { // parameters for hash table
- bucket_size = 4, // 0 < bucket_size
- min_buckets = 8
- }; // min_buckets = 2 ^^ N, 0 < N
-
- bool operator()( char t1, char t2 ) const{
- return t1 < t2;
- }
- };
-#endif //!_CL_DISABLE_MULTITHREADING
+class CLuceneThreadIdCompare {
+public:
+ enum { // parameters for hash table
+ bucket_size = 4,// 0 < bucket_size
+ min_buckets = 8
+ };// min_buckets = 2 ^^ N, 0 < N
+
+ bool operator()(char t1, char t2) const {
+ return t1 < t2;
+ }
+};
+#endif//!_CL_DISABLE_MULTITHREADING
CL_NS_END
-#endif //_config_threads_h
+#endif//_config_threads_h
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]