UniSet
1.4.0
|
00001 /* This file is part of the UniSet project 00002 * Copyright (c) 2002 Free Software Foundation, Inc. 00003 * Copyright (c) 2002 Pavel Vainerman 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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_