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//NOTE: do not include this file directly, it is included from lucene internally.
8
9#ifndef lucene_config_threadPthread_h
10#define lucene_config_threadPthread_h
11
12#include <pthread.h>
13
14CL_NS_DEF(util)
15
16///a posix implementation of the lock mutex
17///todo: we need a spinlock implemenation for usage in reference counting
18class mutex_pthread
19{
20private:
21 pthread_mutex_t mtx;
22
23public:
24 mutex_pthread(const mutex_pthread& clone);
25 mutex_pthread();
26 ~mutex_pthread();
27 void lock();
28 void unlock();
29
30private:
31 #ifndef _CL_HAVE_PTHREAD_MUTEX_RECURSIVE
32 pthread_t lockOwner;
33 unsigned int lockCount;
34 #endif
35};
36
37#define _LUCENE_SLEEP(x) usleep(x*1000) //_LUCENE_SLEEP should be in millis, usleep is in micros
38#define _LUCENE_THREADMUTEX CL_NS(util)::mutex_pthread
39#define _LUCENE_CURRTHREADID pthread_self()
40#define _LUCENE_THREADID_TYPE pthread_t
41
42class CLuceneThreadIdCompare
43{
44public:
45 enum
46 { // parameters for hash table
47 bucket_size = 4, // 0 < bucket_size
48 min_buckets = 8
49 }; // min_buckets = 2 ^^ N, 0 < N
50
51 bool operator()( pthread_t t1, pthread_t t2 ) const{
52 return t1 < t2;
53 }
54};
55
56
57CL_NS_END
58
59#endif //lucene_config_threadPthread_h
60