1 | /*------------------------------------------------------------------------------ |
2 | * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team |
3 | * |
4 | * Distributable under the terms of either the Apache License (Version 2.0) or |
5 | * the GNU Lesser General Public License, as specified in the COPYING file. |
6 | ------------------------------------------------------------------------------*/ |
7 | #ifndef _LuceneThreads_h |
8 | #define _LuceneThreads_h |
9 | #if defined(_LUCENE_PRAGMA_ONCE) |
10 | # pragma once |
11 | #endif |
12 | |
13 | #if defined(_CL_DISABLE_MULTITHREADING) |
14 | #define SCOPED_LOCK_MUTEX(theMutex) |
15 | #define DEFINE_MUTEX(x) |
16 | #define STATIC_DEFINE_MUTEX(x) |
17 | #define _LUCENE_SLEEP(x) |
18 | #define _LUCENE_CURRTHREADID 1 |
19 | #define _LUCENE_THREADID_TYPE char |
20 | |
21 | CL_NS_DEF(util) |
22 | class CLuceneThreadIdCompare |
23 | { |
24 | public: |
25 | enum |
26 | { // parameters for hash table |
27 | bucket_size = 4, // 0 < bucket_size |
28 | min_buckets = 8 |
29 | }; // min_buckets = 2 ^^ N, 0 < N |
30 | |
31 | bool operator()( char t1, char t2 ) const{ |
32 | return t1 < t2; |
33 | } |
34 | }; |
35 | CL_NS_END |
36 | #else |
37 | |
38 | #if defined(_LUCENE_DONTIMPLEMENT_THREADMUTEX) |
39 | //do nothing |
40 | #elif defined(_CL_HAVE_PTHREAD) |
41 | #include "CLucene/config/threadPthread.h" |
42 | #elif defined(_CL_HAVE_WIN32_THREADS) || defined(_CLCOMPILER_MSVC) || defined(__MINGW32__) //note that mingw32 could have pthreads, so put this after. |
43 | #if !defined(_CL_HAVE_WIN32_THREADS) |
44 | #define _CL_HAVE_WIN32_THREADS |
45 | #endif |
46 | #include "CLucene/config/threadCSection.h" |
47 | #else |
48 | #error A valid thread library was not found |
49 | #endif //mutex types |
50 | |
51 | CL_NS_DEF(util) |
52 | /** @internal */ |
53 | class mutexGuard |
54 | { |
55 | private: |
56 | _LUCENE_THREADMUTEX* mrMutex; |
57 | mutexGuard(const mutexGuard& clone); |
58 | public: |
59 | mutexGuard( _LUCENE_THREADMUTEX& rMutex ); |
60 | ~mutexGuard(); |
61 | }; |
62 | CL_NS_END |
63 | |
64 | #define SCOPED_LOCK_MUTEX(theMutex) CL_NS(util)::mutexGuard theMutexGuard(theMutex); |
65 | #define DEFINE_MUTEX(theMutex) _LUCENE_THREADMUTEX theMutex; |
66 | #define STATIC_DEFINE_MUTEX(theMutex) static _LUCENE_THREADMUTEX theMutex; |
67 | |
68 | #endif //_CL_DISABLE_MULTITHREADING |
69 | |
70 | |
71 | |
72 | #endif |
73 | |