00001 #ifndef __THREAD_H__
00002 #define __THREAD_H__
00003
00004 #include <pthread.h>
00005 #include <iostream>
00006 #include <unistd.h>
00007
00008 class Thread
00009 {
00010 public:
00011 Thread () {}
00012 int start (void* a);
00013 pthread_t id() { return _thread_id; }
00014 static void join (Thread &t);
00015
00016 protected:
00017 void run (void* a);
00018 static void* entry (void*);
00019 virtual void exec (void*) = 0;
00020 void* arg() const { return _arg; }
00021 void arg (void* a) { _arg = a; }
00022 private:
00023 pthread_t _thread_id;
00024 void* _arg;
00025 };
00026
00027 class Mutex
00028 {
00029 public:
00030 Mutex ();
00031 void lock ();
00032 void unlock ();
00033 void destroy ();
00034 pthread_mutex_t getMutex ();
00035 private:
00036 pthread_mutex_t _mutex;
00037 };
00038
00039 class Semaphore
00040 {
00041 public:
00042 Semaphore ();
00043 void destroy ();
00044 int up ();
00045 int down ();
00046 int value ();
00047 private:
00048 int v;
00049 Mutex mutex;
00050 pthread_cond_t cond;
00051 };
00052
00053 #endif // __THREAD_H__