00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef OFTHREAD_H
00039 #define OFTHREAD_H
00040
00041 #include "osconfig.h"
00042 #include "oftypes.h"
00043 #include "ofstring.h"
00044
00049 extern "C"
00050 {
00051 #ifdef HAVE_WINDOWS_H
00052 unsigned int __stdcall thread_stub(void *arg);
00053 #else
00054 void *thread_stub(void *arg);
00055 #endif
00056 }
00057
00058
00066 class OFThread
00067 {
00068 public:
00069
00074 OFThread();
00075
00083 virtual ~OFThread();
00084
00100 int start();
00101
00111 int join();
00112
00121 unsigned long threadID();
00122
00128 OFBool equal(unsigned long tID);
00129
00135 static void errorstr(OFString& description, int code);
00136
00143 static const int busy;
00144
00145 protected:
00146
00150 static void thread_exit();
00151
00161 static unsigned long self();
00162
00163 private:
00164
00172 virtual void run() = 0;
00173
00174 #ifdef HAVE_WINDOWS_H
00175
00176 unsigned long theThreadHandle;
00177 #endif
00178
00180 unsigned long theThread;
00181
00183 OFThread(const OFThread& arg);
00184
00186 OFThread& operator=(const OFThread& arg);
00187
00189 #ifdef HAVE_WINDOWS_H
00190 friend unsigned int __stdcall thread_stub(void *arg);
00191 #else
00192 friend void *thread_stub(void *arg);
00193 #endif
00194 };
00195
00196
00206 class OFThreadSpecificData
00207 {
00208 public:
00209
00211 OFThreadSpecificData();
00212
00216 ~OFThreadSpecificData();
00217
00221 OFBool initialized() const;
00222
00229 int set(void *value);
00230
00237 int get(void *&value);
00238
00244 static void errorstr(OFString& description, int code);
00245
00246 private:
00247
00249 #ifdef HAVE_CXX_VOLATILE
00250 volatile
00251 #endif
00252 void *theKey;
00253
00255 OFThreadSpecificData(const OFThreadSpecificData& arg);
00256
00258 OFThreadSpecificData& operator=(const OFThreadSpecificData& arg);
00259 };
00260
00261
00270 class OFSemaphore
00271 {
00272 public:
00273
00277 OFSemaphore(unsigned int numResources);
00278
00280 ~OFSemaphore();
00281
00285 OFBool initialized() const;
00286
00291 int wait();
00292
00298 int trywait();
00299
00304 int post();
00305
00311 static void errorstr(OFString& description, int code);
00312
00318 static const int busy;
00319
00320 private:
00322 #ifdef HAVE_CXX_VOLATILE
00323 volatile
00324 #endif
00325 void * theSemaphore;
00326
00328 OFSemaphore(const OFSemaphore& arg);
00329
00331 OFSemaphore& operator=(const OFSemaphore& arg);
00332 };
00333
00334
00343 class OFMutex
00344 {
00345 public:
00346
00348 OFMutex();
00349
00351 ~OFMutex();
00352
00356 OFBool initialized() const;
00357
00364 int lock();
00365
00371 int trylock();
00372
00380 int unlock();
00381
00387 static void errorstr(OFString& description, int code);
00388
00394 static const int busy;
00395
00396 private:
00398 #ifdef HAVE_CXX_VOLATILE
00399 volatile
00400 #endif
00401 void * theMutex;
00402
00404 OFMutex(const OFMutex& arg);
00405
00407 OFMutex& operator=(const OFMutex& arg);
00408 };
00409
00410
00418 class OFReadWriteLock
00419 {
00420 public:
00421
00423 OFReadWriteLock();
00424
00426 ~OFReadWriteLock();
00427
00431 OFBool initialized() const;
00432
00439 int rdlock();
00440
00447 int wrlock();
00448
00454 int tryrdlock();
00455
00461 int trywrlock();
00462
00470 int unlock();
00471
00477 static void errorstr(OFString& description, int code);
00478
00484 static const int busy;
00485
00486 private:
00488 #ifdef HAVE_CXX_VOLATILE
00489 volatile
00490 #endif
00491 void * theLock;
00492
00494 OFReadWriteLock(const OFReadWriteLock& arg);
00495
00497 OFReadWriteLock& operator=(const OFReadWriteLock& arg);
00498 };
00499
00500 #endif
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532