Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Asterisk locking-related definitions: More...
#include <pthread.h>
#include <time.h>
#include <sys/param.h>
#include <execinfo.h>
#include "asterisk/backtrace.h"
#include "asterisk/logger.h"
#include "asterisk/compiler.h"
#include "asterisk/inline_api.h"
Go to the source code of this file.
Data Structures | |
struct | ast_lock_track |
Lock tracking information. More... | |
struct | ast_lock_track_flags |
struct | ast_mutex_info |
Structure for mutex and tracking information. More... | |
struct | ast_rwlock_info |
Structure for rwlock and tracking information. More... | |
Macros | |
#define | __AST_MUTEX_DEFINE(scope, mutex, init_val, track) scope ast_mutex_t mutex = init_val |
#define | __AST_RWLOCK_DEFINE(scope, rwlock, init_val, track) scope ast_rwlock_t rwlock = init_val |
#define | __AST_RWLOCK_INIT_VALUE PTHREAD_RWLOCK_INITIALIZER |
#define | AO2_DEADLOCK_AVOIDANCE(obj) |
#define | ast_cond_broadcast(cond) __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond) |
#define | ast_cond_destroy(cond) __ast_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond) |
#define | ast_cond_init(cond, attr) __ast_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr) |
#define | ast_cond_signal(cond) __ast_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond) |
#define | ast_cond_timedwait(cond, mutex, time) __ast_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time) |
#define | ast_cond_wait(cond, mutex) __ast_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex) |
#define | AST_LOCK_TRACK_INIT_VALUE { { NULL }, { 0 }, 0, { NULL }, { 0 }, {{{ 0 }}}, PTHREAD_MUTEX_INIT_VALUE } |
#define | AST_MAX_REENTRANCY 10 |
#define | AST_MUTEX_DEFINE_STATIC(mutex) __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE, 1) |
#define | AST_MUTEX_DEFINE_STATIC_NOTRACKING(mutex) __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE_NOTRACKING, 0) |
#define | ast_mutex_destroy(a) __ast_pthread_mutex_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a) |
#define | ast_mutex_init(pmutex) __ast_pthread_mutex_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex) |
#define | ast_mutex_init_notracking(pmutex) __ast_pthread_mutex_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex) |
#define | AST_MUTEX_INIT_VALUE { PTHREAD_MUTEX_INIT_VALUE, NULL, {1, 0} } |
#define | AST_MUTEX_INIT_VALUE_NOTRACKING { PTHREAD_MUTEX_INIT_VALUE, NULL, {0, 0} } |
#define | AST_MUTEX_INITIALIZER __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__ |
#define | AST_MUTEX_KIND PTHREAD_MUTEX_RECURSIVE_NP |
#define | ast_mutex_lock(a) __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a) |
#define | ast_mutex_trylock(a) __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a) |
#define | ast_mutex_unlock(a) __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a) |
#define | AST_PTHREADT_NULL (pthread_t) -1 |
#define | AST_PTHREADT_STOP (pthread_t) -2 |
#define | AST_RWLOCK_DEFINE_STATIC(rwlock) __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE, 1) |
#define | AST_RWLOCK_DEFINE_STATIC_NOTRACKING(rwlock) __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE_NOTRACKING, 0) |
#define | ast_rwlock_destroy(rwlock) __ast_rwlock_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock) |
#define | ast_rwlock_init(rwlock) __ast_rwlock_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock) |
wrapper for rwlock with tracking enabled More... | |
#define | ast_rwlock_init_notracking(rwlock) __ast_rwlock_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock) |
wrapper for ast_rwlock_init with tracking disabled More... | |
#define | AST_RWLOCK_INIT_VALUE { __AST_RWLOCK_INIT_VALUE, NULL, {1, 0} } |
#define | AST_RWLOCK_INIT_VALUE_NOTRACKING { __AST_RWLOCK_INIT_VALUE, NULL, {0, 0} } |
#define | ast_rwlock_rdlock(a) __ast_rwlock_rdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define | ast_rwlock_timedrdlock(a, b) __ast_rwlock_timedrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a, b) |
#define | ast_rwlock_timedwrlock(a, b) __ast_rwlock_timedwrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a, b) |
#define | ast_rwlock_tryrdlock(a) __ast_rwlock_tryrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define | ast_rwlock_trywrlock(a) __ast_rwlock_trywrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define | ast_rwlock_unlock(a) __ast_rwlock_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define | ast_rwlock_wrlock(a) __ast_rwlock_wrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define | CHANNEL_DEADLOCK_AVOIDANCE(chan) |
#define | DEADLOCK_AVOIDANCE(lock) |
#define | DLA_LOCK(lock) ast_mutex_lock(lock) |
#define | DLA_UNLOCK(lock) ast_mutex_unlock(lock) |
#define | gethostbyname __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__ |
#define | pthread_cond_broadcast use_ast_cond_broadcast_instead_of_pthread_cond_broadcast |
#define | pthread_cond_destroy use_ast_cond_destroy_instead_of_pthread_cond_destroy |
#define | pthread_cond_init use_ast_cond_init_instead_of_pthread_cond_init |
#define | pthread_cond_signal use_ast_cond_signal_instead_of_pthread_cond_signal |
#define | pthread_cond_t use_ast_cond_t_instead_of_pthread_cond_t |
#define | pthread_cond_timedwait use_ast_cond_timedwait_instead_of_pthread_cond_timedwait |
#define | pthread_cond_wait use_ast_cond_wait_instead_of_pthread_cond_wait |
#define | pthread_create __use_ast_pthread_create_instead__ |
#define | pthread_mutex_destroy use_ast_mutex_destroy_instead_of_pthread_mutex_destroy |
#define | pthread_mutex_init use_ast_mutex_init_instead_of_pthread_mutex_init |
#define | PTHREAD_MUTEX_INIT_VALUE PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP |
#define | pthread_mutex_lock use_ast_mutex_lock_instead_of_pthread_mutex_lock |
#define | pthread_mutex_t use_ast_mutex_t_instead_of_pthread_mutex_t |
#define | pthread_mutex_trylock use_ast_mutex_trylock_instead_of_pthread_mutex_trylock |
#define | pthread_mutex_unlock use_ast_mutex_unlock_instead_of_pthread_mutex_unlock |
#define | ROFFSET ((lt->reentrancy > 0) ? (lt->reentrancy-1) : 0) |
#define | SCOPED_AO2LOCK(varname, obj) SCOPED_LOCK(varname, (obj), ao2_lock, ao2_unlock) |
scoped lock specialization for ao2 mutexes. More... | |
#define | SCOPED_AO2RDLOCK(varname, obj) SCOPED_LOCK(varname, (obj), ao2_rdlock, ao2_unlock) |
scoped lock specialization for ao2 read locks. More... | |
#define | SCOPED_AO2WRLOCK(varname, obj) SCOPED_LOCK(varname, (obj), ao2_wrlock, ao2_unlock) |
scoped lock specialization for ao2 write locks. More... | |
#define | SCOPED_CHANNELLOCK(varname, chan) SCOPED_LOCK(varname, (chan), ast_channel_lock, ast_channel_unlock) |
scoped lock specialization for channels. More... | |
#define | SCOPED_LOCK(varname, lock, lockfunc, unlockfunc) RAII_VAR(typeof((lock)), varname, ({lockfunc((lock)); (lock); }), unlockfunc) |
Scoped Locks. More... | |
#define | SCOPED_MUTEX(varname, lock) SCOPED_LOCK(varname, (lock), ast_mutex_lock, ast_mutex_unlock) |
scoped lock specialization for mutexes More... | |
#define | SCOPED_RDLOCK(varname, lock) SCOPED_LOCK(varname, (lock), ast_rwlock_rdlock, ast_rwlock_unlock) |
scoped lock specialization for read locks More... | |
#define | SCOPED_WRLOCK(varname, lock) SCOPED_LOCK(varname, (lock), ast_rwlock_wrlock, ast_rwlock_unlock) |
scoped lock specialization for write locks More... | |
Typedefs | |
typedef pthread_cond_t | ast_cond_t |
typedef struct ast_mutex_info | ast_mutex_t |
typedef struct ast_rwlock_info | ast_rwlock_t |
Functions | |
int | __ast_cond_broadcast (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond) |
int | __ast_cond_destroy (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond) |
int | __ast_cond_init (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond, pthread_condattr_t *cond_attr) |
int | __ast_cond_signal (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond) |
int | __ast_cond_timedwait (const char *filename, int lineno, const char *func, const char *cond_name, const char *mutex_name, ast_cond_t *cond, ast_mutex_t *t, const struct timespec *abstime) |
int | __ast_cond_wait (const char *filename, int lineno, const char *func, const char *cond_name, const char *mutex_name, ast_cond_t *cond, ast_mutex_t *t) |
int | __ast_pthread_mutex_destroy (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t) |
int | __ast_pthread_mutex_init (int tracking, const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t) |
int | __ast_pthread_mutex_lock (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t) |
int | __ast_pthread_mutex_trylock (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t) |
int | __ast_pthread_mutex_unlock (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t) |
int | __ast_rwlock_destroy (const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t) |
int | __ast_rwlock_init (int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t) |
int | __ast_rwlock_rdlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name) |
int | __ast_rwlock_timedrdlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name, const struct timespec *abs_timeout) |
int | __ast_rwlock_timedwrlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name, const struct timespec *abs_timeout) |
int | __ast_rwlock_tryrdlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name) |
int | __ast_rwlock_trywrlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name) |
int | __ast_rwlock_unlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name) |
int | __ast_rwlock_wrlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name) |
#define | ast_atomic_add_fetch(ptr, val, memorder) __atomic_add_fetch((ptr), (val), (memorder)) |
#define | ast_atomic_and_fetch(ptr, val, memorder) __atomic_and_fetch((ptr), (val), (memorder)) |
int | ast_atomic_dec_and_test (volatile int *p) |
decrement *p by 1 and return true if the variable has reached 0. More... | |
#define | ast_atomic_fetch_add(ptr, val, memorder) __atomic_fetch_add((ptr), (val), (memorder)) |
Support for atomic instructions. More... | |
#define | ast_atomic_fetch_and(ptr, val, memorder) __atomic_fetch_and((ptr), (val), (memorder)) |
#define | ast_atomic_fetch_or(ptr, val, memorder) __atomic_fetch_or((ptr), (val), (memorder)) |
#define | ast_atomic_fetch_sub(ptr, val, memorder) __atomic_fetch_sub((ptr), (val), (memorder)) |
#define | ast_atomic_fetch_xor(ptr, val, memorder) __atomic_fetch_xor((ptr), (val), (memorder)) |
int | ast_atomic_fetchadd_int (volatile int *p, int v) |
Atomically add v to *p and return the previous value of *p. More... | |
#define | ast_atomic_flag_clear(ptr, val, memorder) ast_atomic_fetch_and((ptr), ~(val), (memorder)) |
#define | ast_atomic_flag_set(ptr, val, memorder) ast_atomic_fetch_or((ptr), (val), (memorder)) |
#define | ast_atomic_or_fetch(ptr, val, memorder) __atomic_or_fetch((ptr), (val), (memorder)) |
#define | ast_atomic_sub_fetch(ptr, val, memorder) __atomic_sub_fetch((ptr), (val), (memorder)) |
#define | ast_atomic_xor_fetch(ptr, val, memorder) __atomic_xor_fetch((ptr), (val), (memorder)) |
Asterisk locking-related definitions:
Magic number.
This is used to verify that a pointer is a valid astobj2 or ao2_weak reference.
options
and lockused
.Definition in file lock.h.
#define __AST_MUTEX_DEFINE | ( | scope, | |
mutex, | |||
init_val, | |||
track | |||
) | scope ast_mutex_t mutex = init_val |
#define __AST_RWLOCK_DEFINE | ( | scope, | |
rwlock, | |||
init_val, | |||
track | |||
) | scope ast_rwlock_t rwlock = init_val |
#define AO2_DEADLOCK_AVOIDANCE | ( | obj | ) |
Support for atomic instructions.
These macros implement a uniform interface to use built-in atomic functionality. If available __atomic built-ins are prefered. Legacy __sync built-ins are used as a fallback for older compilers.
Detailed documentation can be found in the GCC manual, all API's are modeled after the __atomic interfaces but using the namespace ast_atomic.
The memorder argument is always ignored by legacy __sync functions. Invalid memorder arguments do not produce errors unless __atomic functions are supported as the argument is erased by the preprocessor.
Atomic +=
#define ast_atomic_flag_clear | ( | ptr, | |
val, | |||
memorder | |||
) | ast_atomic_fetch_and((ptr), ~(val), (memorder)) |
#define ast_atomic_flag_set | ( | ptr, | |
val, | |||
memorder | |||
) | ast_atomic_fetch_or((ptr), (val), (memorder)) |
#define ast_cond_broadcast | ( | cond | ) | __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond) |
#define ast_cond_destroy | ( | cond | ) | __ast_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond) |
#define ast_cond_init | ( | cond, | |
attr | |||
) | __ast_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr) |
#define ast_cond_signal | ( | cond | ) | __ast_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond) |
#define ast_cond_timedwait | ( | cond, | |
mutex, | |||
time | |||
) | __ast_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time) |
#define ast_cond_wait | ( | cond, | |
mutex | |||
) | __ast_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex) |
#define AST_LOCK_TRACK_INIT_VALUE { { NULL }, { 0 }, 0, { NULL }, { 0 }, {{{ 0 }}}, PTHREAD_MUTEX_INIT_VALUE } |
#define AST_MUTEX_DEFINE_STATIC | ( | mutex | ) | __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE, 1) |
#define AST_MUTEX_DEFINE_STATIC_NOTRACKING | ( | mutex | ) | __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE_NOTRACKING, 0) |
#define ast_mutex_destroy | ( | a | ) | __ast_pthread_mutex_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a) |
#define ast_mutex_init | ( | pmutex | ) | __ast_pthread_mutex_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex) |
#define ast_mutex_init_notracking | ( | pmutex | ) | __ast_pthread_mutex_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex) |
#define AST_MUTEX_INIT_VALUE { PTHREAD_MUTEX_INIT_VALUE, NULL, {1, 0} } |
#define AST_MUTEX_INIT_VALUE_NOTRACKING { PTHREAD_MUTEX_INIT_VALUE, NULL, {0, 0} } |
#define AST_MUTEX_INITIALIZER __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__ |
#define ast_mutex_lock | ( | a | ) | __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a) |
#define ast_mutex_trylock | ( | a | ) | __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a) |
#define ast_mutex_unlock | ( | a | ) | __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a) |
#define AST_RWLOCK_DEFINE_STATIC | ( | rwlock | ) | __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE, 1) |
#define AST_RWLOCK_DEFINE_STATIC_NOTRACKING | ( | rwlock | ) | __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE_NOTRACKING, 0) |
#define ast_rwlock_destroy | ( | rwlock | ) | __ast_rwlock_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock) |
#define ast_rwlock_init | ( | rwlock | ) | __ast_rwlock_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock) |
#define ast_rwlock_init_notracking | ( | rwlock | ) | __ast_rwlock_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock) |
#define AST_RWLOCK_INIT_VALUE { __AST_RWLOCK_INIT_VALUE, NULL, {1, 0} } |
#define AST_RWLOCK_INIT_VALUE_NOTRACKING { __AST_RWLOCK_INIT_VALUE, NULL, {0, 0} } |
#define ast_rwlock_rdlock | ( | a | ) | __ast_rwlock_rdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define ast_rwlock_tryrdlock | ( | a | ) | __ast_rwlock_tryrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define ast_rwlock_trywrlock | ( | a | ) | __ast_rwlock_trywrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define ast_rwlock_unlock | ( | a | ) | __ast_rwlock_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define ast_rwlock_wrlock | ( | a | ) | __ast_rwlock_wrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a) |
#define CHANNEL_DEADLOCK_AVOIDANCE | ( | chan | ) |
#define DLA_LOCK | ( | lock | ) | ast_mutex_lock(lock) |
#define DLA_UNLOCK | ( | lock | ) | ast_mutex_unlock(lock) |
#define gethostbyname __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__ |
#define pthread_cond_broadcast use_ast_cond_broadcast_instead_of_pthread_cond_broadcast |
#define pthread_cond_destroy use_ast_cond_destroy_instead_of_pthread_cond_destroy |
#define pthread_cond_init use_ast_cond_init_instead_of_pthread_cond_init |
#define pthread_cond_signal use_ast_cond_signal_instead_of_pthread_cond_signal |
#define pthread_cond_t use_ast_cond_t_instead_of_pthread_cond_t |
#define pthread_cond_timedwait use_ast_cond_timedwait_instead_of_pthread_cond_timedwait |
#define pthread_cond_wait use_ast_cond_wait_instead_of_pthread_cond_wait |
#define pthread_mutex_destroy use_ast_mutex_destroy_instead_of_pthread_mutex_destroy |
#define pthread_mutex_init use_ast_mutex_init_instead_of_pthread_mutex_init |
#define PTHREAD_MUTEX_INIT_VALUE PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP |
#define pthread_mutex_lock use_ast_mutex_lock_instead_of_pthread_mutex_lock |
#define pthread_mutex_t use_ast_mutex_t_instead_of_pthread_mutex_t |
#define pthread_mutex_trylock use_ast_mutex_trylock_instead_of_pthread_mutex_trylock |
#define pthread_mutex_unlock use_ast_mutex_unlock_instead_of_pthread_mutex_unlock |
#define ROFFSET ((lt->reentrancy > 0) ? (lt->reentrancy-1) : 0) |
#define SCOPED_AO2LOCK | ( | varname, | |
obj | |||
) | SCOPED_LOCK(varname, (obj), ao2_lock, ao2_unlock) |
#define SCOPED_AO2RDLOCK | ( | varname, | |
obj | |||
) | SCOPED_LOCK(varname, (obj), ao2_rdlock, ao2_unlock) |
#define SCOPED_AO2WRLOCK | ( | varname, | |
obj | |||
) | SCOPED_LOCK(varname, (obj), ao2_wrlock, ao2_unlock) |
#define SCOPED_CHANNELLOCK | ( | varname, | |
chan | |||
) | SCOPED_LOCK(varname, (chan), ast_channel_lock, ast_channel_unlock) |
#define SCOPED_LOCK | ( | varname, | |
lock, | |||
lockfunc, | |||
unlockfunc | |||
) | RAII_VAR(typeof((lock)), varname, ({lockfunc((lock)); (lock); }), unlockfunc) |
Scoped Locks.
Scoped locks provide a way to use RAII locks. In other words, declaration of a scoped lock will automatically define and lock the lock. When the lock goes out of scope, it will automatically be unlocked.
In the above example, neither return path requires explicit unlocking of the channel.
varname | The unique name to give to the scoped lock. You are not likely to reference this outside of the SCOPED_LOCK invocation. |
lock | The variable to lock. This can be anything that can be passed to a locking or unlocking function. |
lockfunc | The function to call to lock the lock |
unlockfunc | The function to call to unlock the lock |
#define SCOPED_MUTEX | ( | varname, | |
lock | |||
) | SCOPED_LOCK(varname, (lock), ast_mutex_lock, ast_mutex_unlock) |
#define SCOPED_RDLOCK | ( | varname, | |
lock | |||
) | SCOPED_LOCK(varname, (lock), ast_rwlock_rdlock, ast_rwlock_unlock) |
#define SCOPED_WRLOCK | ( | varname, | |
lock | |||
) | SCOPED_LOCK(varname, (lock), ast_rwlock_wrlock, ast_rwlock_unlock) |
typedef pthread_cond_t ast_cond_t |
typedef struct ast_mutex_info ast_mutex_t |
typedef struct ast_rwlock_info ast_rwlock_t |
int __ast_cond_broadcast | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | cond_name, | ||
ast_cond_t * | cond | ||
) |
int __ast_cond_destroy | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | cond_name, | ||
ast_cond_t * | cond | ||
) |
int __ast_cond_init | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | cond_name, | ||
ast_cond_t * | cond, | ||
pthread_condattr_t * | cond_attr | ||
) |
int __ast_cond_signal | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | cond_name, | ||
ast_cond_t * | cond | ||
) |
int __ast_cond_timedwait | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | cond_name, | ||
const char * | mutex_name, | ||
ast_cond_t * | cond, | ||
ast_mutex_t * | t, | ||
const struct timespec * | abstime | ||
) |
Definition at line 631 of file lock.c.
References ast_lock_track::backtrace, cond, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_cond_timedwait, pthread_mutex_t, ast_lock_track::reentrancy, ROFFSET, and ast_lock_track::thread_id.
int __ast_cond_wait | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | cond_name, | ||
const char * | mutex_name, | ||
ast_cond_t * | cond, | ||
ast_mutex_t * | t | ||
) |
Definition at line 566 of file lock.c.
References ast_lock_track::backtrace, cond, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_cond_wait, pthread_mutex_t, ast_lock_track::reentrancy, ROFFSET, and ast_lock_track::thread_id.
int __ast_pthread_mutex_destroy | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | mutex_name, | ||
ast_mutex_t * | t | ||
) |
Definition at line 177 of file lock.c.
References ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, pthread_mutex_destroy, pthread_mutex_t, pthread_mutex_trylock, pthread_mutex_unlock, ast_lock_track::reentrancy, ROFFSET, and ast_lock_track::thread_id.
int __ast_pthread_mutex_init | ( | int | tracking, |
const char * | filename, | ||
int | lineno, | ||
const char * | func, | ||
const char * | mutex_name, | ||
ast_mutex_t * | t | ||
) |
Definition at line 145 of file lock.c.
References AST_MUTEX_KIND, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_mutex_init, and pthread_mutex_t.
int __ast_pthread_mutex_lock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | mutex_name, | ||
ast_mutex_t * | t | ||
) |
Definition at line 255 of file lock.c.
References ast_bt_get_addresses, ast_mark(), AST_MAX_REENTRANCY, AST_MUTEX, ast_lock_track::backtrace, EVENT_FLAG_SYSTEM, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, manager_event, ast_mutex_info::mutex, NULL, pthread_mutex_lock, pthread_mutex_trylock, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread_id, and tmp().
Referenced by __ao2_lock().
int __ast_pthread_mutex_trylock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | mutex_name, | ||
ast_mutex_t * | t | ||
) |
Definition at line 393 of file lock.c.
References ast_bt_get_addresses, ast_mark_lock_failed(), AST_MAX_REENTRANCY, AST_MUTEX, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_mutex_trylock, ast_lock_track::reentrancy, ast_lock_track::thread_id, and tmp().
Referenced by __ao2_trylock().
int __ast_pthread_mutex_unlock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | mutex_name, | ||
ast_mutex_t * | t | ||
) |
Definition at line 448 of file lock.c.
References AST_MAX_REENTRANCY, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_mutex_t, pthread_mutex_unlock, ast_lock_track::reentrancy, ROFFSET, and ast_lock_track::thread_id.
Referenced by __ao2_unlock().
int __ast_rwlock_destroy | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
const char * | rwlock_name, | ||
ast_rwlock_t * | t | ||
) |
Definition at line 730 of file lock.c.
References __AST_RWLOCK_INIT_VALUE, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, ast_lock_track::reentrancy, and ast_lock_track::thread_id.
int __ast_rwlock_init | ( | int | tracking, |
const char * | filename, | ||
int | lineno, | ||
const char * | func, | ||
const char * | rwlock_name, | ||
ast_rwlock_t * | t | ||
) |
Definition at line 696 of file lock.c.
References __AST_RWLOCK_INIT_VALUE, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, and NULL.
int __ast_rwlock_rdlock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
ast_rwlock_t * | t, | ||
const char * | name | ||
) |
Definition at line 848 of file lock.c.
References ast_bt_get_addresses, AST_MAX_REENTRANCY, AST_RDLOCK, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, name, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, and tmp().
Referenced by __ao2_global_obj_ref(), __ao2_lock(), and __ast_heap_rdlock().
int __ast_rwlock_timedrdlock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
ast_rwlock_t * | t, | ||
const char * | name, | ||
const struct timespec * | abs_timeout | ||
) |
Definition at line 1055 of file lock.c.
References ast_bt_get_addresses, AST_MAX_REENTRANCY, ast_tvnow(), AST_WRLOCK, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, name, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, and tmp().
int __ast_rwlock_timedwrlock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
ast_rwlock_t * | t, | ||
const char * | name, | ||
const struct timespec * | abs_timeout | ||
) |
Definition at line 1137 of file lock.c.
References ast_bt_get_addresses, AST_MAX_REENTRANCY, ast_tvnow(), AST_WRLOCK, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, name, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, and tmp().
int __ast_rwlock_tryrdlock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
ast_rwlock_t * | t, | ||
const char * | name | ||
) |
Definition at line 1219 of file lock.c.
References ast_bt_get_addresses, ast_mark_lock_failed(), AST_MAX_REENTRANCY, AST_RDLOCK, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, name, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, and tmp().
Referenced by __ao2_trylock().
int __ast_rwlock_trywrlock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
ast_rwlock_t * | t, | ||
const char * | name | ||
) |
Definition at line 1269 of file lock.c.
References ast_bt_get_addresses, ast_mark_lock_failed(), AST_MAX_REENTRANCY, AST_WRLOCK, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, name, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, and tmp().
Referenced by __ao2_trylock().
int __ast_rwlock_unlock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
ast_rwlock_t * | t, | ||
const char * | name | ||
) |
Definition at line 777 of file lock.c.
References __AST_RWLOCK_INIT_VALUE, AST_PTHREADT_NULL, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, name, NULL, ast_lock_track::reentrancy, and ast_lock_track::thread_id.
Referenced by __ao2_global_obj_ref(), __ao2_global_obj_replace(), __ao2_unlock(), and __ast_heap_unlock().
int __ast_rwlock_wrlock | ( | const char * | filename, |
int | lineno, | ||
const char * | func, | ||
ast_rwlock_t * | t, | ||
const char * | name | ||
) |
Definition at line 952 of file lock.c.
References ast_bt_get_addresses, AST_MAX_REENTRANCY, AST_WRLOCK, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, name, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, and tmp().
Referenced by __ao2_global_obj_replace(), __ao2_lock(), and __ast_heap_wrlock().
|
inline |
decrement *p by 1 and return true if the variable has reached 0.
Useful e.g. to check if a refcount has reached 0.
Definition at line 767 of file lock.h.
Referenced by dispose_conf(), iax2_process_thread_cleanup(), run_station(), and sla_station_exec().
|
inline |
Atomically add v to *p and return the previous value of *p.
This can be used to handle reference counts, and the return value can be used to generate unique identifiers.
Definition at line 757 of file lock.h.
Referenced by __ao2_link(), __ao2_lock(), __ao2_ref(), __ao2_trylock(), __ao2_unlock(), __ast_channel_alloc_ap(), __ast_channel_internal_alloc_with_initializers(), __ast_module_ref(), __ast_module_unref(), __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), __container_unlink_node_debug(), __manager_event_sessions_va(), acf_odbc_read(), action_login(), admin_exec(), advance_event(), ao2_container_count(), append_event(), ast_bridge_interval_hook(), ast_channel_destructor(), ast_channel_internal_setup_topics(), ast_cli_command_full(), ast_create_callid(), ast_odbc_execute_sql(), ast_odbc_prepare(), ast_odbc_prepare_and_execute(), ast_odbc_smart_execute(), ast_sip_schedule_task(), ast_taskprocessor_seq_num(), AST_TEST_DEFINE(), ast_undestroyed_channels(), ast_unreal_new_channels(), authenticate_verify(), bridge_channel_handle_interval(), bridge_channel_queue_action_data_sync(), build_conf(), cc_device_monitor_init(), cc_extension_monitor_init(), cc_interfaces_datastore_init(), cdr_object_alloc(), chan_pjsip_new(), container_destruct(), dahdi_destroy(), dahdi_request(), dahdi_translate(), destroy_session(), dial_append_common(), dispatch_message(), dns_query_set_callback(), dundi_query_read(), enum_query_read(), fax_session_new(), fax_session_release(), fax_session_reserve(), find_idle_thread(), find_load_queue_rt_friendly(), find_session(), find_transcoders(), generate_msg_id(), generic_fax_exec(), grab_last(), hash_ao2_container_init(), hash_test_grow(), hash_test_lookup(), hook_read(), ht_delete(), ht_new(), httpd_helper_thread(), iax2_destroy_helper(), iax2_process_thread(), iax_frame_free(), iax_frame_new(), inprocess_count(), internal_ao2_alloc(), internal_stasis_subscribe(), pjsip_history_entry_alloc(), publish_msg(), pubsub_on_rx_publish_request(), rb_ao2_container_init(), rec_request(), receivefax_exec(), reload_single_queue(), run_station(), sendfax_exec(), session_destructor(), session_do(), sip_create_publication(), sla_add_trunk_to_station(), sla_handle_hold_event(), sla_station_exec(), smdi_msg_retrieve_read(), spandsp_fax_switch_to_t38(), stasis_app_control_snoop(), stasis_caching_topic_create(), stasis_cp_all_create(), stasis_message_type_create(), transport_create(), try_merge_optimize_out(), try_swap_optimize_out(), update_stats(), and worker_thread_alloc().