Loading...
Searching...
No Matches
mutex.h
Go to the documentation of this file.
#ifndef JANUS_MUTEX_H
#define JANUS_MUTEX_H
#include <pthread.h>
#include <errno.h>
#include "debug.h"
extern int lock_debug;
#ifdef USE_PTHREAD_MUTEX
typedef pthread_mutex_t janus_mutex;
#define janus_mutex_init(a) pthread_mutex_init(a,NULL)
#define JANUS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define janus_mutex_destroy(a) pthread_mutex_destroy(a)
#define janus_mutex_lock_nodebug(a) pthread_mutex_lock(a)
#define janus_mutex_lock_debug(a) { JANUS_PRINT("[%s:%s:%d:lock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); pthread_mutex_lock(a); }
#define janus_mutex_lock(a) { if(!lock_debug) { janus_mutex_lock_nodebug(a); } else { janus_mutex_lock_debug(a); } }
#define janus_mutex_trylock_nodebug(a) { ret = !pthread_mutex_trylock(a); }
#define janus_mutex_trylock_debug(a) { JANUS_PRINT("[%s:%s:%d:trylock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); ret = !pthread_mutex_trylock(a); }
#define janus_mutex_trylock(a) ({ int ret; if(!lock_debug) { janus_mutex_trylock_nodebug(a); } else { janus_mutex_trylock_debug(a); } ret; })
#define janus_mutex_unlock_nodebug(a) pthread_mutex_unlock(a)
#define janus_mutex_unlock_debug(a) { JANUS_PRINT("[%s:%s:%d:unlock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); pthread_mutex_unlock(a); }
#define janus_mutex_unlock(a) { if(!lock_debug) { janus_mutex_unlock_nodebug(a); } else { janus_mutex_unlock_debug(a); } }
typedef pthread_cond_t janus_condition;
#define janus_condition_init(a) pthread_cond_init(a,NULL)
#define janus_condition_destroy(a) pthread_cond_destroy(a)
#define janus_condition_wait(a, b) pthread_cond_wait(a, b);
#define janus_condition_wait_until(a, b, c) { \
const struct timespec jct = { \
.tv_sec = c / G_USEC_PER_SEC, \
.tv_nsec = (c % G_USEC_PER_SEC)*1000 \
}; \
pthread_cond_timedwait(a, b, &jct); \
}
#define janus_condition_signal(a) pthread_cond_signal(a);
#define janus_condition_broadcast(a) pthread_cond_broadcast(a);
#else
typedef GMutex janus_mutex;
#define janus_mutex_init(a) g_mutex_init(a)
#define JANUS_MUTEX_INITIALIZER {0}
#define janus_mutex_destroy(a) g_mutex_clear(a)
#define janus_mutex_lock_nodebug(a) g_mutex_lock(a)
#define janus_mutex_lock_debug(a) { JANUS_PRINT("[%s:%s:%d:lock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); g_mutex_lock(a); }
#define janus_mutex_lock(a) { if(!lock_debug) { janus_mutex_lock_nodebug(a); } else { janus_mutex_lock_debug(a); } }
#define janus_mutex_trylock_nodebug(a) { ret = g_mutex_trylock(a); }
#define janus_mutex_trylock_debug(a) { JANUS_PRINT("[%s:%s:%d:trylock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); ret = g_mutex_trylock(a); }
#define janus_mutex_trylock(a) ({ gboolean ret; if(!lock_debug) { janus_mutex_trylock_nodebug(a); } else { janus_mutex_trylock_debug(a); } ret; })
#define janus_mutex_unlock_nodebug(a) g_mutex_unlock(a)
#define janus_mutex_unlock_debug(a) { JANUS_PRINT("[%s:%s:%d:unlock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); g_mutex_unlock(a); }
#define janus_mutex_unlock(a) { if(!lock_debug) { janus_mutex_unlock_nodebug(a); } else { janus_mutex_unlock_debug(a); } }
typedef GCond janus_condition;
#define janus_condition_init(a) g_cond_init(a)
#define janus_condition_destroy(a) g_cond_clear(a)
#define janus_condition_wait(a, b) g_cond_wait(a, b);
#define janus_condition_wait_until(a, b, c) g_cond_wait_until(a, b, c);
#define janus_condition_signal(a) g_cond_signal(a);
#define janus_condition_broadcast(a) g_cond_broadcast(a);
#endif
#endif
debug.h
Logging and Debugging.
lock_debug
int lock_debug
Definition janus-cfgconv.c:38
janus_condition
GCond janus_condition
Janus condition implementation.
Definition mutex.h:100
janus_mutex
GMutex janus_mutex
Janus mutex implementation.
Definition mutex.h:73