From 682a4b191a6947bd2bd504d0a6dbbb8d7370bdbb Mon Sep 17 00:00:00 2001 From: csoutheren Date: Wed, 5 Sep 2007 11:58:47 +0000 Subject: [PATCH] Fixed build on MacOSX --- include/ptlib/mutex.h | 5 +++- include/ptlib/semaphor.h | 4 +++ include/ptlib/unix/ptlib/semaphor.h | 9 ++---- src/ptlib/unix/tlibthrd.cxx | 56 ++++++------------------------------- 4 files changed, 20 insertions(+), 54 deletions(-) diff --git a/include/ptlib/mutex.h b/include/ptlib/mutex.h index 7940b855..a3daed52 100644 --- a/include/ptlib/mutex.h +++ b/include/ptlib/mutex.h @@ -27,6 +27,9 @@ * Contributor(s): ______________________________________. * * $Log$ + * Revision 1.16 2007/09/05 11:58:47 csoutheren + * Fixed build on MacOSX + * * Revision 1.15 2007/09/05 11:09:09 csoutheren * Removed misleading and incorrect code from Linux implementation of * PCriticalSection. Apologies to Hannes Friederich :( @@ -159,7 +162,7 @@ class PTimedMutex : public PSync typedef PCriticalSection PMutex; #else typedef PTimedMutex PMutex; -typedef PTimedMutex PCriticalSection; +#define PCriticalSection PTimedMutex #endif #endif diff --git a/include/ptlib/semaphor.h b/include/ptlib/semaphor.h index 8c8b881f..0a2444f8 100644 --- a/include/ptlib/semaphor.h +++ b/include/ptlib/semaphor.h @@ -27,6 +27,9 @@ * Contributor(s): ______________________________________. * * $Log$ + * Revision 1.22 2007/09/05 11:58:47 csoutheren + * Fixed build on MacOSX + * * Revision 1.21 2005/11/25 03:43:47 csoutheren * Fixed function argument comments to be compatible with Doxygen * @@ -114,6 +117,7 @@ #include #include +#include /**This class defines a thread synchonisation object. This is in the form of a integer semaphore. The semaphore has a count and a maximum value. The diff --git a/include/ptlib/unix/ptlib/semaphor.h b/include/ptlib/unix/ptlib/semaphor.h index d5e51220..72040d41 100644 --- a/include/ptlib/unix/ptlib/semaphor.h +++ b/include/ptlib/unix/ptlib/semaphor.h @@ -27,11 +27,8 @@ * Contributor(s): ______________________________________. * * $Log$ - * Revision 1.26 2007/09/05 11:28:14 hfriederich - * Cleanup & protection against recursive initialization - * - * Revision 1.25 2007/09/05 08:03:25 hfriederich - * Implement PCriticalSection with named semaphores + * Revision 1.27 2007/09/05 11:58:47 csoutheren + * Fixed build on MacOSX * * Revision 1.24 2005/11/25 00:06:12 csoutheren * Applied patch #1364593 from Hannes Friederich @@ -145,7 +142,7 @@ mutable sem_t semId; #elif defined(P_HAS_NAMED_SEMAPHORES) mutable sem_t *semId; - static sem_t *CreateSem(unsigned initialValue); + sem_t *CreateSem(unsigned initialValue); #else mutable unsigned currentCount; mutable unsigned maximumCount; diff --git a/src/ptlib/unix/tlibthrd.cxx b/src/ptlib/unix/tlibthrd.cxx index 114a3214..2303514a 100644 --- a/src/ptlib/unix/tlibthrd.cxx +++ b/src/ptlib/unix/tlibthrd.cxx @@ -27,11 +27,8 @@ * Contributor(s): ______________________________________. * * $Log$ - * Revision 1.172 2007/09/05 11:28:15 hfriederich - * Cleanup & protection against recursive initialization - * - * Revision 1.171 2007/09/05 08:53:27 hfriederich - * Prevent recursive initialization when using named semaphores + * Revision 1.173 2007/09/05 11:58:47 csoutheren + * Fixed build on MacOSX * * Revision 1.170 2007/08/17 07:29:21 csoutheren * Fix build on MacOSX @@ -650,39 +647,6 @@ static BOOL PAssertThreadOp(int retval, return FALSE; } -#define PAssertPTHREAD_NoPTrace(func, args) \ - { \ - unsigned threadOpRetry = 0; \ - while (PAssertThreadOpNoPThread(func args, threadOpRetry, #func, __FILE__, __LINE__)); \ - } - - static BOOL PAssertThreadOpNoPThread(int retval, - unsigned & retry, - const char * funcname, - const char * file, - unsigned line) -{ - if (retval == 0) { - // Don't use PTrace here! - return FALSE; - } - - if (errno == EINTR || errno == EAGAIN) { - if (++retry < 1000) { -#if defined(P_RTEMS) - sched_yield(); -#else - usleep(10000); // Basically just swap out thread to try and clear blockage -#endif - return TRUE; // Return value to try again - } - // Give up and assert - } - - PAssertFunc(file, line, NULL, psprintf("Function %s failed", funcname)); - return FALSE; -} - PDECLARE_CLASS(PHouseKeepingThread, PThread) public: @@ -1605,16 +1569,14 @@ sem_t * PSemaphore::CreateSem(unsigned initialValue) // Since sem_open and sem_unlink are two operations, there is a small // window of opportunity that two simultaneous accesses may return // the same semaphore. Therefore, the static mutex is used to - // prevent this. - // Don't use PTRACE within the assertion macro as this will lead - // to a recursive initialization (__gnu_cxx::recursive_init) + // prevent this, even if the chances are small static pthread_mutex_t semCreationMutex = PTHREAD_MUTEX_INITIALIZER; - PAssertPTHREAD_NoPTrace(pthread_mutex_lock, (&semCreationMutex)); + PAssertPTHREAD(pthread_mutex_lock, (&semCreationMutex)); sem_unlink("/pwlib_sem"); sem = sem_open("/pwlib_sem", (O_CREAT | O_EXCL), 700, initialValue); - PAssertPTHREAD_NoPTrace(pthread_mutex_unlock, (&semCreationMutex)); + PAssertPTHREAD(pthread_mutex_unlock, (&semCreationMutex)); PAssert(((int)sem != SEM_FAILED), "Couldn't create named semaphore"); return sem; @@ -1792,10 +1754,10 @@ PTimedMutex::PTimedMutex() { #if P_HAS_RECURSIVE_MUTEX pthread_mutexattr_t attr; - PAssertPTHREAD_NoPTrace(pthread_mutexattr_init, (&attr)); - PAssertPTHREAD_NoPTrace(pthread_mutexattr_settype, (&attr, PTHREAD_MUTEX_RECURSIVE_NP)); - PAssertPTHREAD_NoPTrace(pthread_mutex_init, (&mutex, &attr)); - PAssertPTHREAD_NoPTrace(pthread_mutexattr_destroy, (&attr)); + PAssertPTHREAD(pthread_mutexattr_init, (&attr)); + PAssertPTHREAD(pthread_mutexattr_settype, (&attr, PTHREAD_MUTEX_RECURSIVE_NP)); + PAssertPTHREAD(pthread_mutex_init, (&mutex, &attr)); + PAssertPTHREAD(pthread_mutexattr_destroy, (&attr)); #else PAssertPTHREAD(pthread_mutex_init, (&mutex, NULL)); #endif -- 2.11.4.GIT