00001 #ifndef _FL_THREAD_LINUX_H_
00002 #define _FL_THREAD_LINUX_H_
00003
00004
00005
00006 bool Fl_Thread::create(thread_function function, void* arg)
00007 {
00008 bool result = true;
00009 _function = function;
00010 _arg = arg;
00011 _kill_thread = _th_running = 0;
00012 if(pthread_create(&_threadHandle, NULL, Fl_Thread::st_th_func, this))
00013 result = false;
00014 return result;
00015 }
00016
00017 void Fl_Thread::destroy(int exitcode)
00018 {
00019 pthread_cancel(_threadHandle);
00020 }
00021
00022 void Fl_Thread::join(int timeout)
00023 {
00024 void *result;
00025 pthread_join(_threadHandle, &result);
00026 }
00027
00028 int Fl_Thread::get_priority() const
00029 {
00030 return 0;
00031 }
00032
00033 int Fl_Thread::set_priority(unsigned int priority)
00034 {
00035 return 0;
00036 }
00037
00038 void Fl_Thread::destroy() { }
00039
00041
00042
00043
00044 #ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
00045
00046 extern pthread_mutexattr_t Fl_Mutex_attrib;
00047
00048 void Fl_Mutex::init() {
00049 pthread_mutex_init(&cs, &Fl_Mutex_attrib);
00050 }
00051
00052 void Fl_Mutex::lock() {
00053 pthread_mutex_lock(&cs);
00054 }
00055
00056 void Fl_Mutex::unlock() {
00057 pthread_mutex_unlock(&cs);
00058 }
00059
00060 #else
00061
00062
00063 void Fl_Mutex::init() {
00064 recursive_counter = 0;
00065 pthread_mutex_init(&cs, NULL);
00066 }
00067
00068 void Fl_Mutex::lock() {
00069 if(!recursive_counter || owner_ != pthread_self()) {
00070 pthread_mutex_lock(&cs);
00071 owner_ = pthread_self();
00072 }
00073 recursive_counter++;
00074 }
00075
00076 void Fl_Mutex::unlock() {
00077 if (!--recursive_counter)
00078 pthread_mutex_unlock(&cs);
00079 }
00080
00081 #endif
00082
00083 void Fl_Mutex::destroy() {
00084 pthread_mutex_destroy(&cs);
00085 }
00086
00087
00088 #endif