00001
00002
00003
00004 #ifndef __J2K__Basic_PThread_HPP__
00005 #define __J2K__Basic_PThread_HPP__
00006
00007 #include <j2k/Fred/Standard.hpp>
00008 #include <j2k/Fred/Error/JErrorController.hpp>
00009 #include <pthread.h>
00010 #include <unistd.h>
00011
00012 #if defined( __sun ) || defined( __SUN__ )
00013 #include <thread.h>
00014 #endif
00015
00016
00017 #include <sched.h>
00018
00019 #include <time.h>
00020 #include <signal.h>
00021 #include <sys/types.h>
00022
00023 #define pid_t pthread_t
00024
00025 #define INVALID_PID ((unsigned)(-1))
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class Basic_PThread {
00041
00042
00043 public:
00044
00045
00046 inline Basic_PThread( BOOL autostart = FALSE, BOOL autojoin = FALSE );
00047
00048
00049 inline virtual ~Basic_PThread();
00050
00051 private:
00052
00053 inline Basic_PThread( const Basic_PThread& src );
00054 inline const Basic_PThread& operator=( const Basic_PThread& src );
00055
00056 public:
00057
00058 inline pid_t getPID();
00059
00060
00061
00062 virtual void run() = 0;
00063
00064
00065
00066
00067
00068
00069
00070 static void* Basic_PThread::Wrapper( void* ptrThis )
00071 {
00072 Basic_PThread* me = (Basic_PThread*)ptrThis;
00073
00074
00075
00076 me->run();
00077
00078
00079
00080
00081 me->pid = (unsigned)(-1);
00082 pthread_exit( NULL );
00083
00084 return NULL;
00085 }
00086
00087 inline void start( int start_prio = 20 );
00088
00089 inline void yield();
00090
00091 inline void stop();
00092 inline void end();
00093
00094 inline BOOL isStarted();
00095
00096
00097 inline void join( void** value_ptr = NULL );
00098
00099 inline void detach();
00100
00101 protected:
00102
00103 pid_t pid;
00104 BOOL isDetached;
00105 pthread_attr_t attr;
00106 sched_param param;
00107 };
00108
00109
00110 #endif