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 {
|
struct CommsCtxt {
|
||||||
XW_UtilCtxt* util;
|
XW_UtilCtxt* util;
|
||||||
XW_DUtilCtxt* dutil;
|
XW_DUtilCtxt* dutil;
|
||||||
|
MutexState mutex;
|
||||||
|
|
||||||
pthread_mutex_t mutex;
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
pthread_t lockHolder;
|
pthread_t lockHolder;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
typedef struct StatsState {
|
typedef struct StatsState {
|
||||||
XP_U32* statsVals;
|
XP_U32* statsVals;
|
||||||
pthread_mutex_t mutex;
|
MutexState mutex;
|
||||||
} StatsState;
|
} StatsState;
|
||||||
|
|
||||||
static const XP_UCHAR* STATtoStr(STAT stat);
|
static const XP_UCHAR* STATtoStr(STAT stat);
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "xwmutex.h"
|
#include "xwmutex.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
initMutex( pthread_mutex_t* mutex, XP_Bool recursive )
|
initMutex( MutexState* mutex, XP_Bool recursive )
|
||||||
{
|
{
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
int ret = pthread_mutexattr_init(&attr);
|
int ret = pthread_mutexattr_init(&attr);
|
||||||
|
@ -30,7 +30,7 @@ initMutex( pthread_mutex_t* mutex, XP_Bool recursive )
|
||||||
PTHREAD_MUTEX_RECURSIVE);
|
PTHREAD_MUTEX_RECURSIVE);
|
||||||
XP_ASSERT(0 == ret);
|
XP_ASSERT(0 == ret);
|
||||||
}
|
}
|
||||||
pthread_mutex_init( mutex, &attr );
|
pthread_mutex_init( &mutex->mutex, &attr );
|
||||||
ret = pthread_mutexattr_destroy(&attr);
|
ret = pthread_mutexattr_destroy(&attr);
|
||||||
XP_ASSERT(0 == ret);
|
XP_ASSERT(0 == ret);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,20 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "xptypes.h"
|
#include "xptypes.h"
|
||||||
|
|
||||||
#define WITH_MUTEX_LOCK_DEBUG(MUTEX) { \
|
/* Making this a struct in case I want to add e.g. a chain of holders */
|
||||||
pthread_mutex_t* _mutex = (MUTEX); \
|
typedef struct _MutexState {
|
||||||
time_t startTime = time(NULL); \
|
pthread_mutex_t mutex;
|
||||||
pthread_mutex_lock(_mutex); \
|
} MutexState;
|
||||||
time_t gotItTime = time(NULL); \
|
|
||||||
time_t _elapsed = gotItTime-startTime; \
|
#define WITH_MUTEX_LOCK_DEBUG(STATEP) { \
|
||||||
if ( 0 < _elapsed ) { \
|
MutexState* _state = (STATEP); \
|
||||||
XP_LOGFF("took %lds to get mutex", _elapsed); \
|
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() \
|
#define WITH_MUTEX_UNLOCK_DEBUG() \
|
||||||
time_t unlockTime = time(NULL); \
|
time_t unlockTime = time(NULL); \
|
||||||
|
@ -39,7 +44,7 @@
|
||||||
if ( 0 < _elapsed ) { \
|
if ( 0 < _elapsed ) { \
|
||||||
XP_LOGFF("held mutex for %lds", _elapsed); \
|
XP_LOGFF("held mutex for %lds", _elapsed); \
|
||||||
} \
|
} \
|
||||||
pthread_mutex_unlock(_mutex); \
|
pthread_mutex_unlock(&_state->mutex); \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
#define WITH_MUTEX_LOCK_RELEASE(COMMS) { \
|
#define WITH_MUTEX_LOCK_RELEASE(COMMS) { \
|
||||||
|
@ -58,6 +63,6 @@
|
||||||
#define END_WITH_MUTEX WITH_MUTEX_UNLOCK_RELEASE
|
#define END_WITH_MUTEX WITH_MUTEX_UNLOCK_RELEASE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void initMutex( pthread_mutex_t* mutex, XP_Bool recursive );
|
void initMutex( MutexState* mutex, XP_Bool recursive );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue