From: Mikko L. <laz...@us...> - 2004-06-13 19:41:01
|
Update of /cvsroot/rtk/rtk/src/core/platform/linux In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv851/core/platform/linux Modified Files: File.cpp Mutex.cpp Log Message: Moved all includes to source file in Mutex, we dont want to include platform specific files in our public header! File works now Index: File.cpp =================================================================== RCS file: /cvsroot/rtk/rtk/src/core/platform/linux/File.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** File.cpp 13 Jun 2004 18:46:03 -0000 1.10 --- File.cpp 13 Jun 2004 19:40:51 -0000 1.11 *************** *** 223,227 **** } } ! RETURN_SUCCESS; } --- 223,228 ---- } } ! ! SetOpen(); RETURN_SUCCESS; } *************** *** 242,245 **** --- 243,249 ---- if(close(FD)<0) return false; + ClearOpen(); + _handle = INVALID_HANDLE_VALUE; + const RCHAR *file = _filename.c_str(); const char *afile = NULL; *************** *** 256,261 **** unlink(afile); - _handle = INVALID_HANDLE_VALUE; - return true; } --- 260,263 ---- Index: Mutex.cpp =================================================================== RCS file: /cvsroot/rtk/rtk/src/core/platform/linux/Mutex.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Mutex.cpp 9 Mar 2004 17:01:28 -0000 1.6 --- Mutex.cpp 13 Jun 2004 19:40:52 -0000 1.7 *************** *** 40,44 **** * - ***************************************************************************/ ! #include <rtk/Mutex.h> #include <rtk/debug.h> --- 40,49 ---- * - ***************************************************************************/ ! ! #include <stdlib.h> ! #include <pthread.h> ! #include <signal.h> ! #include <unistd.h> ! #include <rtk/Mutex.h> #include <rtk/debug.h> *************** *** 47,50 **** --- 52,64 ---- { + struct _private_data + { + pthread_mutex_t cs; + pthread_t owner; + int recursive_counter; + }; + + #define PRV ((struct _private_data*)_prv) + // Linux supports recursive locks, use them directly, with some cheating: #ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP *************** *** 53,65 **** void Mutex::Init() { ! pthread_mutex_init(&_cs, &mutex_attr); } void Mutex::Lock() { ! pthread_mutex_lock(&_cs); } void Mutex::Unlock() { ! pthread_mutex_unlock(&_cs); } --- 67,81 ---- void Mutex::Init() { ! _prv = malloc(sizeof(_private_data)); ! memset(_prv, 0, sizeof(_private_data)); ! pthread_mutex_init(&PRV->cs, &mutex_attr); } void Mutex::Lock() { ! pthread_mutex_lock(&PRV->cs); } void Mutex::Unlock() { ! pthread_mutex_unlock(&PRV->cs); } *************** *** 69,93 **** 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); #ifdef _DEBUG // This is bug in users code.. ! if (recursive_counter<0) { DBG(_R("Mutex recursive count < 0!! FATAL! Fix your code!\n")); exit(-1); --- 85,111 ---- void Mutex::Init() { ! _prv = malloc(sizeof(_private_data)); ! memset(_prv, 0, sizeof(_private_data)); ! PRV->recursive_counter = 0; ! pthread_mutex_init(&PRV->cs, NULL); ! PRV->owner = 0; } void Mutex::Lock() { ! if(PRV->recursive_counter==0 || PRV->owner != pthread_self()) { ! pthread_mutex_lock(&PRV->cs); ! PRV->owner = pthread_self(); } ! PRV->recursive_counter++; } void Mutex::Unlock() { ! if (--PRV->recursive_counter == 0) ! pthread_mutex_unlock(&PRV->cs); #ifdef _DEBUG // This is bug in users code.. ! if (PRV->recursive_counter<0) { DBG(_R("Mutex recursive count < 0!! FATAL! Fix your code!\n")); exit(-1); *************** *** 99,103 **** void Mutex::Destroy() { ! pthread_mutex_destroy(&_cs); } --- 117,123 ---- void Mutex::Destroy() { ! pthread_mutex_destroy(&PRV->cs); ! free(_prv); ! _prv = 0; } |