CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _LuceneThreads_h 00008 #define _LuceneThreads_h 00009 00010 00011 CL_NS_DEF(util) 00012 class CLuceneThreadIdCompare; 00013 00014 #if defined(_CL_DISABLE_MULTITHREADING) 00015 #define SCOPED_LOCK_MUTEX(theMutex) 00016 #define DEFINE_MUTEX(x) 00017 #define DEFINE_MUTABLE_MUTEX(x) 00018 #define STATIC_DEFINE_MUTEX(x) 00019 #define _LUCENE_SLEEP(x) 00020 #define _LUCENE_CURRTHREADID 1 00021 #define _LUCENE_THREADID_TYPE char 00022 00023 #else 00024 #if defined(_LUCENE_DONTIMPLEMENT_THREADMUTEX) 00025 //do nothing 00026 #elif defined(_CL_HAVE_PTHREAD) 00027 class CLUCENE_EXPORT mutex_pthread 00028 { 00029 private: 00030 struct Internal; 00031 Internal* internal; 00032 public: 00033 mutex_pthread(const mutex_pthread& clone); 00034 mutex_pthread(); 00035 ~mutex_pthread(); 00036 void lock(); 00037 void unlock(); 00038 }; 00039 #define _LUCENE_SLEEP(x) usleep(x*1000) //_LUCENE_SLEEP should be in millis, usleep is in micros 00040 #define _LUCENE_THREADMUTEX CL_NS(util)::mutex_pthread 00041 #define _LUCENE_CURRTHREADID pthread_self() 00042 #define _LUCENE_THREADID_TYPE pthread_t 00043 00044 #elif defined(_CL_HAVE_WIN32_THREADS) 00045 class CLUCENE_EXPORT mutex_win32 00046 { 00047 private: 00048 struct Internal; 00049 Internal* internal; 00050 public: 00051 mutex_win32(const mutex_win32& clone); 00052 mutex_win32(); 00053 ~mutex_win32(); 00054 void lock(); 00055 void unlock(); 00056 static uint64_t _GetCurrentThreadId(); 00057 }; 00058 #define _LUCENE_SLEEP(x) Sleep(x) 00059 #define _LUCENE_THREADMUTEX CL_NS(util)::mutex_win32 00060 #define _LUCENE_CURRTHREADID mutex_win32::_GetCurrentThreadId() 00061 #define _LUCENE_THREADID_TYPE uint64_t 00062 #else 00063 #error A valid thread library was not found 00064 #endif //mutex types 00065 00067 class mutexGuard 00068 { 00069 private: 00070 _LUCENE_THREADMUTEX* mrMutex; 00071 mutexGuard(const mutexGuard& clone); 00072 public: 00073 mutexGuard( _LUCENE_THREADMUTEX& rMutex ); 00074 ~mutexGuard(); 00075 }; 00076 00077 #define SCOPED_LOCK_MUTEX(theMutex) CL_NS(util)::mutexGuard theMutexGuard(theMutex); 00078 #define DEFINE_MUTEX(theMutex) _LUCENE_THREADMUTEX theMutex; 00079 #define DEFINE_MUTABLE_MUTEX(theMutex) mutable _LUCENE_THREADMUTEX theMutex; 00080 #define STATIC_DEFINE_MUTEX(theMutex) static _LUCENE_THREADMUTEX theMutex; 00081 00082 #endif //_CL_DISABLE_MULTITHREADING 00083 CL_NS_END 00084 00085 #endif