From: <laz...@us...> - 2004-03-05 21:37:54
|
Update of /cvsroot/rtk/rtk/src/core/platform/linux In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1183/src/core/platform/linux Modified Files: Mutex.cpp Thread.cpp Log Message: - Removed unneeded member variables / functions from Thread - Fixed linux Mutex initializer If you port something from efltk please, RTKlize it FIRST! And check that all variables are actually needed Index: Mutex.cpp =================================================================== RCS file: /cvsroot/rtk/rtk/src/core/platform/linux/Mutex.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Mutex.cpp 5 Mar 2004 18:18:25 -0000 1.1 --- Mutex.cpp 5 Mar 2004 21:15:39 -0000 1.2 *************** *** 42,45 **** --- 42,46 ---- #include <rtk/Mutex.h> + #include <rtk/debug.h> namespace Rtk *************** *** 48,88 **** // Linux supports recursive locks, use them directly, with some cheating: #ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP - extern pthread_mutexattr_t Mutex_attrib; ! void Mutex::Init() { ! pthread_mutex_init(&_cs, &Mutex_attrib); ! } ! void Mutex::Lock() { ! pthread_mutex_lock(&_cs); ! } ! void Mutex::Unlock() { ! pthread_mutex_unlock(&_cs); ! } #else - // standard pthread mutexes need a bit of work to be recursive: - void Mutex::Init() { - recursive_counter = 0; - pthread_mutex_init(&_cs, NULL); - } ! void Mutex::Lock() { ! if(!recursive_counter || owner_ != pthread_self()) { ! pthread_mutex_lock(&_cs); ! owner_ = pthread_self(); ! } ! recursive_counter++; } ! void Mutex::Unlock() { ! if (!--recursive_counter) ! pthread_mutex_unlock(&_cs); ! } // unlock() #endif void Mutex::Destroy() { pthread_mutex_destroy(&_cs); ! } // destroy() }; // Rtk --- 49,104 ---- // Linux supports recursive locks, use them directly, with some cheating: #ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ! static pthread_mutexattr_t mutex_attr = { PTHREAD_MUTEX_RECURSIVE_NP }; ! ! void Mutex::Init() { ! pthread_mutex_init(&_cs, &mutex_attr); ! } ! void Mutex::Lock() { ! pthread_mutex_lock(&_cs); ! } ! void Mutex::Unlock() { ! pthread_mutex_unlock(&_cs); ! } ! #else ! // standard pthread mutexes need a bit of work to be recursive: ! void Mutex::Init() ! { ! recursive_counter = 0; ! pthread_mutex_init(&_cs, NULL); ! owner_ = 0; ! } ! ! void Mutex::Lock() ! { ! if(recursive_counter==0 || owner_ != pthread_self()) { ! pthread_mutex_lock(&_cs); ! owner_ = pthread_self(); } + recursive_counter++; + } ! void Mutex::Unlock() ! { ! if(--recursive_counter == 0) ! pthread_mutex_unlock(&_cs); ! #if _DEBUG ! // This is bug in users code.. ! if(recursive_counter<0) { ! DBG(_R("Mutex recursive count < 0!! FATAL! Fix your code!\n")); ! exit(-1); ! } ! #endif ! } ! #endif void Mutex::Destroy() { pthread_mutex_destroy(&_cs); ! } }; // Rtk Index: Thread.cpp =================================================================== RCS file: /cvsroot/rtk/rtk/src/core/platform/linux/Thread.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Thread.cpp 5 Mar 2004 18:18:25 -0000 1.1 --- Thread.cpp 5 Mar 2004 21:15:39 -0000 1.2 *************** *** 69,74 **** _function = function; _arg = arg; ! _kill_thread = _running = 0; ! if (pthread_create((pthread_t*)(_thread_handle), NULL, thread_function, this)) result = false; return result; --- 69,74 ---- _function = function; _arg = arg; ! _running = 0; ! if (pthread_create(&_thread_handle, NULL, thread_function, this)) result = false; return result; *************** *** 77,81 **** void Thread::Terminate(int exitcode) { ! pthread_cancel(*((pthread_t*)(_thread_handle))); } --- 77,81 ---- void Thread::Terminate(int exitcode) { ! pthread_cancel(_thread_handle); } *************** *** 83,97 **** { void *result; ! return (bool)pthread_join(*((pthread_t*)(_thread_handle)), &result); } int Thread::GetPriority() const { ! return 0; } int Thread::SetPriority(int priority) { ! return 0; } --- 83,97 ---- { void *result; ! return (bool)pthread_join(_thread_handle, &result); } int Thread::GetPriority() const { ! return -1; } int Thread::SetPriority(int priority) { ! return -1; } |