mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 11:58:52 +00:00
add 'ast_cond_t' type for pthread condition variables, and appropriate API wrappers
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6877 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
10
cdr.c
10
cdr.c
@@ -91,7 +91,7 @@ AST_MUTEX_DEFINE_STATIC(cdr_batch_lock);
|
||||
|
||||
/* these are used to wake up the CDR thread when there's work to do */
|
||||
AST_MUTEX_DEFINE_STATIC(cdr_pending_lock);
|
||||
static pthread_cond_t cdr_pending_cond;
|
||||
static ast_cond_t cdr_pending_cond;
|
||||
|
||||
/*
|
||||
* We do a lot of checking here in the CDR code to try to be sure we don't ever let a CDR slip
|
||||
@@ -956,7 +956,7 @@ static void submit_unscheduled_batch(void)
|
||||
cdr_sched = ast_sched_add(sched, 1, submit_scheduled_batch, NULL);
|
||||
/* signal the do_cdr thread to wakeup early and do some work (that lazy thread ;) */
|
||||
ast_mutex_lock(&cdr_pending_lock);
|
||||
pthread_cond_signal(&cdr_pending_cond);
|
||||
ast_cond_signal(&cdr_pending_cond);
|
||||
ast_mutex_unlock(&cdr_pending_lock);
|
||||
}
|
||||
|
||||
@@ -1032,7 +1032,7 @@ static void *do_cdr(void *data)
|
||||
timeout.tv_nsec = (now.tv_usec * 1000) + ((schedms % 1000) * 1000);
|
||||
/* prevent stuff from clobbering cdr_pending_cond, then wait on signals sent to it until the timeout expires */
|
||||
ast_mutex_lock(&cdr_pending_lock);
|
||||
ast_pthread_cond_timedwait(&cdr_pending_cond, &cdr_pending_lock, &timeout);
|
||||
ast_cond_timedwait(&cdr_pending_cond, &cdr_pending_lock, &timeout);
|
||||
numevents = ast_sched_runq(sched);
|
||||
ast_mutex_unlock(&cdr_pending_lock);
|
||||
if (option_debug > 1)
|
||||
@@ -1179,7 +1179,7 @@ static int do_reload(void)
|
||||
/* if this reload enabled the CDR batch mode, create the background thread
|
||||
if it does not exist */
|
||||
if (enabled && batchmode && (!was_enabled || !was_batchmode) && (cdr_thread == AST_PTHREADT_NULL)) {
|
||||
pthread_cond_init(&cdr_pending_cond, NULL);
|
||||
ast_cond_init(&cdr_pending_cond, NULL);
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
if (ast_pthread_create(&cdr_thread, &attr, do_cdr, NULL) < 0) {
|
||||
@@ -1198,7 +1198,7 @@ static int do_reload(void)
|
||||
pthread_kill(cdr_thread, SIGURG);
|
||||
pthread_join(cdr_thread, NULL);
|
||||
cdr_thread = AST_PTHREADT_NULL;
|
||||
pthread_cond_destroy(&cdr_pending_cond);
|
||||
ast_cond_destroy(&cdr_pending_cond);
|
||||
ast_cli_unregister(&cli_submit);
|
||||
ast_unregister_atexit(ast_cdr_engine_term);
|
||||
res = 0;
|
||||
|
@@ -67,7 +67,7 @@ struct state_change {
|
||||
static AST_LIST_HEAD_STATIC(state_changes, state_change);
|
||||
|
||||
static pthread_t change_thread = AST_PTHREADT_NULL;
|
||||
static pthread_cond_t change_pending;
|
||||
static ast_cond_t change_pending;
|
||||
|
||||
/*--- devstate2str: Find devicestate as text message for output */
|
||||
const char *devstate2str(int devstate)
|
||||
@@ -216,7 +216,7 @@ static int __ast_device_state_changed_literal(char *buf)
|
||||
AST_LIST_INSERT_TAIL(&state_changes, change, list);
|
||||
if (AST_LIST_FIRST(&state_changes) == change)
|
||||
/* the list was empty, signal the thread */
|
||||
pthread_cond_signal(&change_pending);
|
||||
ast_cond_signal(&change_pending);
|
||||
AST_LIST_UNLOCK(&state_changes);
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ static void *do_devstate_changes(void *data)
|
||||
} else {
|
||||
/* there was no entry, so atomically unlock the list and wait for
|
||||
the condition to be signalled (returns with the lock held) */
|
||||
ast_pthread_cond_wait(&change_pending, &state_changes.lock);
|
||||
ast_cond_wait(&change_pending, &state_changes.lock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ int ast_device_state_engine_init(void)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
|
||||
pthread_cond_init(&change_pending, NULL);
|
||||
ast_cond_init(&change_pending, NULL);
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
if (ast_pthread_create(&change_thread, &attr, do_devstate_changes, NULL) < 0) {
|
||||
|
@@ -91,6 +91,8 @@ struct ast_mutex_info {
|
||||
|
||||
typedef struct ast_mutex_info ast_mutex_t;
|
||||
|
||||
typedef pthread_cond_t ast_cond_t;
|
||||
|
||||
static inline int __ast_pthread_mutex_init_attr(const char *filename, int lineno, const char *func,
|
||||
const char *mutex_name, ast_mutex_t *t,
|
||||
pthread_mutexattr_t *attr)
|
||||
@@ -341,8 +343,33 @@ static inline int __ast_pthread_mutex_unlock(const char *filename, int lineno, c
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline int __ast_pthread_cond_init(const char *filename, int lineno, const char *func,
|
||||
const char *cond_name, ast_cond_t *cond, pthread_condattr_t *cond_attr)
|
||||
{
|
||||
return pthread_cond_init(cond, cond_attr);
|
||||
}
|
||||
|
||||
static inline int __ast_pthread_cond_signal(const char *filename, int lineno, const char *func,
|
||||
const char *cond_name, ast_cond_t *cond)
|
||||
{
|
||||
return pthread_cond_signal(cond);
|
||||
}
|
||||
|
||||
static inline int __ast_pthread_cond_broadcast(const char *filename, int lineno, const char *func,
|
||||
const char *cond_name, ast_cond_t *cond)
|
||||
{
|
||||
return pthread_cond_broadcast(cond);
|
||||
}
|
||||
|
||||
static inline int __ast_pthread_cond_destroy(const char *filename, int lineno, const char *func,
|
||||
const char *cond_name, ast_cond_t *cond)
|
||||
{
|
||||
return pthread_cond_destroy(cond);
|
||||
}
|
||||
|
||||
static inline int __ast_pthread_cond_wait(const char *filename, int lineno, const char *func,
|
||||
pthread_cond_t *cond, const char *mutex_name, ast_mutex_t *t)
|
||||
const char *cond_name, const char *mutex_name,
|
||||
ast_cond_t *cond, ast_mutex_t *t)
|
||||
{
|
||||
int res;
|
||||
int canlog = strcmp(filename, "logger.c");
|
||||
@@ -400,8 +427,8 @@ static inline int __ast_pthread_cond_wait(const char *filename, int lineno, cons
|
||||
}
|
||||
|
||||
static inline int __ast_pthread_cond_timedwait(const char *filename, int lineno, const char *func,
|
||||
pthread_cond_t *cond, const struct timespec *abstime,
|
||||
const char *mutex_name, ast_mutex_t *t)
|
||||
const char *cond_name, const char *mutex_name, ast_cond_t *cond,
|
||||
ast_mutex_t *t, const struct timespec *abstime)
|
||||
{
|
||||
int res;
|
||||
int canlog = strcmp(filename, "logger.c");
|
||||
@@ -459,22 +486,16 @@ static inline int __ast_pthread_cond_timedwait(const char *filename, int lineno,
|
||||
}
|
||||
|
||||
#define ast_mutex_init(pmutex) __ast_pthread_mutex_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex)
|
||||
#define ast_pthread_mutex_init(pmutex,attr) __ast_pthread_mutex_init_attr(__FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex, attr)
|
||||
#define ast_mutex_destroy(a) __ast_pthread_mutex_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
|
||||
#define ast_mutex_lock(a) __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
|
||||
#define ast_mutex_unlock(a) __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
|
||||
#define ast_mutex_trylock(a) __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
|
||||
#define ast_pthread_cond_wait(cond, a) __ast_pthread_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, cond, #a, a)
|
||||
#define ast_pthread_cond_timedwait(cond, a, t) __ast_pthread_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, cond, t, #a, a)
|
||||
|
||||
#define pthread_mutex_t use_ast_mutex_t_instead_of_pthread_mutex_t
|
||||
#define pthread_mutex_lock use_ast_mutex_lock_instead_of_pthread_mutex_lock
|
||||
#define pthread_mutex_unlock use_ast_mutex_unlock_instead_of_pthread_mutex_unlock
|
||||
#define pthread_mutex_trylock use_ast_mutex_trylock_instead_of_pthread_mutex_trylock
|
||||
#define pthread_mutex_init use_ast_pthread_mutex_init_instead_of_pthread_mutex_init
|
||||
#define pthread_mutex_destroy use_ast_pthread_mutex_destroy_instead_of_pthread_mutex_destroy
|
||||
#define pthread_cond_wait use_ast_pthread_cond_wait_instead_of_pthread_cond_wait
|
||||
#define pthread_cond_timedwait use_ast_pthread_cond_wait_instead_of_pthread_cond_timedwait
|
||||
#define ast_cond_init(cond, attr) __ast_pthread_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr)
|
||||
#define ast_cond_destroy(cond) __ast_pthread_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
|
||||
#define ast_cond_signal(cond) __ast_pthread_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
|
||||
#define ast_cond_broadcast(cond) __ast_pthread_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
|
||||
#define ast_cond_wait(cond, mutex) __ast_pthread_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex)
|
||||
#define ast_cond_timedwait(cond, mutex, time) __ast_pthread_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time)
|
||||
|
||||
#else /* !DEBUG_THREADS */
|
||||
|
||||
@@ -540,11 +561,31 @@ static inline int ast_mutex_trylock(ast_mutex_t *pmutex)
|
||||
#define ast_mutex_trylock(pmutex) pthread_mutex_trylock(pmutex)
|
||||
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
|
||||
|
||||
#define ast_pthread_cond_wait pthread_cond_wait
|
||||
#define ast_pthread_cond_timedwait pthread_cond_timedwait
|
||||
typedef pthread_cond_t ast_cond_t
|
||||
|
||||
#define ast_cond_init pthread_cond_init
|
||||
#define ast_cond_destroy pthread_cond_destroy
|
||||
#define ast_cond_signal pthread_cond_signal
|
||||
#define ast_cond_broadcast pthread_cond_broadcast
|
||||
#define ast_cond_wait pthread_cond_wait
|
||||
#define ast_cond_timedwait pthread_cond_timedwait
|
||||
|
||||
#endif /* !DEBUG_THREADS */
|
||||
|
||||
#define pthread_mutex_t use_ast_mutex_t_instead_of_pthread_mutex_t
|
||||
#define pthread_mutex_lock use_ast_mutex_lock_instead_of_pthread_mutex_lock
|
||||
#define pthread_mutex_unlock use_ast_mutex_unlock_instead_of_pthread_mutex_unlock
|
||||
#define pthread_mutex_trylock use_ast_mutex_trylock_instead_of_pthread_mutex_trylock
|
||||
#define pthread_mutex_init use_ast_mutex_init_instead_of_pthread_mutex_init
|
||||
#define pthread_mutex_destroy use_ast_mutex_destroy_instead_of_pthread_mutex_destroy
|
||||
#define pthread_cond_t use_ast_cond_t_instead_of_pthread_cond_t
|
||||
#define pthread_cond_init use_ast_cond_init_instead_of_pthread_cond_init
|
||||
#define pthread_cond_destroy use_ast_cond_destroy_instead_of_pthread_cond_destroy
|
||||
#define pthread_cond_signal use_ast_cond_signal_instead_of_pthread_cond_signal
|
||||
#define pthread_cond_broadcast use_ast_cond_broadcast_instead_of_pthread_cond_broadcast
|
||||
#define pthread_cond_wait use_ast_cond_wait_instead_of_pthread_cond_wait
|
||||
#define pthread_cond_timedwait use_ast_cond_wait_instead_of_pthread_cond_timedwait
|
||||
|
||||
#define AST_MUTEX_DEFINE_STATIC(mutex) __AST_MUTEX_DEFINE(static,mutex)
|
||||
#define AST_MUTEX_DEFINE_EXPORTED(mutex) __AST_MUTEX_DEFINE(/**/,mutex)
|
||||
|
||||
|
Reference in New Issue
Block a user