PosixThread.h
См. документацию.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024
00025 #ifndef PosixThread_h_
00026 #define PosixThread_h_
00027
00028 #include <pthread.h>
00029 #include <iostream>
00030 #include <signal.h>
00031
00033 class PosixThread
00034 {
00035 public:
00036 PosixThread();
00037 virtual ~PosixThread();
00038
00039 void start( void *args );
00040 void stop();
00041
00042 void thrkill( int signo );
00044 enum TAttr{ SCOPE, DETACH, PRIORITY };
00045
00046 void setAttr( TAttr Attr, int state );
00047
00048 pthread_t getTID(){ return tid; }
00049
00050 void setPriority( int priority );
00051
00052 static void* funcp( void * test );
00053
00054
00055
00056 protected:
00057
00058 void reinit();
00059
00060 virtual void work() = 0;
00062 void readlock( pthread_rwlock_t *lock = &lockx );
00063 void writelock( pthread_rwlock_t *lock = &lockx );
00064 void lock( pthread_mutex_t *mute = &mutex );
00065 void unlock( pthread_mutex_t *mute = &mutex );
00066 void rwunlock( pthread_rwlock_t *lock = &lockx );
00067 void wait( pthread_cond_t *cond = &condx, pthread_mutex_t *mute = &mutex );
00068 void continueRun( pthread_cond_t *cond = &condx );
00069 void continueRunAll( pthread_cond_t *cond = &condx );
00070 private:
00071 pthread_t tid;
00072 pthread_attr_t *attrPtr;
00073
00074 static pthread_rwlock_t lockx;
00075 static pthread_mutex_t mutex;
00076 static pthread_cond_t condx;
00077
00078 static int countThreads;
00079 };
00080
00081 #endif // PosixThread_h_