Changeset 21349 for trunk/psLib/src/sys/psMutex.h
- Timestamp:
- Feb 5, 2009, 3:06:45 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psMutex.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psMutex.h
r19232 r21349 17 17 18 18 // These bells and whistles are only defined if PS_MUTEX_CAREFUL and __USE_GNU are both defined 19 #define PS_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK_NP // Error-checking mutex 20 #define PS_MUTEX_TRACE(LEVEL, STRING, PTR) psTrace("psLib.sys.mutex", LEVEL, STRING, #PTR); // Trace message 21 #define PS_MUTEX_TRACE_THREAD(LEVEL, STRING, PTR) \ // Trace message with thread and pointer 22 psTrace("psLib.sys.mutex", LEVEL, STRING, (void*)pthread_self(), #PTR); 23 #define PS_MUTEX_CHECK_DEADLOCK() \ // Check for dead-locked mutex 19 20 // Error-checking mutex 21 #define PS_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK_NP 22 23 #define PS_MUTEX_TRACE(LEVEL, STRING, PTR) psTrace("psLib.sys.mutex", LEVEL, STRING, #PTR, (unsigned long) PTR); // Trace message 24 25 // Trace message with thread and pointer 26 #define PS_MUTEX_TRACE_THREAD(LEVEL, STRING, PTR) \ 27 psTrace("psLib.sys.mutex", LEVEL, STRING, (void*)pthread_self(), #PTR, (unsigned long) PTR); 28 29 // Check for dead-locked mutex 30 #define PS_MUTEX_CHECK_DEADLOCK(PTR) \ 24 31 if (pml == EDEADLK) { \ 25 psAbort("Deadlocked mutex on %s ", #PTR); \32 psAbort("Deadlocked mutex on %s (%lx)", #PTR, (unsigned long) PTR); \ 26 33 } 27 #define PS_MUTEX_CHECK_STOLEN(PTR) \ // Check for stolen mutex 34 35 // Check for stolen mutex 36 #define PS_MUTEX_CHECK_STOLEN(PTR) \ 28 37 if (pmu == EPERM) { \ 29 psAbort("Unlocking stolen mutex on %s ", #PTR);\38 psAbort("Unlocking stolen mutex on %s (%lx)", #PTR, (unsigned long) PTR); \ 30 39 } 31 40 … … 53 62 #define psMutexInit(PTR) { \ 54 63 psAssert(PTR, "Require non-NULL pointer to initialise mutex"); \ 55 PS_MUTEX_TRACE(3, "Initialising mutex on %s ...", PTR); \64 PS_MUTEX_TRACE(3, "Initialising mutex on %s (%lx)...", PTR); \ 56 65 /* Gotta go the long way, since we can't use PTHREAD_MUTEX_INITIALIZER after we declare the variable */ \ 57 66 pthread_mutexattr_t attr; /* Mutex attributes */ \ … … 65 74 #define psMutexLock(PTR) { \ 66 75 psAssert(PTR, "Require non-NULL pointer to lock mutex"); \ 67 PS_MUTEX_TRACE_THREAD(1, "Thread %p waiting for mutex lock on %s ...", PTR); \76 PS_MUTEX_TRACE_THREAD(1, "Thread %p waiting for mutex lock on %s (%lx)...", PTR); \ 68 77 int pml = pthread_mutex_lock(&(PTR)->lock); \ 69 PS_MUTEX_TRACE_THREAD(1, "Thread %p locked mutex on %s ", PTR); \78 PS_MUTEX_TRACE_THREAD(1, "Thread %p locked mutex on %s (%lx)", PTR); \ 70 79 if (pml == EINVAL) { \ 71 psAbort("Cannot lock mutex on %s : not initialised", #PTR); \80 psAbort("Cannot lock mutex on %s (%lx): not initialised", #PTR, (unsigned long) PTR); \ 72 81 } \ 73 82 PS_MUTEX_CHECK_DEADLOCK(PTR); \ … … 77 86 #define psMutexUnlock(PTR) { \ 78 87 psAssert(PTR, "Require non-NULL pointer to unlock mutex"); \ 79 PS_MUTEX_TRACE_THREAD(1, "Thread %p unlocking mutex on %s ", PTR); \88 PS_MUTEX_TRACE_THREAD(1, "Thread %p unlocking mutex on %s (%lx)", PTR); \ 80 89 int pmu = pthread_mutex_unlock(&(PTR)->lock); \ 81 90 if (pmu == EINVAL) { \ 82 psAbort("Cannot unlock mutex on %s : not initialised", #PTR); \91 psAbort("Cannot unlock mutex on %s (%lx): not initialised", #PTR, (unsigned long) PTR); \ 83 92 } \ 84 93 PS_MUTEX_CHECK_STOLEN(PTR); \ … … 89 98 psAssert(PTR, "Require non-NULL pointer to destroy mutex"); \ 90 99 if (pthread_mutex_destroy(&(PTR)->lock) == EBUSY) { \ 91 psAbort("Cannot destroy mutex on %s : is busy", #PTR);\100 psAbort("Cannot destroy mutex on %s (%lx): is busy", #PTR, (unsigned long) PTR); \ 92 101 } \ 93 102 }
Note:
See TracChangeset
for help on using the changeset viewer.
