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 #if defined(_LUCENE_PRAGMA_ONCE) 00010 # pragma once 00011 #endif 00012 00013 #if defined(_CL_DISABLE_MULTITHREADING) 00014 #define SCOPED_LOCK_MUTEX(theMutex) 00015 #define DEFINE_MUTEX(x) 00016 #define STATIC_DEFINE_MUTEX(x) 00017 #define _LUCENE_SLEEP(x) 00018 #define _LUCENE_CURRTHREADID 1 00019 #define _LUCENE_THREADID_TYPE char 00020 00021 CL_NS_DEF(util) 00022 class CLuceneThreadIdCompare 00023 { 00024 public: 00025 enum 00026 { // parameters for hash table 00027 bucket_size = 4, // 0 < bucket_size 00028 min_buckets = 8 00029 }; // min_buckets = 2 ^^ N, 0 < N 00030 00031 bool operator()( char t1, char t2 ) const{ 00032 return t1 < t2; 00033 } 00034 }; 00035 CL_NS_END 00036 #else 00037 00038 #if defined(_LUCENE_DONTIMPLEMENT_THREADMUTEX) 00039 //do nothing 00040 #elif defined(_CL_HAVE_PTHREAD) 00041 #include "CLucene/config/threadPthread.h" 00042 #elif defined(_CL_HAVE_WIN32_THREADS) || defined(_CLCOMPILER_MSVC) || defined(__MINGW32__) //note that mingw32 could have pthreads, so put this after. 00043 #if !defined(_CL_HAVE_WIN32_THREADS) 00044 #define _CL_HAVE_WIN32_THREADS 00045 #endif 00046 #include "CLucene/config/threadCSection.h" 00047 #else 00048 #error A valid thread library was not found 00049 #endif //mutex types 00050 00051 CL_NS_DEF(util) 00053 class mutexGuard 00054 { 00055 private: 00056 _LUCENE_THREADMUTEX* mrMutex; 00057 mutexGuard(const mutexGuard& clone); 00058 public: 00059 mutexGuard( _LUCENE_THREADMUTEX& rMutex ); 00060 ~mutexGuard(); 00061 }; 00062 CL_NS_END 00063 00064 #define SCOPED_LOCK_MUTEX(theMutex) CL_NS(util)::mutexGuard theMutexGuard(theMutex); 00065 #define DEFINE_MUTEX(theMutex) _LUCENE_THREADMUTEX theMutex; 00066 #define STATIC_DEFINE_MUTEX(theMutex) static _LUCENE_THREADMUTEX theMutex; 00067 00068 #endif //_CL_DISABLE_MULTITHREADING 00069 00070 00071 00072 #endif