mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-15 08:47:56 +01:00
move mutex into a struct (for future dev advantage)
This commit is contained in:
parent
464e124038
commit
0a992c5a4b
4 changed files with 20 additions and 15 deletions
|
@ -116,8 +116,8 @@ typedef struct AddressRecord {
|
|||
struct CommsCtxt {
|
||||
XW_UtilCtxt* util;
|
||||
XW_DUtilCtxt* dutil;
|
||||
MutexState mutex;
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
#ifdef DEBUG
|
||||
pthread_t lockHolder;
|
||||
#endif
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
typedef struct StatsState {
|
||||
XP_U32* statsVals;
|
||||
pthread_mutex_t mutex;
|
||||
MutexState mutex;
|
||||
} StatsState;
|
||||
|
||||
static const XP_UCHAR* STATtoStr(STAT stat);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "xwmutex.h"
|
||||
|
||||
void
|
||||
initMutex( pthread_mutex_t* mutex, XP_Bool recursive )
|
||||
initMutex( MutexState* mutex, XP_Bool recursive )
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
int ret = pthread_mutexattr_init(&attr);
|
||||
|
@ -30,7 +30,7 @@ initMutex( pthread_mutex_t* mutex, XP_Bool recursive )
|
|||
PTHREAD_MUTEX_RECURSIVE);
|
||||
XP_ASSERT(0 == ret);
|
||||
}
|
||||
pthread_mutex_init( mutex, &attr );
|
||||
pthread_mutex_init( &mutex->mutex, &attr );
|
||||
ret = pthread_mutexattr_destroy(&attr);
|
||||
XP_ASSERT(0 == ret);
|
||||
}
|
||||
|
|
|
@ -23,15 +23,20 @@
|
|||
#include <pthread.h>
|
||||
#include "xptypes.h"
|
||||
|
||||
#define WITH_MUTEX_LOCK_DEBUG(MUTEX) { \
|
||||
pthread_mutex_t* _mutex = (MUTEX); \
|
||||
time_t startTime = time(NULL); \
|
||||
pthread_mutex_lock(_mutex); \
|
||||
time_t gotItTime = time(NULL); \
|
||||
time_t _elapsed = gotItTime-startTime; \
|
||||
if ( 0 < _elapsed ) { \
|
||||
XP_LOGFF("took %lds to get mutex", _elapsed); \
|
||||
} \
|
||||
/* Making this a struct in case I want to add e.g. a chain of holders */
|
||||
typedef struct _MutexState {
|
||||
pthread_mutex_t mutex;
|
||||
} MutexState;
|
||||
|
||||
#define WITH_MUTEX_LOCK_DEBUG(STATEP) { \
|
||||
MutexState* _state = (STATEP); \
|
||||
time_t startTime = time(NULL); \
|
||||
pthread_mutex_lock(&_state->mutex); \
|
||||
time_t gotItTime = time(NULL); \
|
||||
time_t _elapsed = gotItTime-startTime; \
|
||||
if ( 0 < _elapsed ) { \
|
||||
XP_LOGFF("took %lds to get mutex", _elapsed); \
|
||||
} \
|
||||
|
||||
#define WITH_MUTEX_UNLOCK_DEBUG() \
|
||||
time_t unlockTime = time(NULL); \
|
||||
|
@ -39,7 +44,7 @@
|
|||
if ( 0 < _elapsed ) { \
|
||||
XP_LOGFF("held mutex for %lds", _elapsed); \
|
||||
} \
|
||||
pthread_mutex_unlock(_mutex); \
|
||||
pthread_mutex_unlock(&_state->mutex); \
|
||||
} \
|
||||
|
||||
#define WITH_MUTEX_LOCK_RELEASE(COMMS) { \
|
||||
|
@ -58,6 +63,6 @@
|
|||
#define END_WITH_MUTEX WITH_MUTEX_UNLOCK_RELEASE
|
||||
#endif
|
||||
|
||||
void initMutex( pthread_mutex_t* mutex, XP_Bool recursive );
|
||||
void initMutex( MutexState* mutex, XP_Bool recursive );
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue