Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Typedefs | Enumerations | Functions
lock.h File Reference

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 <errno.h>
#include "asterisk/inline_api.h"
Include dependency graph for lock.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)
 Unlock a lock briefly. More...
 
#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)
 Deadlock avoidance lock. More...
 
#define DLA_UNLOCK(lock)
 Deadlock avoidance unlock. More...
 
#define DO_THREAD_CRASH   do { } while (0)
 
#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
 

Enumerations

enum  ast_lock_type { AST_MUTEX, AST_RDLOCK, AST_WRLOCK }
 

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)
 
struct ast_strast_dump_locks (void)
 Generate a lock dump equivalent to "core show locks". More...
 
int ast_find_lock_info (void *lock_addr, char *filename, size_t filename_size, int *lineno, char *func, size_t func_size, char *mutex_name, size_t mutex_name_size)
 retrieve lock info for the specified mutex More...
 
void ast_log_show_lock (void *this_lock_addr)
 log info for the current lock with ast_log(). More...
 
void ast_mark_lock_acquired (void *lock_addr)
 Mark the last lock as acquired. More...
 
void ast_mark_lock_failed (void *lock_addr)
 Mark the last lock as failed (trylock) More...
 
static void ast_reentrancy_lock (struct ast_lock_track *lt)
 
static void ast_reentrancy_unlock (struct ast_lock_track *lt)
 
void ast_remove_lock_info (void *lock_addr, struct ast_bt *bt)
 remove lock info for the current thread More...
 
void ast_restore_lock_info (void *lock_addr)
 
void ast_store_lock_info (enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
 Store lock info for the current thread. More...
 
void ast_suspend_lock_info (void *lock_addr)
 
#define ast_atomic_fetch_add(ptr, val, memorder)   __atomic_fetch_add((ptr), (val), (memorder))
 Support for atomic instructions. More...
 
#define ast_atomic_add_fetch(ptr, val, memorder)   __atomic_add_fetch((ptr), (val), (memorder))
 
#define ast_atomic_fetch_sub(ptr, val, memorder)   __atomic_fetch_sub((ptr), (val), (memorder))
 
#define ast_atomic_sub_fetch(ptr, val, memorder)   __atomic_sub_fetch((ptr), (val), (memorder))
 
#define ast_atomic_fetch_and(ptr, val, memorder)   __atomic_fetch_and((ptr), (val), (memorder))
 
#define ast_atomic_and_fetch(ptr, val, memorder)   __atomic_and_fetch((ptr), (val), (memorder))
 
#define ast_atomic_fetch_or(ptr, val, memorder)   __atomic_fetch_or((ptr), (val), (memorder))
 
#define ast_atomic_or_fetch(ptr, val, memorder)   __atomic_or_fetch((ptr), (val), (memorder))
 
#define ast_atomic_fetch_xor(ptr, val, memorder)   __atomic_fetch_xor((ptr), (val), (memorder))
 
#define ast_atomic_xor_fetch(ptr, val, memorder)   __atomic_xor_fetch((ptr), (val), (memorder))
 
#define ast_atomic_flag_set(ptr, val, memorder)   ast_atomic_fetch_or((ptr), (val), (memorder))
 
#define ast_atomic_flag_clear(ptr, val, memorder)   ast_atomic_fetch_and((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...
 
int ast_atomic_dec_and_test (volatile int *p)
 decrement *p by 1 and return true if the variable has reached 0. More...
 

Detailed Description

Asterisk locking-related definitions:

Magic number.

This is used to verify that a pointer is a valid astobj2 or ao2_weak reference.

Note
This field is constant after object creation. It shares a uint32_t with options and lockused.
Warning
Stealing bits for any additional writable fields would cause reentrancy issues if using bitfields. If any additional writable bits are required in the future we will need to put all bitfields into a single 'uint32_t flags' field and use atomic operations from to perform writes.

Definition in file lock.h.

Macro Definition Documentation

◆ __AST_MUTEX_DEFINE

#define __AST_MUTEX_DEFINE (   scope,
  mutex,
  init_val,
  track 
)    scope ast_mutex_t mutex = init_val

Definition at line 515 of file lock.h.

◆ __AST_RWLOCK_DEFINE

#define __AST_RWLOCK_DEFINE (   scope,
  rwlock,
  init_val,
  track 
)    scope ast_rwlock_t rwlock = init_val

Definition at line 538 of file lock.h.

◆ __AST_RWLOCK_INIT_VALUE

#define __AST_RWLOCK_INIT_VALUE   PTHREAD_RWLOCK_INITIALIZER

Definition at line 84 of file lock.h.

Referenced by __ast_rwlock_destroy(), __ast_rwlock_init(), and __ast_rwlock_unlock().

◆ AO2_DEADLOCK_AVOIDANCE

#define AO2_DEADLOCK_AVOIDANCE (   obj)

Unlock a lock briefly.

used during deadlock avoidance, to preserve the original location where a lock was originally acquired.

Definition at line 330 of file lock.h.

◆ ast_atomic_add_fetch

#define ast_atomic_add_fetch (   ptr,
  val,
  memorder 
)    __atomic_add_fetch((ptr), (val), (memorder))

Definition at line 668 of file lock.h.

◆ ast_atomic_and_fetch

#define ast_atomic_and_fetch (   ptr,
  val,
  memorder 
)    __atomic_and_fetch((ptr), (val), (memorder))

Definition at line 676 of file lock.h.

◆ ast_atomic_fetch_add

#define ast_atomic_fetch_add (   ptr,
  val,
  memorder 
)    __atomic_fetch_add((ptr), (val), (memorder))

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.

Note
ast_atomic_fetch_nand and ast_atomic_nand_fetch purposely do not exist. It's implementation was broken prior to gcc-4.4.

Atomic +=

Definition at line 667 of file lock.h.

Referenced by __ao2_ref().

◆ ast_atomic_fetch_and

#define ast_atomic_fetch_and (   ptr,
  val,
  memorder 
)    __atomic_fetch_and((ptr), (val), (memorder))

Atomic &=

Definition at line 675 of file lock.h.

◆ ast_atomic_fetch_or

#define ast_atomic_fetch_or (   ptr,
  val,
  memorder 
)    __atomic_fetch_or((ptr), (val), (memorder))

Atomic |=

Definition at line 679 of file lock.h.

◆ ast_atomic_fetch_sub

#define ast_atomic_fetch_sub (   ptr,
  val,
  memorder 
)    __atomic_fetch_sub((ptr), (val), (memorder))

Atomic -=

Definition at line 671 of file lock.h.

◆ ast_atomic_fetch_xor

#define ast_atomic_fetch_xor (   ptr,
  val,
  memorder 
)    __atomic_fetch_xor((ptr), (val), (memorder))

Atomic xor =

Definition at line 683 of file lock.h.

◆ ast_atomic_flag_clear

#define ast_atomic_flag_clear (   ptr,
  val,
  memorder 
)    ast_atomic_fetch_and((ptr), ~(val), (memorder))

Atomic flag clear

Definition at line 744 of file lock.h.

◆ ast_atomic_flag_set

#define ast_atomic_flag_set (   ptr,
  val,
  memorder 
)    ast_atomic_fetch_or((ptr), (val), (memorder))

Atomic flag set

Definition at line 741 of file lock.h.

◆ ast_atomic_or_fetch

#define ast_atomic_or_fetch (   ptr,
  val,
  memorder 
)    __atomic_or_fetch((ptr), (val), (memorder))

Definition at line 680 of file lock.h.

◆ ast_atomic_sub_fetch

#define ast_atomic_sub_fetch (   ptr,
  val,
  memorder 
)    __atomic_sub_fetch((ptr), (val), (memorder))

Definition at line 672 of file lock.h.

Referenced by ast_atomic_fetchadd_int().

◆ ast_atomic_xor_fetch

#define ast_atomic_xor_fetch (   ptr,
  val,
  memorder 
)    __atomic_xor_fetch((ptr), (val), (memorder))

Definition at line 684 of file lock.h.

◆ ast_cond_broadcast

#define ast_cond_broadcast (   cond)    __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)

◆ ast_cond_destroy

#define ast_cond_destroy (   cond)    __ast_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)

◆ ast_cond_init

#define ast_cond_init (   cond,
  attr 
)    __ast_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr)

◆ ast_cond_signal

#define ast_cond_signal (   cond)    __ast_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)

Definition at line 201 of file lock.h.

Referenced by add_notify(), amihook_helper(), analog_ss_thread(), ast_audiohook_update_status(), ast_audiohook_write_frame(), ast_autoservice_start(), ast_devstate_changed_literal(), ast_log_full(), ast_odbc_release_obj(), ast_rtp_on_turn_rtcp_state(), ast_rtp_on_turn_rtp_state(), ast_sched_add_variable(), ast_sched_del(), ast_sched_runq(), ast_sip_session_unsuspend(), async_callback(), async_play_sound_ready(), autoservice_shutdown(), bridge_channel_impart_ds_head_signal(), bridge_channel_internal_unsuspend_nolock(), bridge_manager_destroy(), bridge_manager_service_req(), calendar_destructor(), chan_test_devicestate_cb(), close_logger(), command_complete(), complex_task(), conf_free(), conf_run(), consumer_exec(), db_sync(), defer_full_frame(), device_state_cb(), device_state_engine_cleanup(), dial_trunk(), dispatch_exec_sync(), dns_synchronous_resolve_callback(), exec_command_on_condition(), get_lock(), hangup_playback(), load_task(), lock_free(), message_sink_cb(), minimal_callback(), mixmonitor_ds_destroy(), mock_cdr_backend_cb(), my_decrease_ss_count(), off_nominal_async_callback(), onCallCleared(), onNewCallCreated(), pbx_outgoing_exec(), playback_task(), poke_worker(), pthread_timer_open(), query_set_callback(), recurring_cancel(), resolution_thread(), run_station(), sched_thread_destroy(), schedule_cache_expiration(), schedule_calendar_event(), serializer_shutdown_group_dec(), shutdown_poke(), shutdown_task_exec(), signal_condition(), simple_task(), sip_session_suspend_task(), sla_destroy(), sla_queue_event_full(), softmix_bridge_destroy(), softmix_poke_thread(), sorcery_observer_created(), sorcery_observer_deleted(), sorcery_observer_loaded(), sorcery_observer_updated(), start_batch_mode(), stimulate_attended_transfer(), stop_mixmonitor_full(), stop_poll_thread(), subscription_invoke(), sync_task(), task(), task_1(), test_cancel(), test_emptied(), test_msg_handle_msg_cb(), test_state_changed(), test_sub(), test_task_pushed(), tps_ping_handler(), unload_module(), unlock_read(), user_event_hook_cb(), and worker_set_state().

◆ ast_cond_timedwait

#define ast_cond_timedwait (   cond,
  mutex,
  time 
)    __ast_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time)

◆ ast_cond_wait

#define ast_cond_wait (   cond,
  mutex 
)    __ast_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex)

◆ AST_LOCK_TRACK_INIT_VALUE

#define AST_LOCK_TRACK_INIT_VALUE   { { NULL }, { 0 }, 0, { NULL }, { 0 }, {{{ 0 }}}, PTHREAD_MUTEX_INIT_VALUE }

Definition at line 90 of file lock.h.

◆ AST_MAX_REENTRANCY

#define AST_MAX_REENTRANCY   10

◆ AST_MUTEX_DEFINE_STATIC

#define AST_MUTEX_DEFINE_STATIC (   mutex)    __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE, 1)

Definition at line 518 of file lock.h.

Referenced by ast_crypt_validate().

◆ AST_MUTEX_DEFINE_STATIC_NOTRACKING

#define AST_MUTEX_DEFINE_STATIC_NOTRACKING (   mutex)    __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE_NOTRACKING, 0)

Definition at line 519 of file lock.h.

◆ ast_mutex_destroy

#define ast_mutex_destroy (   a)    __ast_pthread_mutex_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)

Definition at line 186 of file lock.h.

Referenced by __ao2_ref(), __ast_internal_context_destroy(), __unload_module(), ast_audiohook_destroy(), ast_autochan_destroy(), ast_bridge_impart(), ast_dial_destroy(), ast_dnsmgr_release(), ast_sched_context_destroy(), ast_sip_push_task_wait(), ast_speech_destroy(), ast_speech_new(), AST_TEST_DEFINE(), async_data_destructor(), async_datastore_data_destroy(), async_minimal_data_destructor(), auth_http_callback(), build_conf(), build_gateway(), cel_verify_and_cleanup_cb(), chan_list_destructor(), close_client(), command_dtor(), complex_task_data_free(), conf_free(), data_cleanup(), delete_device(), delete_peers(), delete_users(), destroy_dahdi_pvt(), destroy_endpoint(), destroy_session(), destroy_table(), dispatch_message(), dns_synchronous_resolve_destroy(), do_monitor(), find_idle_thread(), find_realtime(), free_config(), generic_http_callback(), get_lock(), hangup_data_destroy(), iax2_process_thread_cleanup(), init_logger(), load_module(), mgcp_prune_realtime_gateway(), misdn_cfg_destroy(), misdn_jb_destroy(), mixmonitor_free(), odbc_class_destructor(), off_nominal_async_data_destructor(), ooh323_destroy(), ooh323c_call_thread(), ooh323c_start_call_thread(), playback_task_data_destroy(), prometheus_metric_free(), query_set_data_destructor(), recurring_data_destructor(), resolver_data_cleanup(), session_destructor(), session_do(), setup_mixmonitor_ds(), shutdown_data_dtor(), simple_task_data_free(), sla_destroy(), sla_handle_dial_state_event(), sla_station_exec(), smdi_interface_destroy(), softmix_bridge_data_destroy(), softmix_bridge_leave(), start_network_thread(), stasis_message_sink_dtor(), task_data_dtor(), test_shutdown(), timing_read(), unistim_free_sub(), unload_module(), vm_allocate_dh(), and worker_thread_destroy().

◆ ast_mutex_init

#define ast_mutex_init (   pmutex)    __ast_pthread_mutex_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex)

Definition at line 184 of file lock.h.

Referenced by accept_thread(), add_notify(), alloc_profile(), alloc_smdi_interface(), ast_audiohook_init(), ast_autochan_setup(), ast_bridge_impart(), ast_context_find_or_create(), ast_dial_create(), ast_dns_resolve(), ast_dnsmgr_get_family(), ast_query_set_resolve(), ast_sched_context_create(), ast_sip_push_task_wait(), ast_speech_new(), ast_ssl_init(), AST_TEST_DEFINE(), async_data_alloc(), async_datastore_data_alloc(), async_minimal_data_alloc(), auth_http_callback(), available(), build_conf(), build_device(), build_gateway(), build_mansession(), build_peer(), build_user(), caldav_load_calendar(), command_create(), complex_task_data_alloc(), conf_run(), config_device(), config_line(), config_parse_variables(), create_client(), dispatch_message(), duplicate_pseudo(), ewscal_load_calendar(), exchangecal_load_calendar(), find_idle_thread(), find_table(), find_tpeer(), generic_http_callback(), get_lock(), hangup_data_init(), ical_load_calendar(), init_logger(), init_timing_thread(), internal_ao2_alloc(), load_config(), load_module(), load_odbc_config(), mbl_load_device(), misdn_cfg_init(), misdn_jb_init(), mkintf(), off_nominal_async_data_alloc(), ooh323_alloc(), ooh323c_start_call_thread(), parse_config(), playback_task_data_init(), prometheus_metric_create(), query_set_data_alloc(), rcv_mac_addr(), read_config(), recurring_data_alloc(), resolver_data_init(), scheduler(), session_do(), setup_mixmonitor_ds(), shutdown_data_create(), simple_task_data_alloc(), sla_handle_dial_state_event(), sla_load_config(), sla_station_exec(), softmix_bridge_create(), softmix_bridge_join(), start_network_thread(), stasis_message_sink_create(), task_data_create(), test_alloc(), test_cel_init_cb(), unistim_alloc_sub(), vm_allocate_dh(), and worker_thread_alloc().

◆ ast_mutex_init_notracking

#define ast_mutex_init_notracking (   pmutex)    __ast_pthread_mutex_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex)

Definition at line 185 of file lock.h.

◆ AST_MUTEX_INIT_VALUE

#define AST_MUTEX_INIT_VALUE   { PTHREAD_MUTEX_INIT_VALUE, NULL, {1, 0} }

Definition at line 95 of file lock.h.

◆ AST_MUTEX_INIT_VALUE_NOTRACKING

#define AST_MUTEX_INIT_VALUE_NOTRACKING   { PTHREAD_MUTEX_INIT_VALUE, NULL, {0, 0} }

Definition at line 96 of file lock.h.

◆ AST_MUTEX_INITIALIZER

#define AST_MUTEX_INITIALIZER   __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__

Definition at line 635 of file lock.h.

◆ AST_MUTEX_KIND

#define AST_MUTEX_KIND   PTHREAD_MUTEX_RECURSIVE_NP

Definition at line 77 of file lock.h.

Referenced by __ast_pthread_mutex_init(), ast_get_reentrancy(), and dummy_start().

◆ ast_mutex_lock

#define ast_mutex_lock (   a)    __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)

Definition at line 187 of file lock.h.

Referenced by __attempt_transmit(), __auth_reject(), __auto_congest(), __auto_hangup(), __dahdi_exception(), __find_callno(), __get_from_jb(), __iax2_poke_noanswer(), __manager_event_sessions_va(), __reload(), __unload_module(), _ast_odbc_request_obj2(), acf_channel_read(), acf_jabberreceive_read(), acl_change_stasis_cb(), action_dahdishowchannels(), action_waitevent(), add_notify(), adsi_delete(), adsi_message(), alsa_answer(), alsa_call(), alsa_digit(), alsa_fixup(), alsa_hangup(), alsa_indicate(), alsa_read(), alsa_request(), alsa_text(), alsa_write(), amihook_helper(), analog_ss_thread(), announce_thread(), answer_exec_run(), app_exec(), append_mailbox_mapping(), ast_ari_remove_handler(), ast_autochan_new_channel(), ast_begin_shutdown(), ast_cancel_shutdown(), ast_cli_netstats(), ast_context_lockmacro(), ast_db_del(), ast_db_deltree(), ast_db_gettree(), ast_db_gettree_by_prefix(), ast_db_put(), ast_dial_join(), ast_dns_get_nameservers(), ast_dns_resolve(), ast_dnsmgr_changed(), ast_file_read_dirs(), ast_get_enum(), ast_iax2_new(), ast_merge_contexts_and_delete(), ast_monitor_start(), ast_odbc_direct_execute(), ast_odbc_prepare_and_execute(), ast_odbc_release_obj(), ast_pjproject_log_intercept_begin(), ast_query_set_resolve(), ast_random(), ast_rdlock_contexts(), ast_replace_sigchld(), ast_sched_add_variable(), ast_sched_clean_by_callback(), ast_sched_context_destroy(), ast_sched_del(), ast_sched_dump(), ast_sched_find_data(), ast_sched_report(), ast_sched_runq(), ast_sched_wait(), ast_sched_when(), ast_search_dns(), ast_sip_push_task_wait(), ast_smdi_md_message_push(), ast_smdi_mwi_message_push(), AST_TEST_DEFINE(), ast_unreplace_sigchld(), ast_verb_update(), ast_wrlock_contexts(), astdb_atexit(), async_callback(), async_play_sound_ready(), attempt_transfer(), auth_reject(), authenticate_reply(), auto_hangup(), blr_ebl(), blr_txt(), bridge_agent_hold_deferred_create(), bridge_channel_impart_ds_head_signal(), bridge_channel_impart_wait(), build_device(), build_reply_digest(), caldav_load_calendar(), can_safely_quit(), cb_events(), cdr_detach(), cdr_handler(), cdr_submit_batch(), chan_test_devicestate_cb(), channel_to_session(), check_unloading(), cl_dequeue_chan(), cl_queue_chan(), clear_history_entries(), clear_result_states(), clear_talking(), cli_tps_ping(), close_client(), close_mailbox(), close_rtp_connection(), close_udptl_connection(), command_complete(), command_join(), conf_free(), conf_run(), config_device(), config_handler(), config_line(), config_load(), config_module(), config_pgsql(), console_answer(), console_autoanswer(), console_dial(), console_hangup(), console_sendtext(), create_channel_name(), create_client(), csv_log(), custom_log(), dahdi_answer(), dahdi_call(), dahdi_cc_callback(), dahdi_create_channel_range(), dahdi_destroy_channel_range(), dahdi_digit_begin(), dahdi_digit_end(), dahdi_exception(), dahdi_fixup(), dahdi_func_read(), dahdi_func_write(), dahdi_handle_dtmf(), dahdi_handle_event(), dahdi_hangup(), dahdi_iflist_extract(), dahdi_indicate(), dahdi_master_slave_unlink(), dahdi_request(), dahdi_restart(), dahdi_sendtext(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dahdi_softhangup_all(), dahdi_write(), db_create_astdb(), db_get_common(), db_open(), db_sync_thread(), decrease_call_count(), defer_full_frame(), DEFINE_SQL_STATEMENT(), delete_peers(), delete_users(), destroy_all_channels(), destroy_all_mailbox_mappings(), destroy_conference_bridge(), destroy_endpoint(), destroy_monitor_audiohook(), destroy_pgsql(), destroy_session(), destroy_table(), device_state_cb(), dial_trunk(), dispatch_exec_sync(), dispatch_message(), dns_advance_field(), dns_synchronous_resolve_callback(), dnsmgr_refresh(), do_cdr(), do_discovery(), do_monitor(), do_monitor_headset(), do_monitor_phone(), do_refresh(), do_reload(), do_timing(), dp_lookup(), dump_cmd_queues(), dump_queue(), ewscal_load_calendar(), exchangecal_load_calendar(), filter_history(), find_call(), find_chan_by_bc(), find_channel(), find_command(), find_database(), find_friend(), find_hold_active_call(), find_hold_call(), find_hold_call_l3(), find_idle_thread(), find_peer(), find_subchannel_and_lock(), find_subchannel_by_name(), find_table(), find_tpeer(), find_user(), finish_bookmark(), function_ooh323_read(), function_ooh323_write(), generate_uuid(), generic_http_callback(), get_chan_by_ast_name(), get_dial_bridge(), get_input(), get_lock(), get_unused_callno(), handle_capabilities_res_message(), handle_clear_alarms(), handle_cli_database_query(), handle_cli_database_show(), handle_cli_database_showkey(), handle_cli_dialplan_save(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_stats(), handle_cli_locks_show(), handle_cli_misdn_show_channel(), handle_cli_misdn_show_channels(), handle_cli_mobile_cusd(), handle_cli_mobile_rfcomm(), handle_cli_mobile_show_devices(), handle_cli_odbc_show(), handle_cli_ooh323_reload(), handle_cli_ooh323_show_peer(), handle_cli_ooh323_show_peers(), handle_cli_ooh323_show_user(), handle_cli_ooh323_show_users(), handle_cli_osp_show(), handle_cli_realtime_pgsql_status(), handle_deferred_full_frames(), handle_init_event(), handle_mgcp_audit_endpoint(), handle_mgcp_show_endpoints(), handle_modlist(), handle_request(), handle_request_do(), handle_speechrecognize(), handler_wait_for_message(), hangup_playback(), headset_send_ring(), history_on_rx_msg(), history_on_tx_msg(), http_callback(), iax2_call(), iax2_do_register(), iax2_fixup(), iax2_hangup(), iax2_indicate(), iax2_key_rotate(), iax2_lock_callno_unless_destroyed(), iax2_poke_peer(), iax2_process_thread(), iax2_queryoption(), iax2_setoption(), iax2_write(), iax_process_template(), iax_prov_complete_template(), iax_provision_build(), iax_provision_free_templates(), iax_provision_version(), iax_show_provisioning(), iax_template_parse(), ical_load_calendar(), increase_call_count(), inotify_daemon(), key_main_page(), key_select_extension(), leave_voicemail(), load_config(), load_module(), load_values_config(), lock_free(), lock_it(), lock_msg_q(), log_jitterstats(), lua_free_extensions(), lua_load_extensions(), lua_reload_extensions(), make_trunk(), mansession_lock(), mb_poll_thread(), mbl_answer(), mbl_call(), mbl_devicestate(), mbl_digit_end(), mbl_fixup(), mbl_hangup(), mbl_request(), mbl_sendsms_exec(), mbl_status_exec(), meetme_menu_admin_extended(), mgcp_answer(), mgcp_call(), mgcp_devicestate(), mgcp_fixup(), mgcp_hangup(), mgcp_indicate(), mgcp_pktcgate_open(), mgcp_pktcgate_remove(), mgcp_postrequest(), mgcp_prune_realtime_gateway(), mgcp_read(), mgcp_reload(), mgcp_senddigit_begin(), mgcp_senddigit_end(), mgcp_write(), mgcpsock_read(), mid_test_sync(), minimal_callback(), misdn_cfg_lock(), misdn_chan_is_valid(), misdn_hangup(), misdn_jb_empty(), misdn_jb_fill(), misdn_overlap_dial_task(), mixmonitor_ds_destroy(), mixmonitor_thread(), mwi_monitor_handler(), my_decrease_ss_count(), my_handle_dtmf(), my_increase_ss_count(), my_lock_private(), MYSQL_exec(), mysql_log(), native_bridge_is_capable(), native_start(), native_stop(), nominal_async_run(), off_nominal_async_callback(), off_nominal_async_run(), onAlerting(), onCallCleared(), onCallEstablished(), onModeChanged(), onNewCallCreated(), onOutgoingCall(), onProgress(), ooh323_alloc(), ooh323_answer(), ooh323_call(), ooh323_delete_peer(), ooh323_destroy(), ooh323_digit_begin(), ooh323_digit_end(), ooh323_do_reload(), ooh323_fixup(), ooh323_hangup(), ooh323_indicate(), ooh323_new(), ooh323_onReceivedDigit(), ooh323_onReceivedSetup(), ooh323_queryoption(), ooh323_read(), ooh323_request(), ooh323_set_read_format(), ooh323_set_rtp_peer(), ooh323_set_write_format(), ooh323_write(), ooh323c_call_thread(), ooh323c_start_call_thread(), osp_create_provider(), osp_create_transaction(), osp_get_provider(), osp_unload(), parse_config(), parsing(), pbx_load_module(), peer_destructor(), pgsql_log(), phone_request(), pjsip_show_history(), play_message(), play_message_by_id_helper(), play_sound_helper(), playback_task(), presence_state_cb(), private_enum_init(), prometheus_scrape_to_string(), prune_gateways(), pthread_timer_open(), publish_msg(), pvt_destructor(), query_set_callback(), query_set_test(), queue_ringing_trunk(), rcv_mac_addr(), realtime_destroy_handler(), realtime_handler(), realtime_ldap_base_ap(), realtime_multi_handler(), realtime_multi_pgsql(), realtime_pgsql(), realtime_store_handler(), realtime_update2_handler(), realtime_update_handler(), recordthread(), recurring_cancel(), register_verify(), registry_authrequest(), registry_message_cb(), release_chan(), release_chan_early(), reload(), reload_config(), reload_followme(), reload_module(), replace_callno(), reqprep(), require_pgsql(), resolution_thread(), restart_monitor(), restart_pktc_thread(), retrans_pkt(), run_station(), save_to_folder(), sched_run(), sched_thread_destroy(), schedule_cache_expiration(), schedule_calendar_event(), scheduled_destroy(), sco_accept(), scrape_metrics(), send_client(), send_command_locked(), send_request(), send_retransmit(), set_hangup_source_and_cause(), set_pvt_defaults(), set_softmix_bridge_data(), set_unloading(), setup_dahdi_int(), setup_rtp_connection(), setup_rtp_remote(), setup_udptl_connection(), signal_condition(), sip_reload(), sip_show_settings(), skinny_session(), sla_destroy(), sla_handle_dial_state_event(), sla_handle_ringing_trunk_event(), sla_hangup_stations(), sla_queue_event_full(), sla_station_exec(), sla_thread(), sla_trunk_exec(), socket_process_helper(), softmix_bridge_destroy(), softmix_bridge_stop(), softmix_bridge_write_rtcp(), softmix_bridge_write_video(), softmix_bridge_write_voice(), softmix_mixing_loop(), softmix_mixing_thread(), softmix_poke_thread(), spandsp_fax_cli_show_stats(), speech_background(), ssl_lock(), start_batch_mode(), start_network_thread(), start_rtp(), stasis_app_control_shutdown(), statistics_show_messages(), stop_mixmonitor_full(), stop_poll_thread(), store_pgsql(), stun_monitor_request(), stun_stop_monitor(), sync_task(), syslog_log(), task_1(), tds_load_module(), tds_log(), tds_unload_module(), test_cancel(), test_msg_handle_msg_cb(), timing_read(), tps_ping_handler(), transmit_frame(), transmit_response_bysession(), unistim_fixup(), unistim_hangup_clean(), unistim_read(), unistim_register(), unistim_show_devices(), unistim_show_info(), unistim_write(), unistimsock_read(), unload_module(), unlock_read(), update2_ldap(), update2_pgsql(), update_pgsql(), update_registry(), user_event_hook_cb(), user_event_wait_for_events(), vm_allocate_dh(), vm_execmain(), vm_instructions_en(), vm_instructions_ja(), wait_for_channel_callback(), wait_for_device_state_updates(), wait_for_hook(), wait_for_initiator(), wait_for_resolution(), wait_until_thread_state_task_pushed(), worker_start(), write_cel(), and xmpp_pak_message().

◆ ast_mutex_trylock

#define ast_mutex_trylock (   a)    __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)

◆ ast_mutex_unlock

#define ast_mutex_unlock (   a)    __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)

Definition at line 188 of file lock.h.

Referenced by __attempt_transmit(), __auth_reject(), __auto_congest(), __auto_hangup(), __dahdi_exception(), __find_callno(), __get_from_jb(), __iax2_poke_noanswer(), __manager_event_sessions_va(), __reload(), __send_lagrq(), __send_ping(), __unload_module(), _ast_odbc_request_obj2(), acf_channel_read(), acf_jabberreceive_read(), acl_change_stasis_cb(), action_dahdishowchannels(), action_waitevent(), add_notify(), adsi_delete(), adsi_message(), alsa_answer(), alsa_call(), alsa_digit(), alsa_fixup(), alsa_hangup(), alsa_indicate(), alsa_read(), alsa_request(), alsa_text(), alsa_write(), amihook_helper(), analog_ss_thread(), announce_thread(), answer_exec_run(), app_exec(), append_mailbox_mapping(), ast_ari_remove_handler(), ast_autochan_new_channel(), ast_begin_shutdown(), ast_cancel_shutdown(), ast_change_hint(), ast_cli_netstats(), ast_cli_perms_init(), ast_context_unlockmacro(), ast_db_del(), ast_db_deltree(), ast_db_gettree(), ast_db_gettree_by_prefix(), ast_db_put(), ast_dial_join(), ast_dns_get_nameservers(), ast_dns_resolve(), ast_dnsmgr_changed(), ast_file_read_dirs(), ast_get_enum(), ast_iax2_new(), ast_merge_contexts_and_delete(), ast_module_reload(), ast_monitor_start(), ast_odbc_direct_execute(), ast_odbc_prepare_and_execute(), ast_odbc_release_obj(), ast_pjproject_log_intercept_end(), ast_query_set_resolve(), ast_random(), ast_replace_sigchld(), ast_sched_add_variable(), ast_sched_clean_by_callback(), ast_sched_context_destroy(), ast_sched_del(), ast_sched_dump(), ast_sched_find_data(), ast_sched_report(), ast_sched_runq(), ast_sched_wait(), ast_sched_when(), ast_search_dns(), ast_sip_push_task_wait(), ast_smdi_md_message_push(), ast_smdi_mwi_message_push(), AST_TEST_DEFINE(), ast_unlock_contexts(), ast_unreplace_sigchld(), ast_verb_update(), astdb_atexit(), async_callback(), async_play_sound_ready(), attempt_transfer(), auth_reject(), authenticate_reply(), auto_hangup(), blr_ebl(), blr_txt(), bridge_agent_hold_deferred_create(), bridge_channel_impart_ds_head_signal(), bridge_channel_impart_wait(), build_device(), build_reply_digest(), cache_get_callno_locked(), caldav_load_calendar(), can_safely_quit(), cb_events(), cdr_detach(), cdr_handler(), cdr_submit_batch(), chan_test_devicestate_cb(), channel_to_session(), check_unloading(), cl_dequeue_chan(), cl_queue_chan(), clear_history_entries(), clear_result_states(), clear_talking(), cli_tps_ping(), close_client(), close_mailbox(), close_rtp_connection(), close_udptl_connection(), command_complete(), command_join(), conf_free(), conf_run(), config_device(), config_handler(), config_line(), config_load(), config_module(), config_pgsql(), configure_local_rtp(), console_answer(), console_autoanswer(), console_dial(), console_hangup(), console_sendtext(), create_channel_name(), create_client(), csv_log(), custom_log(), dahdi_answer(), dahdi_call(), dahdi_cc_callback(), dahdi_create_channel_range(), dahdi_destroy_channel_range(), dahdi_digit_begin(), dahdi_digit_end(), dahdi_exception(), dahdi_fixup(), dahdi_func_read(), dahdi_func_write(), dahdi_handle_dtmf(), dahdi_handle_event(), dahdi_hangup(), dahdi_iflist_extract(), dahdi_indicate(), dahdi_master_slave_unlink(), dahdi_read(), dahdi_request(), dahdi_restart(), dahdi_sendtext(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dahdi_softhangup_all(), dahdi_write(), db_create_astdb(), db_get_common(), db_open(), db_sync_thread(), decrease_call_count(), defer_full_frame(), DEFINE_SQL_STATEMENT(), delete_peers(), delete_users(), destroy_all_channels(), destroy_all_mailbox_mappings(), destroy_conference_bridge(), destroy_endpoint(), destroy_monitor_audiohook(), destroy_pgsql(), destroy_session(), destroy_table(), device_state_cb(), dial_trunk(), dispatch_exec_sync(), dispatch_message(), dns_advance_field(), dns_synchronous_resolve_callback(), dnsmgr_refresh(), do_cdr(), do_discovery(), do_monitor(), do_monitor_headset(), do_monitor_phone(), do_refresh(), do_reload(), do_timing(), dp_lookup(), dump_cmd_queues(), dump_queue(), ewscal_load_calendar(), exchangecal_load_calendar(), filter_history(), find_cache(), find_call(), find_chan_by_bc(), find_channel(), find_command(), find_friend(), find_hold_active_call(), find_hold_call(), find_hold_call_l3(), find_idle_thread(), find_peer(), find_subchannel_and_lock(), find_subchannel_by_name(), find_table(), find_user(), finish_bookmark(), function_ooh323_read(), function_ooh323_write(), generate_uuid(), generic_http_callback(), get_chan_by_ast_name(), get_dial_bridge(), get_input(), get_lock(), get_unused_callno(), handle_capabilities_res_message(), handle_clear_alarms(), handle_cli_database_query(), handle_cli_database_show(), handle_cli_database_showkey(), handle_cli_dialplan_save(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_stats(), handle_cli_locks_show(), handle_cli_misdn_show_channel(), handle_cli_misdn_show_channels(), handle_cli_mobile_cusd(), handle_cli_mobile_rfcomm(), handle_cli_mobile_show_devices(), handle_cli_odbc_show(), handle_cli_ooh323_reload(), handle_cli_ooh323_show_peer(), handle_cli_ooh323_show_peers(), handle_cli_ooh323_show_user(), handle_cli_ooh323_show_users(), handle_cli_osp_show(), handle_cli_realtime_pgsql_status(), handle_deferred_full_frames(), handle_init_event(), handle_mgcp_audit_endpoint(), handle_mgcp_show_endpoints(), handle_modlist(), handle_request(), handle_request_do(), handle_speechrecognize(), handler_wait_for_message(), hangup_playback(), headset_send_ring(), history_on_rx_msg(), history_on_tx_msg(), http_callback(), iax2_call(), iax2_do_register(), iax2_fixup(), iax2_hangup(), iax2_indicate(), iax2_key_rotate(), iax2_lock_callno_unless_destroyed(), iax2_poke_peer(), iax2_process_thread(), iax2_provision(), iax2_queryoption(), iax2_request(), iax2_setoption(), iax2_trunk_queue(), iax2_write(), iax_process_template(), iax_prov_complete_template(), iax_provision_build(), iax_provision_free_templates(), iax_provision_version(), iax_show_provisioning(), iax_template_parse(), ical_load_calendar(), increase_call_count(), inotify_daemon(), key_main_page(), key_select_extension(), ldap_loadentry(), leave_voicemail(), load_config(), load_module(), load_values_config(), lock_free(), log_jitterstats(), lua_free_extensions(), lua_load_extensions(), lua_reload_extensions(), make_trunk(), mansession_unlock(), mb_poll_thread(), mbl_answer(), mbl_call(), mbl_devicestate(), mbl_digit_end(), mbl_fixup(), mbl_hangup(), mbl_read(), mbl_request(), mbl_sendsms_exec(), mbl_status_exec(), mbl_write(), meetme_menu_admin_extended(), mgcp_answer(), mgcp_call(), mgcp_devicestate(), mgcp_fixup(), mgcp_hangup(), mgcp_indicate(), mgcp_pktcgate_open(), mgcp_pktcgate_remove(), mgcp_postrequest(), mgcp_prune_realtime_gateway(), mgcp_read(), mgcp_reload(), mgcp_request(), mgcp_senddigit_begin(), mgcp_senddigit_end(), mgcp_write(), mgcpsock_read(), mid_test_sync(), minimal_callback(), misdn_cfg_unlock(), misdn_chan_is_valid(), misdn_hangup(), misdn_jb_empty(), misdn_jb_fill(), misdn_overlap_dial_task(), mixmonitor_ds_destroy(), mixmonitor_thread(), mwi_monitor_handler(), my_decrease_ss_count(), my_handle_dtmf(), my_increase_ss_count(), my_unlock_private(), MYSQL_exec(), mysql_log(), native_bridge_is_capable(), native_start(), native_stop(), nominal_async_run(), off_nominal_async_callback(), off_nominal_async_run(), onAlerting(), onCallCleared(), onCallEstablished(), onModeChanged(), onNewCallCreated(), onOutgoingCall(), onProgress(), ooh323_alloc(), ooh323_answer(), ooh323_call(), ooh323_delete_peer(), ooh323_destroy(), ooh323_digit_begin(), ooh323_digit_end(), ooh323_do_reload(), ooh323_fixup(), ooh323_hangup(), ooh323_indicate(), ooh323_new(), ooh323_onReceivedDigit(), ooh323_onReceivedSetup(), ooh323_queryoption(), ooh323_read(), ooh323_request(), ooh323_set_read_format(), ooh323_set_rtp_peer(), ooh323_set_write_format(), ooh323_write(), ooh323c_call_thread(), ooh323c_start_call_thread(), osp_create_provider(), osp_create_transaction(), osp_get_provider(), osp_unload(), parse_config(), parsing(), pbx_load_module(), peer_destructor(), pgsql_log(), phone_request(), pjsip_show_history(), play_message(), play_message_by_id_helper(), play_sound_helper(), playback_task(), presence_state_cb(), private_enum_init(), prometheus_scrape_to_string(), prune_gateways(), pthread_timer_open(), publish_msg(), pvt_destructor(), query_set_callback(), query_set_test(), queue_ringing_trunk(), rcv_mac_addr(), realtime_destroy_handler(), realtime_handler(), realtime_ldap_base_ap(), realtime_multi_handler(), realtime_multi_pgsql(), realtime_pgsql(), realtime_store_handler(), realtime_update2_handler(), realtime_update_handler(), recordthread(), recurring_cancel(), refresh_list(), register_verify(), registry_authrequest(), registry_message_cb(), release_chan(), release_chan_early(), release_table(), reload(), reload_config(), reload_followme(), reload_module(), replace_callno(), reqprep(), require_pgsql(), resolution_thread(), restart_monitor(), restart_pktc_thread(), retrans_pkt(), run_station(), save_to_folder(), sched_run(), sched_thread_destroy(), schedule_cache_expiration(), schedule_calendar_event(), scheduled_destroy(), sco_accept(), scrape_metrics(), send_client(), send_command_locked(), send_request(), send_retransmit(), set_hangup_source_and_cause(), set_pvt_defaults(), set_softmix_bridge_data(), set_unloading(), setup_dahdi_int(), setup_rtp_connection(), setup_rtp_remote(), setup_udptl_connection(), signal_condition(), sip_reload(), sip_show_settings(), skinny_session(), skinny_session_cleanup(), sla_destroy(), sla_handle_dial_state_event(), sla_handle_ringing_trunk_event(), sla_hangup_stations(), sla_queue_event_full(), sla_station_exec(), sla_thread(), sla_trunk_exec(), socket_process_helper(), socket_process_meta(), softmix_bridge_destroy(), softmix_bridge_stop(), softmix_bridge_write_rtcp(), softmix_bridge_write_video(), softmix_bridge_write_voice(), softmix_mixing_loop(), softmix_mixing_thread(), softmix_poke_thread(), spandsp_fax_cli_show_stats(), speech_background(), ssl_lock(), start_batch_mode(), start_network_thread(), start_rtp(), stasis_app_control_shutdown(), statistics_show_messages(), stop_mixmonitor_full(), stop_poll_thread(), store_pgsql(), stun_monitor_request(), stun_stop_monitor(), sync_task(), syslog_log(), task_1(), tds_load_module(), tds_log(), tds_unload_module(), test_cancel(), test_msg_handle_msg_cb(), timing_read(), tps_ping_handler(), transmit_frame(), transmit_response_bysession(), unistim_fixup(), unistim_hangup_clean(), unistim_read(), unistim_register(), unistim_show_devices(), unistim_show_info(), unistim_write(), unistimsock_read(), unload_module(), unlock_it(), unlock_msg_q(), unlock_read(), update2_ldap(), update2_pgsql(), update_pgsql(), update_registry(), user_event_hook_cb(), user_event_wait_for_events(), vm_allocate_dh(), vm_execmain(), vm_instructions_en(), vm_instructions_ja(), wait_for_channel_callback(), wait_for_device_state_updates(), wait_for_hook(), wait_for_initiator(), wait_for_resolution(), wait_until_thread_state_task_pushed(), worker_start(), write_cel(), and xmpp_pak_message().

◆ AST_PTHREADT_NULL

#define AST_PTHREADT_NULL   (pthread_t) -1
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Definition at line 66 of file lock.h.

Referenced by __allocate_taskprocessor(), __ast_rwlock_unlock(), __manager_event_sessions_va(), __sip_reliable_xmit(), __unload_module(), accept_thread(), action_dahdishowchannels(), action_waitevent(), actual_load_config(), add_notify(), ast_autoservice_start(), ast_autoservice_stop(), ast_console_puts_mutable_full(), ast_devstate_changed_literal(), ast_dial_create(), ast_dial_join(), ast_localtime_wakeup_monitor(), ast_log_full(), ast_pjproject_log_intercept_end(), ast_safe_fork(), ast_sched_start_thread(), ast_sip_destroy_transport_management(), ast_taskprocessor_execute(), ast_tcptls_server_start(), ast_tcptls_server_stop(), ast_xmpp_client_disconnect(), autoservice_run(), autoservice_shutdown(), bridge_manager_create(), bridge_manager_destroy(), build_calendar(), build_conf(), build_mansession(), calendar_event_notify(), cdr_enable_batch_mode(), cdr_submit_batch(), cleanup_module(), close_logger(), conf_free(), conf_run(), dahdi_cc_callback(), dahdi_destroy_channel_range(), dahdi_restart(), default_listener_pvt_alloc(), default_listener_shutdown(), destroy_session(), device_state_engine_cleanup(), do_reload(), expiration_global_loaded(), finalize_batch_mode(), generic_http_callback(), get_input(), handle_call_outgoing(), init_pvt(), inotify_daemon(), keepalive_global_loaded(), mbl_load_device(), meetme_menu_admin_extended(), moh_class_destructor(), monitor_sig_flags(), ooh323c_stop_call_thread(), ooh323c_stop_stack_thread(), really_quit(), restart_monitor(), restart_pktc_thread(), sched_thread_destroy(), setup_dahdi_int(), sla_destroy(), sla_load_config(), sla_queue_event_full(), smdi_interface_destroy(), smdi_load(), softmix_bridge_create(), softmix_bridge_destroy(), sorcery_memory_cache_thrash_create(), sorcery_memory_cache_thrash_stop(), start_monitor(), stop_poll_thread(), stop_stream(), unbound_resolver_alloc(), unbound_resolver_start(), unbound_resolver_stop(), unistim_alloc_sub(), unload_module(), worker_shutdown(), worker_thread_alloc(), and xmpp_client_alloc().

◆ AST_PTHREADT_STOP

#define AST_PTHREADT_STOP   (pthread_t) -2

◆ AST_RWLOCK_DEFINE_STATIC

#define AST_RWLOCK_DEFINE_STATIC (   rwlock)    __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE, 1)

Definition at line 541 of file lock.h.

◆ AST_RWLOCK_DEFINE_STATIC_NOTRACKING

#define AST_RWLOCK_DEFINE_STATIC_NOTRACKING (   rwlock)    __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE_NOTRACKING, 0)

Definition at line 542 of file lock.h.

◆ ast_rwlock_destroy

#define ast_rwlock_destroy (   rwlock)    __ast_rwlock_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)

◆ ast_rwlock_init

#define ast_rwlock_init (   rwlock)    __ast_rwlock_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)

◆ ast_rwlock_init_notracking

#define ast_rwlock_init_notracking (   rwlock)    __ast_rwlock_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)

wrapper for ast_rwlock_init with tracking disabled

Returns
0 on success, non zero for error
Since
1.6.1

Definition at line 229 of file lock.h.

◆ AST_RWLOCK_INIT_VALUE

#define AST_RWLOCK_INIT_VALUE   { __AST_RWLOCK_INIT_VALUE, NULL, {1, 0} }

Definition at line 98 of file lock.h.

◆ AST_RWLOCK_INIT_VALUE_NOTRACKING

#define AST_RWLOCK_INIT_VALUE_NOTRACKING   { __AST_RWLOCK_INIT_VALUE, NULL, {0, 0} }

Definition at line 99 of file lock.h.

◆ ast_rwlock_rdlock

#define ast_rwlock_rdlock (   a)    __ast_rwlock_rdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)

Definition at line 233 of file lock.h.

Referenced by _ast_hashtab_start_traversal(), action_messagesend(), allowed_on_shutdown(), ast_adsi_available(), ast_adsi_begin_download(), ast_adsi_channel_restore(), ast_adsi_clear_screen(), ast_adsi_clear_soft_keys(), ast_adsi_connect_session(), ast_adsi_data_mode(), ast_adsi_disconnect_session(), ast_adsi_display(), ast_adsi_download_connect(), ast_adsi_download_disconnect(), ast_adsi_end_download(), ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_input_control(), ast_adsi_input_format(), ast_adsi_load_session(), ast_adsi_load_soft_key(), ast_adsi_print(), ast_adsi_query_cpeid(), ast_adsi_query_cpeinfo(), ast_adsi_read_encoded_dtmf(), ast_adsi_set_keys(), ast_adsi_set_line(), ast_adsi_transmit_message(), ast_adsi_transmit_message_full(), ast_adsi_unload_session(), ast_adsi_voice_mode(), ast_calendar_config_acquire(), ast_hashtab_get_stats(), ast_hashtab_lookup(), ast_hashtab_lookup_with_hash(), ast_hashtab_rdlock(), ast_msg_has_destination(), ast_msg_send(), ast_rdlock_context(), ast_rtp_codecs_find_payload_code(), ast_rtp_codecs_get_framing(), ast_rtp_codecs_get_payload(), ast_rtp_codecs_get_payload_format(), ast_rtp_codecs_get_stream_type(), ast_rtp_codecs_payload_code(), ast_rtp_codecs_payload_code_tx(), ast_rtp_codecs_payload_formats(), ast_rtp_codecs_payloads_set_m_type(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), ast_str_retrieve_variable(), ast_taskprocessor_alert_get(), beanstalk_put(), cel_bs_put(), codec_to_index(), corosync_show_config(), cpg_confchg_cb(), cpg_deliver_cb(), find_table(), get_active_pvt(), get_general_options(), get_odbc_obj(), get_subscription(), handle_msg_cb(), handle_show_globals(), has_destination_cb(), index2codec(), manager_log(), msg_q_cb(), msg_send_exec(), pbx_builtin_getvar_helper(), rtp_address_is_ice_blacklisted(), and stun_address_is_blacklisted().

◆ ast_rwlock_timedrdlock

#define ast_rwlock_timedrdlock (   a,
  b 
)    __ast_rwlock_timedrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a, b)

Definition at line 237 of file lock.h.

◆ ast_rwlock_timedwrlock

#define ast_rwlock_timedwrlock (   a,
  b 
)    __ast_rwlock_timedwrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a, b)

Definition at line 238 of file lock.h.

◆ ast_rwlock_tryrdlock

#define ast_rwlock_tryrdlock (   a)    __ast_rwlock_tryrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)

◆ ast_rwlock_trywrlock

#define ast_rwlock_trywrlock (   a)    __ast_rwlock_trywrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)

Definition at line 236 of file lock.h.

Referenced by cleanup_module(), dispatch_thread_handler(), and load_module().

◆ ast_rwlock_unlock

#define ast_rwlock_unlock (   a)    __ast_rwlock_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)

Definition at line 232 of file lock.h.

Referenced by _ast_hashtab_insert_immediate(), _ast_hashtab_insert_safe(), action_messagesend(), add_codec2index(), add_static_payload(), allowed_on_shutdown(), ast_adsi_available(), ast_adsi_begin_download(), ast_adsi_channel_restore(), ast_adsi_clear_screen(), ast_adsi_clear_soft_keys(), ast_adsi_connect_session(), ast_adsi_data_mode(), ast_adsi_disconnect_session(), ast_adsi_display(), ast_adsi_download_connect(), ast_adsi_download_disconnect(), ast_adsi_end_download(), ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_input_control(), ast_adsi_input_format(), ast_adsi_install_funcs(), ast_adsi_load_session(), ast_adsi_load_soft_key(), ast_adsi_print(), ast_adsi_query_cpeid(), ast_adsi_query_cpeinfo(), ast_adsi_read_encoded_dtmf(), ast_adsi_set_keys(), ast_adsi_set_line(), ast_adsi_transmit_message(), ast_adsi_transmit_message_full(), ast_adsi_unload_session(), ast_adsi_voice_mode(), ast_calendar_config_acquire(), ast_calendar_config_release(), ast_cli_allow_at_shutdown(), ast_hashtab_destroy(), ast_hashtab_end_traversal(), ast_hashtab_get_stats(), ast_hashtab_lookup(), ast_hashtab_lookup_with_hash(), ast_hashtab_remove_object_via_lookup(), ast_hashtab_remove_this_object(), ast_hashtab_unlock(), ast_msg_handler_register(), ast_msg_handler_unregister(), ast_msg_has_destination(), ast_msg_send(), ast_msg_tech_register(), ast_msg_tech_unregister(), ast_rtp_codecs_find_payload_code(), ast_rtp_codecs_get_framing(), ast_rtp_codecs_get_payload(), ast_rtp_codecs_get_payload_format(), ast_rtp_codecs_get_stream_type(), ast_rtp_codecs_payload_code(), ast_rtp_codecs_payload_code_tx(), ast_rtp_codecs_payload_formats(), ast_rtp_codecs_payload_replace_format(), ast_rtp_codecs_payloads_copy(), ast_rtp_codecs_payloads_set_m_type(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_codecs_payloads_unset(), ast_rtp_codecs_payloads_xover(), ast_rtp_codecs_set_framing(), ast_rtp_engine_unload_format(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), ast_str_retrieve_variable(), ast_taskprocessor_alert_get(), ast_unlock_context(), beanstalk_put(), cel_bs_put(), cleanup_module(), codec_to_index(), corosync_show_config(), corosync_show_members(), cpg_confchg_cb(), cpg_deliver_cb(), destroy_pvts(), destroy_table(), dispatch_thread_handler(), get_active_pvt(), get_general_options(), get_odbc_obj(), get_or_create_subscription(), get_subscription(), handle_msg_cb(), handle_show_globals(), has_destination_cb(), index2codec(), load_config(), load_general_config(), load_module(), load_tech_calendars(), manager_log(), matrix_resize(), messaging_app_unsubscribe_endpoint(), msg_q_cb(), msg_send_exec(), pbx_builtin_clear_globals(), pbx_builtin_getvar_helper(), pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), publish_event_to_corosync(), reload(), remove_shutdown_command(), rtp_address_is_ice_blacklisted(), rtp_codecs_assign_payload_code_rx(), rtp_engine_shutdown(), rtp_reload(), rtp_unload_acl(), send_cluster_notify(), set_active(), set_general_options(), set_next_mime_type(), sip_outbound_publish_client_get_publisher(), stun_address_is_blacklisted(), tps_alert_add(), and translate_shutdown().

◆ ast_rwlock_wrlock

#define ast_rwlock_wrlock (   a)    __ast_rwlock_wrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)

◆ CHANNEL_DEADLOCK_AVOIDANCE

#define CHANNEL_DEADLOCK_AVOIDANCE (   chan)

Definition at line 352 of file lock.h.

Referenced by ast_hangup(), dahdi_handle_event(), dahdi_read(), mbl_read(), and mbl_write().

◆ DEADLOCK_AVOIDANCE

#define DEADLOCK_AVOIDANCE (   lock)

◆ DLA_LOCK

#define DLA_LOCK (   lock)

Deadlock avoidance lock.

In certain deadlock avoidance scenarios, there is more than one lock to be unlocked and relocked. Therefore, this pair of macros is provided for that purpose. Note that every DLA_UNLOCK MUST be paired with a matching DLA_LOCK. The intent of this pair of macros is to be used around another set of deadlock avoidance code, mainly CHANNEL_DEADLOCK_AVOIDANCE, as the locking order specifies that we may safely lock a channel, followed by its pvt, with no worries about a deadlock. In any other scenario, this macro may not be safe to use.

Definition at line 427 of file lock.h.

Referenced by dahdi_handle_event().

◆ DLA_UNLOCK

#define DLA_UNLOCK (   lock)
Value:
do { \
char __filename[80], __func[80], __mutex_name[80]; \
int __lineno; \
int __res = ast_find_lock_info(lock, __filename, sizeof(__filename), &__lineno, __func, sizeof(__func), __mutex_name, sizeof(__mutex_name)); \
int __res2 = ast_mutex_unlock(lock);
int ast_find_lock_info(void *lock_addr, char *filename, size_t filename_size, int *lineno, char *func, size_t func_size, char *mutex_name, size_t mutex_name_size)
retrieve lock info for the specified mutex
Definition: main/utils.c:995
ast_mutex_t lock
Definition: app_meetme.c:1091
#define ast_mutex_unlock(a)
Definition: lock.h:188

Deadlock avoidance unlock.

In certain deadlock avoidance scenarios, there is more than one lock to be unlocked and relocked. Therefore, this pair of macros is provided for that purpose. Note that every DLA_UNLOCK MUST be paired with a matching DLA_LOCK. The intent of this pair of macros is to be used around another set of deadlock avoidance code, mainly CHANNEL_DEADLOCK_AVOIDANCE, as the locking order specifies that we may safely lock a channel, followed by its pvt, with no worries about a deadlock. In any other scenario, this macro may not be safe to use.

Definition at line 408 of file lock.h.

Referenced by dahdi_handle_event().

◆ DO_THREAD_CRASH

#define DO_THREAD_CRASH   do { } while (0)

◆ gethostbyname

#define gethostbyname   __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__

Definition at line 637 of file lock.h.

Referenced by connect_asterisk(), connect_sphinx(), connect_to_host(), main(), and manager_login().

◆ pthread_cond_broadcast

#define pthread_cond_broadcast   use_ast_cond_broadcast_instead_of_pthread_cond_broadcast

Definition at line 631 of file lock.h.

Referenced by __ast_cond_broadcast().

◆ pthread_cond_destroy

#define pthread_cond_destroy   use_ast_cond_destroy_instead_of_pthread_cond_destroy

Definition at line 629 of file lock.h.

Referenced by __ast_cond_destroy().

◆ pthread_cond_init

#define pthread_cond_init   use_ast_cond_init_instead_of_pthread_cond_init

Definition at line 628 of file lock.h.

Referenced by __ast_cond_init().

◆ pthread_cond_signal

#define pthread_cond_signal   use_ast_cond_signal_instead_of_pthread_cond_signal

Definition at line 630 of file lock.h.

Referenced by __ast_cond_signal().

◆ pthread_cond_t

#define pthread_cond_t   use_ast_cond_t_instead_of_pthread_cond_t

Definition at line 621 of file lock.h.

◆ pthread_cond_timedwait

#define pthread_cond_timedwait   use_ast_cond_timedwait_instead_of_pthread_cond_timedwait

Definition at line 633 of file lock.h.

Referenced by __ast_cond_timedwait().

◆ pthread_cond_wait

#define pthread_cond_wait   use_ast_cond_wait_instead_of_pthread_cond_wait

Definition at line 632 of file lock.h.

Referenced by __ast_cond_wait().

◆ pthread_create

#define pthread_create   __use_ast_pthread_create_instead__

Definition at line 640 of file lock.h.

Referenced by ast_pthread_create_stack(), main(), misdn_lib_init(), and misdn_tasks_init().

◆ pthread_mutex_destroy

#define pthread_mutex_destroy   use_ast_mutex_destroy_instead_of_pthread_mutex_destroy

◆ pthread_mutex_init

#define pthread_mutex_init   use_ast_mutex_init_instead_of_pthread_mutex_init

◆ PTHREAD_MUTEX_INIT_VALUE

#define PTHREAD_MUTEX_INIT_VALUE   PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP

Definition at line 76 of file lock.h.

◆ pthread_mutex_lock

#define pthread_mutex_lock   use_ast_mutex_lock_instead_of_pthread_mutex_lock

◆ pthread_mutex_t

#define pthread_mutex_t   use_ast_mutex_t_instead_of_pthread_mutex_t

◆ pthread_mutex_trylock

#define pthread_mutex_trylock   use_ast_mutex_trylock_instead_of_pthread_mutex_trylock

◆ pthread_mutex_unlock

#define pthread_mutex_unlock   use_ast_mutex_unlock_instead_of_pthread_mutex_unlock

◆ ROFFSET

#define ROFFSET   ((lt->reentrancy > 0) ? (lt->reentrancy-1) : 0)

◆ SCOPED_AO2LOCK

#define SCOPED_AO2LOCK (   varname,
  obj 
)    SCOPED_LOCK(varname, (obj), ao2_lock, ao2_unlock)

scoped lock specialization for ao2 mutexes.

Definition at line 602 of file lock.h.

Referenced by apply_menu_to_user(), ast_cdr_fork(), ast_endpoint_snapshot_create(), ast_media_cache_create_or_update(), ast_media_cache_retrieve(), ast_sip_publish_client_send(), ast_sip_session_register_sdp_handler(), ast_taskprocessor_set_local(), ast_threadpool_push(), ast_threadpool_set_size(), ast_unreal_channel_push_to_bridge(), cancel_and_unpublish(), clear_stimulus_queue(), cli_show_channels(), complete_confbridge_participant(), consumer_exec(), consumer_exec_sync(), consumer_should_stay(), consumer_wait_for(), consumer_wait_for_completion(), event_session_shutdown(), find_route(), generic_mute_unmute_helper(), get_wait_bridge_wrapper(), handle_bridge_enter(), handle_local_optimization_begin(), handle_local_optimization_end(), kick_conference_participant(), one_protocol(), persistent_endpoint_find_or_create(), playback_cancel(), playback_final_update(), playback_first_update(), playback_forward(), playback_pause(), playback_restart(), playback_reverse(), playback_stop(), playback_unpause(), publisher_client_send(), recording_set_state(), remove_stasis_subscriptions(), sip_outbound_publish_callback(), sip_publisher_service_queue(), stasis_app_control_record(), stasis_app_playback_get_state(), stasis_app_playback_operation(), stasis_app_recording_operation(), stasis_topic_pool_get_topic(), threadpool_active_thread_idle(), threadpool_idle_thread_dead(), threadpool_tps_emptied(), threadpool_tps_task_pushed(), and threadpool_zombie_thread_dead().

◆ SCOPED_AO2RDLOCK

#define SCOPED_AO2RDLOCK (   varname,
  obj 
)    SCOPED_LOCK(varname, (obj), ao2_rdlock, ao2_unlock)

scoped lock specialization for ao2 read locks.

Definition at line 607 of file lock.h.

Referenced by bucket_file_wizard_retrieve(), and bucket_wizard_retrieve().

◆ SCOPED_AO2WRLOCK

#define SCOPED_AO2WRLOCK (   varname,
  obj 
)    SCOPED_LOCK(varname, (obj), ao2_wrlock, ao2_unlock)

scoped lock specialization for ao2 write locks.

Definition at line 612 of file lock.h.

Referenced by __ast_bucket_scheme_register(), __ast_codec_register_with_format(), __ast_format_interface_register(), and ast_format_cache_set().

◆ SCOPED_CHANNELLOCK

#define SCOPED_CHANNELLOCK (   varname,
  chan 
)    SCOPED_LOCK(varname, (chan), ast_channel_lock, ast_channel_unlock)

◆ SCOPED_LOCK

#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.

int some_function(struct ast_channel *chan)
{
if (!strcmp(ast_channel_name(chan, "foo")) {
return 0;
}
return -1;
}

In the above example, neither return path requires explicit unlocking of the channel.

Note
Care should be taken when using SCOPED_LOCKS in conjunction with ao2 objects. ao2 objects should be unlocked before they are unreffed. Since SCOPED_LOCK runs once the variable goes out of scope, this can easily lead to situations where the variable gets unlocked after it is unreffed.
Parameters
varnameThe unique name to give to the scoped lock. You are not likely to reference this outside of the SCOPED_LOCK invocation.
lockThe variable to lock. This can be anything that can be passed to a locking or unlocking function.
lockfuncThe function to call to lock the lock
unlockfuncThe function to call to unlock the lock

Definition at line 581 of file lock.h.

Referenced by add_headers_to_message(), ast_bridge_basic_set_flags(), ast_bridge_transfer_attended(), ast_bridge_transfer_blind(), ast_sip_format_endpoint_ami(), ast_sip_identify_endpoint(), ast_sip_register_endpoint_formatter(), ast_sip_register_endpoint_identifier_with_name(), ast_sip_register_event_publisher_handler(), ast_sip_register_supplement(), ast_sip_session_add_supplements(), ast_sip_session_register_supplement_with_module(), ast_sip_session_unregister_supplement(), ast_sip_unregister_endpoint_formatter(), ast_sip_unregister_endpoint_identifier(), ast_sip_unregister_event_publisher_handler(), ast_sip_unregister_supplement(), AST_TEST_DEFINE(), bridge_basic_change_personality(), channel_get_external_vars(), cli_show_endpoint_identifiers(), get_sip_pvt_from_replaces(), handle_request_invite(), and remove_hooks_on_personality_change().

◆ SCOPED_MUTEX

#define SCOPED_MUTEX (   varname,
  lock 
)    SCOPED_LOCK(varname, (lock), ast_mutex_lock, ast_mutex_unlock)

◆ SCOPED_RDLOCK

#define SCOPED_RDLOCK (   varname,
  lock 
)    SCOPED_LOCK(varname, (lock), ast_rwlock_rdlock, ast_rwlock_unlock)

scoped lock specialization for read locks

Definition at line 592 of file lock.h.

Referenced by ast_get_extension_for_mime_type(), ast_get_format_for_file_ext(), ast_start_mixmonitor(), and ast_stop_mixmonitor().

◆ SCOPED_WRLOCK

#define SCOPED_WRLOCK (   varname,
  lock 
)    SCOPED_LOCK(varname, (lock), ast_rwlock_wrlock, ast_rwlock_unlock)

scoped lock specialization for write locks

Definition at line 597 of file lock.h.

Referenced by ast_clear_mixmonitor_methods(), ast_set_mixmonitor_methods(), ast_sip_publish_client_remove(), and get_publishes_and_update_state().

Typedef Documentation

◆ ast_cond_t

Definition at line 176 of file lock.h.

◆ ast_mutex_t

typedef struct ast_mutex_info ast_mutex_t

Definition at line 172 of file lock.h.

◆ ast_rwlock_t

typedef struct ast_rwlock_info ast_rwlock_t

Definition at line 174 of file lock.h.

Enumeration Type Documentation

◆ ast_lock_type

Enumerator
AST_MUTEX 
AST_RDLOCK 
AST_WRLOCK 

Definition at line 252 of file lock.h.

252  {
253  AST_MUTEX,
254  AST_RDLOCK,
255  AST_WRLOCK,
256 };

Function Documentation

◆ __ast_cond_broadcast()

int __ast_cond_broadcast ( const char *  filename,
int  lineno,
const char *  func,
const char *  cond_name,
ast_cond_t cond 
)

Definition at line 504 of file lock.c.

References pthread_cond_broadcast.

506 {
508 }
#define pthread_cond_broadcast
Definition: lock.h:631
ast_cond_t cond
Definition: app_meetme.c:1090

◆ __ast_cond_destroy()

int __ast_cond_destroy ( const char *  filename,
int  lineno,
const char *  func,
const char *  cond_name,
ast_cond_t cond 
)

Definition at line 510 of file lock.c.

References pthread_cond_destroy.

512 {
513  return pthread_cond_destroy(cond);
514 }
ast_cond_t cond
Definition: app_meetme.c:1090
#define pthread_cond_destroy
Definition: lock.h:629

◆ __ast_cond_init()

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 
)

Definition at line 492 of file lock.c.

References pthread_cond_init.

494 {
495  return pthread_cond_init(cond, cond_attr);
496 }
#define pthread_cond_init
Definition: lock.h:628
ast_cond_t cond
Definition: app_meetme.c:1090

◆ __ast_cond_signal()

int __ast_cond_signal ( const char *  filename,
int  lineno,
const char *  func,
const char *  cond_name,
ast_cond_t cond 
)

Definition at line 498 of file lock.c.

References pthread_cond_signal.

500 {
501  return pthread_cond_signal(cond);
502 }
ast_cond_t cond
Definition: app_meetme.c:1090
#define pthread_cond_signal
Definition: lock.h:630

◆ __ast_cond_timedwait()

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 604 of file lock.c.

References __dump_backtrace(), ast_get_reentrancy(), ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_restore_lock_info(), ast_suspend_lock_info(), ast_lock_track::backtrace, DO_THREAD_CRASH, ast_lock_track::file, ast_mutex_info::flags, ast_lock_track::func, ast_lock_track::lineno, log_mutex_error, ast_mutex_info::mutex, NULL, pthread_cond_timedwait, pthread_mutex_t, ast_lock_track::reentrancy, restore_lock_tracking(), ROFFSET, ast_lock_track::thread_id, ast_mutex_info::track, and ast_lock_track_flags::tracking.

607 {
608  int res;
609 
610 #ifdef DEBUG_THREADS
611  struct ast_lock_track *lt = NULL;
612  struct ast_lock_track lt_orig;
613  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
614 
615 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
616  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
617  log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
618  filename, lineno, func, mutex_name);
620  return EINVAL;
621  }
622 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
623 
624  lt = ast_get_reentrancy(&t->track, &t->flags, 0);
625  if (lt) {
627  if (lt->reentrancy && (lt->thread_id[ROFFSET] != pthread_self())) {
628  log_mutex_error(canlog, "%s line %d (%s): attempted wait using mutex '%s' without owning it!\n",
629  filename, lineno, func, mutex_name);
630  log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",
631  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
632 #ifdef HAVE_BKTR
633  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
634 #endif
636  } else if (lt->reentrancy <= 0) {
637  log_mutex_error(canlog, "%s line %d (%s): attempted wait using an unlocked mutex '%s'\n",
638  filename, lineno, func, mutex_name);
640  }
641 
642  /* Waiting on a condition completely suspends a recursive mutex,
643  * even if it's been recursively locked multiple times. Make a
644  * copy of the lock tracking, and reset reentrancy to zero */
645  lt_orig = *lt;
646  lt->reentrancy = 0;
648 
650  }
651 #endif /* DEBUG_THREADS */
652 
653  res = pthread_cond_timedwait(cond, &t->mutex, abstime);
654 
655 #ifdef DEBUG_THREADS
656  if (res && (res != ETIMEDOUT)) {
657  log_mutex_error(canlog, "%s line %d (%s): Error waiting on condition mutex '%s'\n",
658  filename, lineno, func, strerror(res));
660  } else if (lt) {
661  restore_lock_tracking(lt, &lt_orig);
663  }
664 #endif /* DEBUG_THREADS */
665 
666  return res;
667 }
struct ast_lock_track_flags flags
Definition: lock.h:147
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
#define pthread_mutex_t
Definition: lock.h:620
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
struct ast_lock_track * track
Definition: lock.h:146
Lock tracking information.
Definition: lock.h:111
unsigned int tracking
Definition: lock.h:125
ast_cond_t cond
Definition: app_meetme.c:1090
#define DO_THREAD_CRASH
Definition: lock.h:247
#define ROFFSET
Definition: lock.h:240
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
void ast_suspend_lock_info(void *lock_addr)
Definition: main/utils.c:1030
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
static void restore_lock_tracking(struct ast_lock_track *lt, struct ast_lock_track *lt_saved)
Definition: lock.c:517
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
static void __dump_backtrace(struct ast_bt *bt, int canlog)
Definition: lock.c:68
pthread_mutex_t mutex
Definition: lock.h:136
#define pthread_cond_timedwait
Definition: lock.h:633
void ast_restore_lock_info(void *lock_addr)
Definition: main/utils.c:1059

◆ __ast_cond_wait()

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 539 of file lock.c.

References __dump_backtrace(), ast_get_reentrancy(), ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_restore_lock_info(), ast_suspend_lock_info(), ast_lock_track::backtrace, DO_THREAD_CRASH, ast_lock_track::file, ast_mutex_info::flags, ast_lock_track::func, ast_lock_track::lineno, log_mutex_error, ast_mutex_info::mutex, NULL, pthread_cond_wait, pthread_mutex_t, ast_lock_track::reentrancy, restore_lock_tracking(), ROFFSET, ast_lock_track::thread_id, ast_mutex_info::track, and ast_lock_track_flags::tracking.

542 {
543  int res;
544 
545 #ifdef DEBUG_THREADS
546  struct ast_lock_track *lt = NULL;
547  struct ast_lock_track lt_orig;
548  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
549 
550 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
551  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
552  log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
553  filename, lineno, func, mutex_name);
555  return EINVAL;
556  }
557 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
558 
559  lt = ast_get_reentrancy(&t->track, &t->flags, 0);
560  if (lt) {
562  if (lt->reentrancy && (lt->thread_id[ROFFSET] != pthread_self())) {
563  log_mutex_error(canlog, "%s line %d (%s): attempted wait using mutex '%s' without owning it!\n",
564  filename, lineno, func, mutex_name);
565  log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",
566  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
567 #ifdef HAVE_BKTR
568  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
569 #endif
571  } else if (lt->reentrancy <= 0) {
572  log_mutex_error(canlog, "%s line %d (%s): attempted wait using an unlocked mutex '%s'\n",
573  filename, lineno, func, mutex_name);
575  }
576 
577  /* Waiting on a condition completely suspends a recursive mutex,
578  * even if it's been recursively locked multiple times. Make a
579  * copy of the lock tracking, and reset reentrancy to zero */
580  lt_orig = *lt;
581  lt->reentrancy = 0;
583 
585  }
586 #endif /* DEBUG_THREADS */
587 
588  res = pthread_cond_wait(cond, &t->mutex);
589 
590 #ifdef DEBUG_THREADS
591  if (res) {
592  log_mutex_error(canlog, "%s line %d (%s): Error waiting on condition mutex '%s'\n",
593  filename, lineno, func, strerror(res));
595  } else if (lt) {
596  restore_lock_tracking(lt, &lt_orig);
598  }
599 #endif /* DEBUG_THREADS */
600 
601  return res;
602 }
struct ast_lock_track_flags flags
Definition: lock.h:147
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
#define pthread_mutex_t
Definition: lock.h:620
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
struct ast_lock_track * track
Definition: lock.h:146
Lock tracking information.
Definition: lock.h:111
#define pthread_cond_wait
Definition: lock.h:632
unsigned int tracking
Definition: lock.h:125
ast_cond_t cond
Definition: app_meetme.c:1090
#define DO_THREAD_CRASH
Definition: lock.h:247
#define ROFFSET
Definition: lock.h:240
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
void ast_suspend_lock_info(void *lock_addr)
Definition: main/utils.c:1030
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
static void restore_lock_tracking(struct ast_lock_track *lt, struct ast_lock_track *lt_saved)
Definition: lock.c:517
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
static void __dump_backtrace(struct ast_bt *bt, int canlog)
Definition: lock.c:68
pthread_mutex_t mutex
Definition: lock.h:136
void ast_restore_lock_info(void *lock_addr)
Definition: main/utils.c:1059

◆ __ast_pthread_mutex_destroy()

int __ast_pthread_mutex_destroy ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 175 of file lock.c.

References __dump_backtrace(), ast_get_reentrancy(), ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_lock_track::backtrace, delete_reentrancy_cs(), DO_THREAD_CRASH, ast_lock_track::file, ast_mutex_info::flags, ast_lock_track::func, ast_lock_track::lineno, log_mutex_error, ast_mutex_info::mutex, pthread_mutex_destroy, pthread_mutex_t, pthread_mutex_trylock, pthread_mutex_unlock, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread_id, ast_mutex_info::track, and ast_lock_track_flags::tracking.

177 {
178  int res;
179 
180 #ifdef DEBUG_THREADS
181  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 1);
182  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
183 
184 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
185  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
186  /* Don't try to uninitialize an uninitialized mutex
187  * This may have no effect on linux
188  * but it always generates a core on *BSD when
189  * linked with libpthread.
190  * This is not an error condition if the mutex is created on the fly.
191  */
192  log_mutex_error(canlog, "%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n",
193  filename, lineno, func, mutex_name);
195  res = EINVAL;
196  goto lt_cleanup;
197  }
198 #endif
199 
200  res = pthread_mutex_trylock(&t->mutex);
201  switch (res) {
202  case 0:
204  break;
205  case EINVAL:
206  log_mutex_error(canlog, "%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",
207  filename, lineno, func, mutex_name);
208  break;
209  case EBUSY:
210  log_mutex_error(canlog, "%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",
211  filename, lineno, func, mutex_name);
212  if (lt) {
214  log_mutex_error(canlog, "%s line %d (%s): Error: '%s' was locked here.\n",
215  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
216 #ifdef HAVE_BKTR
217  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
218 #endif
220  }
221  break;
222  }
223 #endif /* DEBUG_THREADS */
224 
225  res = pthread_mutex_destroy(&t->mutex);
226 
227 #ifdef DEBUG_THREADS
228  if (res) {
229  log_mutex_error(canlog, "%s line %d (%s): Error destroying mutex %s: %s\n",
230  filename, lineno, func, mutex_name, strerror(res));
231  }
232 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
233 lt_cleanup:
234 #endif
235  if (lt) {
237  lt->file[0] = filename;
238  lt->lineno[0] = lineno;
239  lt->func[0] = func;
240  lt->reentrancy = 0;
241  lt->thread_id[0] = 0;
242 #ifdef HAVE_BKTR
243  memset(&lt->backtrace[0], 0, sizeof(lt->backtrace[0]));
244 #endif
247  }
248 #endif /* DEBUG_THREADS */
249 
250  return res;
251 }
struct ast_lock_track_flags flags
Definition: lock.h:147
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
int reentrancy
Definition: lock.h:114
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
#define pthread_mutex_t
Definition: lock.h:620
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
struct ast_lock_track * track
Definition: lock.h:146
#define pthread_mutex_destroy
Definition: lock.h:627
Lock tracking information.
Definition: lock.h:111
unsigned int tracking
Definition: lock.h:125
static void delete_reentrancy_cs(struct ast_lock_track **plt)
Definition: lock.c:129
#define DO_THREAD_CRASH
Definition: lock.h:247
#define ROFFSET
Definition: lock.h:240
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
static void __dump_backtrace(struct ast_bt *bt, int canlog)
Definition: lock.c:68
pthread_mutex_t mutex
Definition: lock.h:136
#define pthread_mutex_unlock
Definition: lock.h:624
#define pthread_mutex_trylock
Definition: lock.h:625

◆ __ast_pthread_mutex_init()

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 144 of file lock.c.

References AST_MUTEX_KIND, DO_THREAD_CRASH, ast_mutex_info::flags, log_mutex_error, ast_mutex_info::mutex, NULL, pthread_mutex_init, pthread_mutex_t, ast_lock_track_flags::setup, ast_mutex_info::track, and ast_lock_track_flags::tracking.

146 {
147  int res;
148  pthread_mutexattr_t attr;
149 
150 #ifdef DEBUG_THREADS
151 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
152  if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
153  int canlog = tracking && strcmp(filename, "logger.c");
154 
155  log_mutex_error(canlog, "%s line %d (%s): NOTICE: mutex '%s' is already initialized.\n",
156  filename, lineno, func, mutex_name);
158  return EBUSY;
159  }
160 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
161 
162  t->track = NULL;
163  t->flags.tracking = tracking;
164  t->flags.setup = 0;
165 #endif /* DEBUG_THREADS */
166 
167  pthread_mutexattr_init(&attr);
168  pthread_mutexattr_settype(&attr, AST_MUTEX_KIND);
169  res = pthread_mutex_init(&t->mutex, &attr);
170  pthread_mutexattr_destroy(&attr);
171 
172  return res;
173 }
#define pthread_mutex_init
Definition: lock.h:626
struct ast_lock_track_flags flags
Definition: lock.h:147
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
#define pthread_mutex_t
Definition: lock.h:620
struct ast_lock_track * track
Definition: lock.h:146
volatile unsigned int setup
Definition: lock.h:127
unsigned int tracking
Definition: lock.h:125
#define DO_THREAD_CRASH
Definition: lock.h:247
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
pthread_mutex_t mutex
Definition: lock.h:136
#define AST_MUTEX_KIND
Definition: lock.h:77

◆ __ast_pthread_mutex_lock()

int __ast_pthread_mutex_lock ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 253 of file lock.c.

References __dump_backtrace(), ast_bt_get_addresses, ast_get_reentrancy(), ast_mark(), ast_mark_lock_acquired(), AST_MAX_REENTRANCY, AST_MUTEX, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_remove_lock_info(), ast_store_lock_info(), ast_lock_track::backtrace, DO_THREAD_CRASH, ast_lock_track::file, ast_mutex_info::flags, ast_lock_track::func, ast_lock_track::lineno, log_mutex_error, ast_mutex_info::mutex, NULL, pthread_mutex_lock, pthread_mutex_trylock, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread_id, tmp(), ast_mutex_info::track, and ast_lock_track_flags::tracking.

Referenced by __ao2_lock().

255 {
256  int res;
257 
258 #ifdef DEBUG_THREADS
259  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
260  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
261  struct ast_bt *bt = NULL;
262 
263  if (lt) {
264 #ifdef HAVE_BKTR
265  struct ast_bt tmp;
266 
267  /* The implementation of backtrace() may have its own locks.
268  * Capture the backtrace outside of the reentrancy lock to
269  * avoid deadlocks. See ASTERISK-22455. */
271 
273  if (lt->reentrancy < AST_MAX_REENTRANCY) {
274  lt->backtrace[lt->reentrancy] = tmp;
275  bt = &lt->backtrace[lt->reentrancy];
276  }
278 #endif
279  ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
280  }
281 #endif /* DEBUG_THREADS */
282 
283 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
284  {
285  time_t seconds = time(NULL);
286  time_t wait_time, reported_wait = 0;
287  do {
288 #ifdef HAVE_MTX_PROFILE
289  ast_mark(mtx_prof, 1);
290 #endif
291  res = pthread_mutex_trylock(&t->mutex);
292 #ifdef HAVE_MTX_PROFILE
293  ast_mark(mtx_prof, 0);
294 #endif
295  if (res == EBUSY) {
296  wait_time = time(NULL) - seconds;
297  if (wait_time > reported_wait && (wait_time % 5) == 0) {
298  log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
299  filename, lineno, func, (int) wait_time, mutex_name);
300  if (lt) {
302 #ifdef HAVE_BKTR
303  __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
304 #endif
305  log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",
306  lt->file[ROFFSET], lt->lineno[ROFFSET],
307  lt->func[ROFFSET], mutex_name);
308 #ifdef HAVE_BKTR
309  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
310 #endif
312  }
313  reported_wait = wait_time;
314  }
315  usleep(200);
316  }
317  } while (res == EBUSY);
318  }
319 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
320 #ifdef HAVE_MTX_PROFILE
321  ast_mark(mtx_prof, 1);
322  res = pthread_mutex_trylock(&t->mutex);
323  ast_mark(mtx_prof, 0);
324  if (res)
325 #endif
326  res = pthread_mutex_lock(&t->mutex);
327 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
328 
329 #ifdef DEBUG_THREADS
330  if (lt && !res) {
332  if (lt->reentrancy < AST_MAX_REENTRANCY) {
333  lt->file[lt->reentrancy] = filename;
334  lt->lineno[lt->reentrancy] = lineno;
335  lt->func[lt->reentrancy] = func;
336  lt->thread_id[lt->reentrancy] = pthread_self();
337  lt->reentrancy++;
338  } else {
339  log_mutex_error(canlog, "%s line %d (%s): '%s' really deep reentrancy!\n",
340  filename, lineno, func, mutex_name);
341  }
344  } else if (lt) {
345 #ifdef HAVE_BKTR
346  if (lt->reentrancy) {
348  bt = &lt->backtrace[lt->reentrancy-1];
350  } else {
351  bt = NULL;
352  }
353 #endif
354  ast_remove_lock_info(t, bt);
355  }
356  if (res) {
357  log_mutex_error(canlog, "%s line %d (%s): Error obtaining mutex: %s\n",
358  filename, lineno, func, strerror(res));
360  }
361 #endif /* DEBUG_THREADS */
362 
363  return res;
364 }
int64_t ast_mark(int, int start1_stop0)
Definition: astman.c:103
struct ast_lock_track_flags flags
Definition: lock.h:147
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
static int tmp()
Definition: bt_open.c:389
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
struct ast_lock_track * track
Definition: lock.h:146
Lock tracking information.
Definition: lock.h:111
#define pthread_mutex_lock
Definition: lock.h:623
void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
Store lock info for the current thread.
Definition: check_expr.c:61
unsigned int tracking
Definition: lock.h:125
#define DO_THREAD_CRASH
Definition: lock.h:247
#define ROFFSET
Definition: lock.h:240
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
remove lock info for the current thread
Definition: check_expr.c:68
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
void ast_mark_lock_acquired(void *lock_addr)
Mark the last lock as acquired.
Definition: check_expr.c:94
#define AST_MAX_REENTRANCY
Definition: lock.h:101
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
static void __dump_backtrace(struct ast_bt *bt, int canlog)
Definition: lock.c:68
pthread_mutex_t mutex
Definition: lock.h:136
#define pthread_mutex_trylock
Definition: lock.h:625
#define ast_bt_get_addresses(bt)
Definition: backtrace.h:38

◆ __ast_pthread_mutex_trylock()

int __ast_pthread_mutex_trylock ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 366 of file lock.c.

References ast_bt_get_addresses, ast_get_reentrancy(), ast_mark_lock_acquired(), ast_mark_lock_failed(), AST_MAX_REENTRANCY, AST_MUTEX, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_store_lock_info(), ast_lock_track::backtrace, ast_lock_track::file, ast_mutex_info::flags, ast_lock_track::func, ast_lock_track::lineno, log_mutex_error, ast_mutex_info::mutex, NULL, pthread_mutex_trylock, ast_lock_track::reentrancy, ast_lock_track::thread_id, tmp(), ast_mutex_info::track, and ast_lock_track_flags::tracking.

Referenced by __ao2_trylock().

368 {
369  int res;
370 
371 #ifdef DEBUG_THREADS
372  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
373  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
374  struct ast_bt *bt = NULL;
375 
376  if (lt) {
377 #ifdef HAVE_BKTR
378  struct ast_bt tmp;
379 
380  /* The implementation of backtrace() may have its own locks.
381  * Capture the backtrace outside of the reentrancy lock to
382  * avoid deadlocks. See ASTERISK-22455. */
384 
386  if (lt->reentrancy < AST_MAX_REENTRANCY) {
387  lt->backtrace[lt->reentrancy] = tmp;
388  bt = &lt->backtrace[lt->reentrancy];
389  }
391 #endif
392  ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
393  }
394 #endif /* DEBUG_THREADS */
395 
396  res = pthread_mutex_trylock(&t->mutex);
397 
398 #ifdef DEBUG_THREADS
399  if (lt && !res) {
401  if (lt->reentrancy < AST_MAX_REENTRANCY) {
402  lt->file[lt->reentrancy] = filename;
403  lt->lineno[lt->reentrancy] = lineno;
404  lt->func[lt->reentrancy] = func;
405  lt->thread_id[lt->reentrancy] = pthread_self();
406  lt->reentrancy++;
407  } else {
408  log_mutex_error(canlog, "%s line %d (%s): '%s' really deep reentrancy!\n",
409  filename, lineno, func, mutex_name);
410  }
413  } else if (lt) {
415  }
416 #endif /* DEBUG_THREADS */
417 
418  return res;
419 }
struct ast_lock_track_flags flags
Definition: lock.h:147
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
void ast_mark_lock_failed(void *lock_addr)
Mark the last lock as failed (trylock)
Definition: extconf.c:2314
static int tmp()
Definition: bt_open.c:389
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
struct ast_lock_track * track
Definition: lock.h:146
Lock tracking information.
Definition: lock.h:111
void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
Store lock info for the current thread.
Definition: check_expr.c:61
unsigned int tracking
Definition: lock.h:125
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
void ast_mark_lock_acquired(void *lock_addr)
Mark the last lock as acquired.
Definition: check_expr.c:94
#define AST_MAX_REENTRANCY
Definition: lock.h:101
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
pthread_mutex_t mutex
Definition: lock.h:136
#define pthread_mutex_trylock
Definition: lock.h:625
#define ast_bt_get_addresses(bt)
Definition: backtrace.h:38

◆ __ast_pthread_mutex_unlock()

int __ast_pthread_mutex_unlock ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 421 of file lock.c.

References __dump_backtrace(), ast_get_reentrancy(), AST_MAX_REENTRANCY, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_remove_lock_info(), ast_lock_track::backtrace, DO_THREAD_CRASH, ast_lock_track::file, ast_mutex_info::flags, ast_lock_track::func, ast_lock_track::lineno, log_mutex_error, ast_mutex_info::mutex, NULL, pthread_mutex_t, pthread_mutex_unlock, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread_id, ast_mutex_info::track, and ast_lock_track_flags::tracking.

Referenced by __ao2_unlock().

423 {
424  int res;
425 
426 #ifdef DEBUG_THREADS
427  struct ast_lock_track *lt = NULL;
428  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
429  struct ast_bt *bt = NULL;
430 
431 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
432  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
433  log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
434  filename, lineno, func, mutex_name);
436  return EINVAL;
437  }
438 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
439 
440  lt = ast_get_reentrancy(&t->track, &t->flags, 0);
441  if (lt) {
443  if (lt->reentrancy && (lt->thread_id[ROFFSET] != pthread_self())) {
444  log_mutex_error(canlog, "%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
445  filename, lineno, func, mutex_name);
446  log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",
447  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
448 #ifdef HAVE_BKTR
449  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
450 #endif
452  }
453 
454  if (--lt->reentrancy < 0) {
455  log_mutex_error(canlog, "%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
456  filename, lineno, func, mutex_name);
457  lt->reentrancy = 0;
458  }
459 
460  if (lt->reentrancy < AST_MAX_REENTRANCY) {
461  lt->file[lt->reentrancy] = NULL;
462  lt->lineno[lt->reentrancy] = 0;
463  lt->func[lt->reentrancy] = NULL;
464  lt->thread_id[lt->reentrancy] = 0;
465  }
466 
467 #ifdef HAVE_BKTR
468  if (lt->reentrancy) {
469  bt = &lt->backtrace[lt->reentrancy - 1];
470  }
471 #endif
473 
474  ast_remove_lock_info(t, bt);
475  }
476 #endif /* DEBUG_THREADS */
477 
478  res = pthread_mutex_unlock(&t->mutex);
479 
480 #ifdef DEBUG_THREADS
481  if (res) {
482  log_mutex_error(canlog, "%s line %d (%s): Error releasing mutex: %s\n",
483  filename, lineno, func, strerror(res));
485  }
486 #endif /* DEBUG_THREADS */
487 
488  return res;
489 }
struct ast_lock_track_flags flags
Definition: lock.h:147
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
#define pthread_mutex_t
Definition: lock.h:620
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
struct ast_lock_track * track
Definition: lock.h:146
Lock tracking information.
Definition: lock.h:111
unsigned int tracking
Definition: lock.h:125
#define DO_THREAD_CRASH
Definition: lock.h:247
#define ROFFSET
Definition: lock.h:240
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
remove lock info for the current thread
Definition: check_expr.c:68
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
#define AST_MAX_REENTRANCY
Definition: lock.h:101
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
static void __dump_backtrace(struct ast_bt *bt, int canlog)
Definition: lock.c:68
pthread_mutex_t mutex
Definition: lock.h:136
#define pthread_mutex_unlock
Definition: lock.h:624

◆ __ast_rwlock_destroy()

int __ast_rwlock_destroy ( const char *  filename,
int  lineno,
const char *  func,
const char *  rwlock_name,
ast_rwlock_t t 
)

Definition at line 701 of file lock.c.

References __AST_RWLOCK_INIT_VALUE, ast_get_reentrancy(), ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_lock_track::backtrace, delete_reentrancy_cs(), DO_THREAD_CRASH, ast_lock_track::file, ast_rwlock_info::flags, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, log_mutex_error, ast_lock_track::reentrancy, ast_lock_track::thread_id, ast_rwlock_info::track, and ast_lock_track_flags::tracking.

702 {
703  int res;
704 
705 #ifdef DEBUG_THREADS
706  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 1);
707  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
708 
709 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
710  if (t->lock == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
711  log_mutex_error(canlog, "%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
712  filename, lineno, func, rwlock_name);
714  res = EINVAL;
715  goto lt_cleanup;
716  }
717 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
718 #endif /* DEBUG_THREADS */
719 
720  res = pthread_rwlock_destroy(&t->lock);
721 
722 #ifdef DEBUG_THREADS
723  if (res) {
724  log_mutex_error(canlog, "%s line %d (%s): Error destroying rwlock %s: %s\n",
725  filename, lineno, func, rwlock_name, strerror(res));
726  }
727 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
728 lt_cleanup:
729 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
730  if (lt) {
732  lt->file[0] = filename;
733  lt->lineno[0] = lineno;
734  lt->func[0] = func;
735  lt->reentrancy = 0;
736  lt->thread_id[0] = 0;
737 #ifdef HAVE_BKTR
738  memset(&lt->backtrace[0], 0, sizeof(lt->backtrace[0]));
739 #endif
742  }
743 #endif /* DEBUG_THREADS */
744 
745  return res;
746 }
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:84
int reentrancy
Definition: lock.h:114
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
Lock tracking information.
Definition: lock.h:111
unsigned int tracking
Definition: lock.h:125
static void delete_reentrancy_cs(struct ast_lock_track **plt)
Definition: lock.c:129
#define DO_THREAD_CRASH
Definition: lock.h:247
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
struct ast_lock_track_flags flags
Definition: lock.h:168
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
pthread_rwlock_t lock
Definition: lock.h:157
struct ast_lock_track * track
Definition: lock.h:167

◆ __ast_rwlock_init()

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 669 of file lock.c.

References __AST_RWLOCK_INIT_VALUE, DO_THREAD_CRASH, ast_rwlock_info::flags, ast_rwlock_info::lock, log_mutex_error, NULL, ast_lock_track_flags::setup, ast_rwlock_info::track, and ast_lock_track_flags::tracking.

670 {
671  int res;
672  pthread_rwlockattr_t attr;
673 
674 #ifdef DEBUG_THREADS
675 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
676  if (t->lock != ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
677  int canlog = tracking && strcmp(filename, "logger.c");
678 
679  log_mutex_error(canlog, "%s line %d (%s): Warning: rwlock '%s' is already initialized.\n",
680  filename, lineno, func, rwlock_name);
682  return EBUSY;
683  }
684 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
685 
686  t->track = NULL;
687  t->flags.tracking = tracking;
688  t->flags.setup = 0;
689 #endif /* DEBUG_THREADS */
690 
691  pthread_rwlockattr_init(&attr);
692 #ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
693  pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP);
694 #endif
695  res = pthread_rwlock_init(&t->lock, &attr);
696  pthread_rwlockattr_destroy(&attr);
697 
698  return res;
699 }
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:84
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
volatile unsigned int setup
Definition: lock.h:127
unsigned int tracking
Definition: lock.h:125
#define DO_THREAD_CRASH
Definition: lock.h:247
struct ast_lock_track_flags flags
Definition: lock.h:168
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
pthread_rwlock_t lock
Definition: lock.h:157
struct ast_lock_track * track
Definition: lock.h:167

◆ __ast_rwlock_rdlock()

int __ast_rwlock_rdlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 819 of file lock.c.

References __dump_backtrace(), ast_bt_get_addresses, ast_get_reentrancy(), ast_mark_lock_acquired(), AST_MAX_REENTRANCY, AST_RDLOCK, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_remove_lock_info(), ast_store_lock_info(), ast_lock_track::backtrace, DO_THREAD_CRASH, ast_lock_track::file, ast_rwlock_info::flags, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, log_mutex_error, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, tmp(), ast_rwlock_info::track, and ast_lock_track_flags::tracking.

Referenced by __ao2_global_obj_ref(), __ao2_lock(), and __ast_heap_rdlock().

820 {
821  int res;
822 
823 #ifdef DEBUG_THREADS
824  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
825  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
826  struct ast_bt *bt = NULL;
827 
828  if (lt) {
829 #ifdef HAVE_BKTR
830  struct ast_bt tmp;
831 
832  /* The implementation of backtrace() may have its own locks.
833  * Capture the backtrace outside of the reentrancy lock to
834  * avoid deadlocks. See ASTERISK-22455. */
836 
838  if (lt->reentrancy < AST_MAX_REENTRANCY) {
839  lt->backtrace[lt->reentrancy] = tmp;
840  bt = &lt->backtrace[lt->reentrancy];
841  }
843 #endif
844  ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
845  }
846 #endif /* DEBUG_THREADS */
847 
848 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
849  {
850  time_t seconds = time(NULL);
851  time_t wait_time, reported_wait = 0;
852  do {
853  res = pthread_rwlock_tryrdlock(&t->lock);
854  if (res == EBUSY) {
855  wait_time = time(NULL) - seconds;
856  if (wait_time > reported_wait && (wait_time % 5) == 0) {
857  log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for readlock '%s'?\n",
858  filename, line, func, (int)wait_time, name);
859  if (lt) {
861 #ifdef HAVE_BKTR
862  __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
863 #endif
864  log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",
865  lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
866  lt->func[lt->reentrancy-1], name);
867 #ifdef HAVE_BKTR
868  __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
869 #endif
871  }
872  reported_wait = wait_time;
873  }
874  usleep(200);
875  }
876  } while (res == EBUSY);
877  }
878 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
879  res = pthread_rwlock_rdlock(&t->lock);
880 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
881 
882 #ifdef DEBUG_THREADS
883  if (!res && lt) {
885  if (lt->reentrancy < AST_MAX_REENTRANCY) {
886  lt->file[lt->reentrancy] = filename;
887  lt->lineno[lt->reentrancy] = line;
888  lt->func[lt->reentrancy] = func;
889  lt->thread_id[lt->reentrancy] = pthread_self();
890  lt->reentrancy++;
891  }
894  } else if (lt) {
895 #ifdef HAVE_BKTR
896  if (lt->reentrancy) {
898  bt = &lt->backtrace[lt->reentrancy-1];
900  } else {
901  bt = NULL;
902  }
903 #endif
904  ast_remove_lock_info(t, bt);
905  }
906 
907  if (res) {
908  log_mutex_error(canlog, "%s line %d (%s): Error obtaining read lock: %s\n",
909  filename, line, func, strerror(res));
911  }
912 #endif /* DEBUG_THREADS */
913 
914  return res;
915 }
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
static int tmp()
Definition: bt_open.c:389
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
Lock tracking information.
Definition: lock.h:111
void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
Store lock info for the current thread.
Definition: check_expr.c:61
unsigned int tracking
Definition: lock.h:125
#define DO_THREAD_CRASH
Definition: lock.h:247
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
struct ast_lock_track_flags flags
Definition: lock.h:168
void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
remove lock info for the current thread
Definition: check_expr.c:68
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
static const char name[]
Definition: cdr_mysql.c:74
void ast_mark_lock_acquired(void *lock_addr)
Mark the last lock as acquired.
Definition: check_expr.c:94
#define AST_MAX_REENTRANCY
Definition: lock.h:101
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
static void __dump_backtrace(struct ast_bt *bt, int canlog)
Definition: lock.c:68
pthread_rwlock_t lock
Definition: lock.h:157
#define ast_bt_get_addresses(bt)
Definition: backtrace.h:38
struct ast_lock_track * track
Definition: lock.h:167

◆ __ast_rwlock_timedrdlock()

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 1014 of file lock.c.

References ast_bt_get_addresses, ast_get_reentrancy(), ast_mark_lock_acquired(), AST_MAX_REENTRANCY, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_remove_lock_info(), ast_store_lock_info(), ast_tvnow(), AST_WRLOCK, ast_lock_track::backtrace, DO_THREAD_CRASH, ast_lock_track::file, ast_rwlock_info::flags, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, log_mutex_error, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, tmp(), ast_rwlock_info::track, and ast_lock_track_flags::tracking.

1016 {
1017  int res;
1018 
1019 #ifdef DEBUG_THREADS
1020  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
1021  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
1022  struct ast_bt *bt = NULL;
1023 
1024  if (lt) {
1025 #ifdef HAVE_BKTR
1026  struct ast_bt tmp;
1027 
1028  /* The implementation of backtrace() may have its own locks.
1029  * Capture the backtrace outside of the reentrancy lock to
1030  * avoid deadlocks. See ASTERISK-22455. */
1032 
1033  ast_reentrancy_lock(lt);
1034  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1035  lt->backtrace[lt->reentrancy] = tmp;
1036  bt = &lt->backtrace[lt->reentrancy];
1037  }
1039 #endif
1040  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
1041  }
1042 #endif /* DEBUG_THREADS */
1043 
1044 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
1045  res = pthread_rwlock_timedrdlock(&t->lock, abs_timeout);
1046 #else
1047  do {
1048  struct timeval _now;
1049  for (;;) {
1050  if (!(res = pthread_rwlock_tryrdlock(&t->lock))) {
1051  break;
1052  }
1053  _now = ast_tvnow();
1054  if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
1055  break;
1056  }
1057  usleep(1);
1058  }
1059  } while (0);
1060 #endif
1061 
1062 #ifdef DEBUG_THREADS
1063  if (!res && lt) {
1064  ast_reentrancy_lock(lt);
1065  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1066  lt->file[lt->reentrancy] = filename;
1067  lt->lineno[lt->reentrancy] = line;
1068  lt->func[lt->reentrancy] = func;
1069  lt->thread_id[lt->reentrancy] = pthread_self();
1070  lt->reentrancy++;
1071  }
1074  } else if (lt) {
1075 #ifdef HAVE_BKTR
1076  if (lt->reentrancy) {
1077  ast_reentrancy_lock(lt);
1078  bt = &lt->backtrace[lt->reentrancy-1];
1080  } else {
1081  bt = NULL;
1082  }
1083 #endif
1084  ast_remove_lock_info(t, bt);
1085  }
1086  if (res) {
1087  log_mutex_error(canlog, "%s line %d (%s): Error obtaining read lock: %s\n",
1088  filename, line, func, strerror(res));
1090  }
1091 #endif /* DEBUG_THREADS */
1092 
1093  return res;
1094 }
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
static int tmp()
Definition: bt_open.c:389
int reentrancy
Definition: lock.h:114
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
Lock tracking information.
Definition: lock.h:111
void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
Store lock info for the current thread.
Definition: check_expr.c:61
unsigned int tracking
Definition: lock.h:125
#define DO_THREAD_CRASH
Definition: lock.h:247
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
struct ast_lock_track_flags flags
Definition: lock.h:168
void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
remove lock info for the current thread
Definition: check_expr.c:68
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
static const char name[]
Definition: cdr_mysql.c:74
void ast_mark_lock_acquired(void *lock_addr)
Mark the last lock as acquired.
Definition: check_expr.c:94
#define AST_MAX_REENTRANCY
Definition: lock.h:101
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
pthread_rwlock_t lock
Definition: lock.h:157
#define ast_bt_get_addresses(bt)
Definition: backtrace.h:38
struct ast_lock_track * track
Definition: lock.h:167

◆ __ast_rwlock_timedwrlock()

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 1096 of file lock.c.

References ast_bt_get_addresses, ast_get_reentrancy(), ast_mark_lock_acquired(), AST_MAX_REENTRANCY, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_remove_lock_info(), ast_store_lock_info(), ast_tvnow(), AST_WRLOCK, ast_lock_track::backtrace, DO_THREAD_CRASH, ast_lock_track::file, ast_rwlock_info::flags, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, log_mutex_error, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, tmp(), ast_rwlock_info::track, and ast_lock_track_flags::tracking.

1098 {
1099  int res;
1100 
1101 #ifdef DEBUG_THREADS
1102  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
1103  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
1104  struct ast_bt *bt = NULL;
1105 
1106  if (lt) {
1107 #ifdef HAVE_BKTR
1108  struct ast_bt tmp;
1109 
1110  /* The implementation of backtrace() may have its own locks.
1111  * Capture the backtrace outside of the reentrancy lock to
1112  * avoid deadlocks. See ASTERISK-22455. */
1114 
1115  ast_reentrancy_lock(lt);
1116  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1117  lt->backtrace[lt->reentrancy] = tmp;
1118  bt = &lt->backtrace[lt->reentrancy];
1119  }
1121 #endif
1122  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
1123  }
1124 #endif /* DEBUG_THREADS */
1125 
1126 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
1127  res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout);
1128 #else
1129  do {
1130  struct timeval _now;
1131  for (;;) {
1132  if (!(res = pthread_rwlock_trywrlock(&t->lock))) {
1133  break;
1134  }
1135  _now = ast_tvnow();
1136  if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
1137  break;
1138  }
1139  usleep(1);
1140  }
1141  } while (0);
1142 #endif
1143 
1144 #ifdef DEBUG_THREADS
1145  if (!res && lt) {
1146  ast_reentrancy_lock(lt);
1147  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1148  lt->file[lt->reentrancy] = filename;
1149  lt->lineno[lt->reentrancy] = line;
1150  lt->func[lt->reentrancy] = func;
1151  lt->thread_id[lt->reentrancy] = pthread_self();
1152  lt->reentrancy++;
1153  }
1156  } else if (lt) {
1157 #ifdef HAVE_BKTR
1158  if (lt->reentrancy) {
1159  ast_reentrancy_lock(lt);
1160  bt = &lt->backtrace[lt->reentrancy-1];
1162  } else {
1163  bt = NULL;
1164  }
1165 #endif
1166  ast_remove_lock_info(t, bt);
1167  }
1168  if (res) {
1169  log_mutex_error(canlog, "%s line %d (%s): Error obtaining read lock: %s\n",
1170  filename, line, func, strerror(res));
1172  }
1173 #endif /* DEBUG_THREADS */
1174 
1175  return res;
1176 }
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
static int tmp()
Definition: bt_open.c:389
int reentrancy
Definition: lock.h:114
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
Lock tracking information.
Definition: lock.h:111
void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
Store lock info for the current thread.
Definition: check_expr.c:61
unsigned int tracking
Definition: lock.h:125
#define DO_THREAD_CRASH
Definition: lock.h:247
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
struct ast_lock_track_flags flags
Definition: lock.h:168
void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
remove lock info for the current thread
Definition: check_expr.c:68
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
static const char name[]
Definition: cdr_mysql.c:74
void ast_mark_lock_acquired(void *lock_addr)
Mark the last lock as acquired.
Definition: check_expr.c:94
#define AST_MAX_REENTRANCY
Definition: lock.h:101
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
pthread_rwlock_t lock
Definition: lock.h:157
#define ast_bt_get_addresses(bt)
Definition: backtrace.h:38
struct ast_lock_track * track
Definition: lock.h:167

◆ __ast_rwlock_tryrdlock()

int __ast_rwlock_tryrdlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 1178 of file lock.c.

References ast_bt_get_addresses, ast_get_reentrancy(), ast_mark_lock_acquired(), ast_mark_lock_failed(), AST_MAX_REENTRANCY, AST_RDLOCK, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_store_lock_info(), ast_lock_track::backtrace, ast_lock_track::file, ast_rwlock_info::flags, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, tmp(), and ast_rwlock_info::track.

Referenced by __ao2_trylock().

1179 {
1180  int res;
1181 
1182 #ifdef DEBUG_THREADS
1183  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
1184  struct ast_bt *bt = NULL;
1185 
1186  if (lt) {
1187 #ifdef HAVE_BKTR
1188  struct ast_bt tmp;
1189 
1190  /* The implementation of backtrace() may have its own locks.
1191  * Capture the backtrace outside of the reentrancy lock to
1192  * avoid deadlocks. See ASTERISK-22455. */
1194 
1195  ast_reentrancy_lock(lt);
1196  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1197  lt->backtrace[lt->reentrancy] = tmp;
1198  bt = &lt->backtrace[lt->reentrancy];
1199  }
1201 #endif
1202  ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
1203  }
1204 #endif /* DEBUG_THREADS */
1205 
1206  res = pthread_rwlock_tryrdlock(&t->lock);
1207 
1208 #ifdef DEBUG_THREADS
1209  if (!res && lt) {
1210  ast_reentrancy_lock(lt);
1211  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1212  lt->file[lt->reentrancy] = filename;
1213  lt->lineno[lt->reentrancy] = line;
1214  lt->func[lt->reentrancy] = func;
1215  lt->thread_id[lt->reentrancy] = pthread_self();
1216  lt->reentrancy++;
1217  }
1220  } else if (lt) {
1222  }
1223 #endif /* DEBUG_THREADS */
1224 
1225  return res;
1226 }
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
void ast_mark_lock_failed(void *lock_addr)
Mark the last lock as failed (trylock)
Definition: extconf.c:2314
static int tmp()
Definition: bt_open.c:389
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
Lock tracking information.
Definition: lock.h:111
void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
Store lock info for the current thread.
Definition: check_expr.c:61
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
struct ast_lock_track_flags flags
Definition: lock.h:168
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
static const char name[]
Definition: cdr_mysql.c:74
void ast_mark_lock_acquired(void *lock_addr)
Mark the last lock as acquired.
Definition: check_expr.c:94
#define AST_MAX_REENTRANCY
Definition: lock.h:101
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
pthread_rwlock_t lock
Definition: lock.h:157
#define ast_bt_get_addresses(bt)
Definition: backtrace.h:38
struct ast_lock_track * track
Definition: lock.h:167

◆ __ast_rwlock_trywrlock()

int __ast_rwlock_trywrlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 1228 of file lock.c.

References ast_bt_get_addresses, ast_get_reentrancy(), ast_mark_lock_acquired(), ast_mark_lock_failed(), AST_MAX_REENTRANCY, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_store_lock_info(), AST_WRLOCK, ast_lock_track::backtrace, ast_lock_track::file, ast_rwlock_info::flags, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, tmp(), and ast_rwlock_info::track.

Referenced by __ao2_trylock().

1229 {
1230  int res;
1231 
1232 #ifdef DEBUG_THREADS
1233  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
1234  struct ast_bt *bt = NULL;
1235 
1236  if (lt) {
1237 #ifdef HAVE_BKTR
1238  struct ast_bt tmp;
1239 
1240  /* The implementation of backtrace() may have its own locks.
1241  * Capture the backtrace outside of the reentrancy lock to
1242  * avoid deadlocks. See ASTERISK-22455. */
1244 
1245  ast_reentrancy_lock(lt);
1246  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1247  lt->backtrace[lt->reentrancy] = tmp;
1248  bt = &lt->backtrace[lt->reentrancy];
1249  }
1251 #endif
1252  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
1253  }
1254 #endif /* DEBUG_THREADS */
1255 
1256  res = pthread_rwlock_trywrlock(&t->lock);
1257 
1258 #ifdef DEBUG_THREADS
1259  if (!res && lt) {
1260  ast_reentrancy_lock(lt);
1261  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1262  lt->file[lt->reentrancy] = filename;
1263  lt->lineno[lt->reentrancy] = line;
1264  lt->func[lt->reentrancy] = func;
1265  lt->thread_id[lt->reentrancy] = pthread_self();
1266  lt->reentrancy++;
1267  }
1270  } else if (lt) {
1272  }
1273 #endif /* DEBUG_THREADS */
1274 
1275  return res;
1276 }
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
void ast_mark_lock_failed(void *lock_addr)
Mark the last lock as failed (trylock)
Definition: extconf.c:2314
static int tmp()
Definition: bt_open.c:389
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
Lock tracking information.
Definition: lock.h:111
void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
Store lock info for the current thread.
Definition: check_expr.c:61
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
struct ast_lock_track_flags flags
Definition: lock.h:168
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
static const char name[]
Definition: cdr_mysql.c:74
void ast_mark_lock_acquired(void *lock_addr)
Mark the last lock as acquired.
Definition: check_expr.c:94
#define AST_MAX_REENTRANCY
Definition: lock.h:101
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
pthread_rwlock_t lock
Definition: lock.h:157
#define ast_bt_get_addresses(bt)
Definition: backtrace.h:38
struct ast_lock_track * track
Definition: lock.h:167

◆ __ast_rwlock_unlock()

int __ast_rwlock_unlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 748 of file lock.c.

References __AST_RWLOCK_INIT_VALUE, ast_get_reentrancy(), AST_PTHREADT_NULL, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_remove_lock_info(), ast_lock_track::backtrace, DO_THREAD_CRASH, ast_lock_track::file, ast_rwlock_info::flags, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, log_mutex_error, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, ast_rwlock_info::track, and ast_lock_track_flags::tracking.

Referenced by __ao2_global_obj_ref(), __ao2_global_obj_replace(), __ao2_unlock(), and __ast_heap_unlock().

749 {
750  int res;
751 
752 #ifdef DEBUG_THREADS
753  struct ast_lock_track *lt = NULL;
754  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
755  struct ast_bt *bt = NULL;
756  int lock_found = 0;
757 
758 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
759  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
760  log_mutex_error(canlog, "%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
761  filename, line, func, name);
763  return EINVAL;
764  }
765 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
766 
767  lt = ast_get_reentrancy(&t->track, &t->flags, 0);
768  if (lt) {
770  if (lt->reentrancy) {
771  int i;
772  pthread_t self = pthread_self();
773  for (i = lt->reentrancy - 1; i >= 0; --i) {
774  if (lt->thread_id[i] == self) {
775  lock_found = 1;
776  if (i != lt->reentrancy - 1) {
777  lt->file[i] = lt->file[lt->reentrancy - 1];
778  lt->lineno[i] = lt->lineno[lt->reentrancy - 1];
779  lt->func[i] = lt->func[lt->reentrancy - 1];
780  lt->thread_id[i] = lt->thread_id[lt->reentrancy - 1];
781  }
782 #ifdef HAVE_BKTR
783  bt = &lt->backtrace[i];
784 #endif
785  lt->file[lt->reentrancy - 1] = NULL;
786  lt->lineno[lt->reentrancy - 1] = 0;
787  lt->func[lt->reentrancy - 1] = NULL;
788  lt->thread_id[lt->reentrancy - 1] = AST_PTHREADT_NULL;
789  break;
790  }
791  }
792  }
793 
794  if (lock_found && --lt->reentrancy < 0) {
795  log_mutex_error(canlog, "%s line %d (%s): rwlock '%s' freed more times than we've locked!\n",
796  filename, line, func, name);
797  lt->reentrancy = 0;
798  }
799 
801 
802  ast_remove_lock_info(t, bt);
803  }
804 #endif /* DEBUG_THREADS */
805 
806  res = pthread_rwlock_unlock(&t->lock);
807 
808 #ifdef DEBUG_THREADS
809  if (res) {
810  log_mutex_error(canlog, "%s line %d (%s): Error releasing rwlock: %s\n",
811  filename, line, func, strerror(res));
813  }
814 #endif /* DEBUG_THREADS */
815 
816  return res;
817 }
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:84
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
Lock tracking information.
Definition: lock.h:111
#define AST_PTHREADT_NULL
Definition: lock.h:66
unsigned int tracking
Definition: lock.h:125
#define DO_THREAD_CRASH
Definition: lock.h:247
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
struct ast_lock_track_flags flags
Definition: lock.h:168
void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
remove lock info for the current thread
Definition: check_expr.c:68
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
static const char name[]
Definition: cdr_mysql.c:74
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
pthread_rwlock_t lock
Definition: lock.h:157
struct ast_lock_track * track
Definition: lock.h:167

◆ __ast_rwlock_wrlock()

int __ast_rwlock_wrlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 917 of file lock.c.

References __dump_backtrace(), ast_bt_get_addresses, ast_get_reentrancy(), ast_mark_lock_acquired(), AST_MAX_REENTRANCY, ast_reentrancy_lock(), ast_reentrancy_unlock(), ast_remove_lock_info(), ast_store_lock_info(), AST_WRLOCK, ast_lock_track::backtrace, DO_THREAD_CRASH, ast_lock_track::file, ast_rwlock_info::flags, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, log_mutex_error, NULL, ast_lock_track::reentrancy, ast_lock_track::thread_id, tmp(), ast_rwlock_info::track, and ast_lock_track_flags::tracking.

Referenced by __ao2_global_obj_replace(), __ao2_lock(), and __ast_heap_wrlock().

918 {
919  int res;
920 
921 #ifdef DEBUG_THREADS
922  struct ast_lock_track *lt = ast_get_reentrancy(&t->track, &t->flags, 0);
923  int canlog = t->flags.tracking && strcmp(filename, "logger.c");
924  struct ast_bt *bt = NULL;
925 
926  if (lt) {
927 #ifdef HAVE_BKTR
928  struct ast_bt tmp;
929 
930  /* The implementation of backtrace() may have its own locks.
931  * Capture the backtrace outside of the reentrancy lock to
932  * avoid deadlocks. See ASTERISK-22455. */
934 
936  if (lt->reentrancy < AST_MAX_REENTRANCY) {
937  lt->backtrace[lt->reentrancy] = tmp;
938  bt = &lt->backtrace[lt->reentrancy];
939  }
941 #endif
942  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
943  }
944 #endif /* DEBUG_THREADS */
945 
946 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
947  {
948  time_t seconds = time(NULL);
949  time_t wait_time, reported_wait = 0;
950  do {
951  res = pthread_rwlock_trywrlock(&t->lock);
952  if (res == EBUSY) {
953  wait_time = time(NULL) - seconds;
954  if (wait_time > reported_wait && (wait_time % 5) == 0) {
955  log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for writelock '%s'?\n",
956  filename, line, func, (int)wait_time, name);
957  if (lt) {
959 #ifdef HAVE_BKTR
960  __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
961 #endif
962  log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",
963  lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
964  lt->func[lt->reentrancy-1], name);
965 #ifdef HAVE_BKTR
966  __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
967 #endif
969  }
970  reported_wait = wait_time;
971  }
972  usleep(200);
973  }
974  } while (res == EBUSY);
975  }
976 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
977  res = pthread_rwlock_wrlock(&t->lock);
978 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
979 
980 #ifdef DEBUG_THREADS
981  if (!res && lt) {
983  if (lt->reentrancy < AST_MAX_REENTRANCY) {
984  lt->file[lt->reentrancy] = filename;
985  lt->lineno[lt->reentrancy] = line;
986  lt->func[lt->reentrancy] = func;
987  lt->thread_id[lt->reentrancy] = pthread_self();
988  lt->reentrancy++;
989  }
992  } else if (lt) {
993 #ifdef HAVE_BKTR
994  if (lt->reentrancy) {
996  bt = &lt->backtrace[lt->reentrancy-1];
998  } else {
999  bt = NULL;
1000  }
1001 #endif
1002  ast_remove_lock_info(t, bt);
1003  }
1004  if (res) {
1005  log_mutex_error(canlog, "%s line %d (%s): Error obtaining write lock: %s\n",
1006  filename, line, func, strerror(res));
1008  }
1009 #endif /* DEBUG_THREADS */
1010 
1011  return res;
1012 }
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:112
static struct ast_lock_track * ast_get_reentrancy(struct ast_lock_track **plt, struct ast_lock_track_flags *flags, int no_setup)
Definition: lock.c:86
static int tmp()
Definition: bt_open.c:389
int reentrancy
Definition: lock.h:114
#define NULL
Definition: resample.c:96
#define log_mutex_error(canlog,...)
Definition: lock.c:57
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:113
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:118
Lock tracking information.
Definition: lock.h:111
void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
Store lock info for the current thread.
Definition: check_expr.c:61
unsigned int tracking
Definition: lock.h:125
#define DO_THREAD_CRASH
Definition: lock.h:247
static void ast_reentrancy_lock(struct ast_lock_track *lt)
Definition: lock.h:443
struct ast_lock_track_flags flags
Definition: lock.h:168
void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
remove lock info for the current thread
Definition: check_expr.c:68
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:115
static void ast_reentrancy_unlock(struct ast_lock_track *lt)
Definition: lock.h:454
static const char name[]
Definition: cdr_mysql.c:74
void ast_mark_lock_acquired(void *lock_addr)
Mark the last lock as acquired.
Definition: check_expr.c:94
#define AST_MAX_REENTRANCY
Definition: lock.h:101
pthread_t thread_id[AST_MAX_REENTRANCY]
Definition: lock.h:116
static void __dump_backtrace(struct ast_bt *bt, int canlog)
Definition: lock.c:68
pthread_rwlock_t lock
Definition: lock.h:157
#define ast_bt_get_addresses(bt)
Definition: backtrace.h:38
struct ast_lock_track * track
Definition: lock.h:167

◆ ast_atomic_dec_and_test()

int ast_atomic_dec_and_test ( volatile int *  p)
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 765 of file lock.h.

Referenced by dispose_conf(), iax2_process_thread_cleanup(), run_station(), and sla_station_exec().

◆ ast_atomic_fetchadd_int()

int ast_atomic_fetchadd_int ( volatile int *  p,
int  v 
)
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 755 of file lock.h.

References ast_atomic_sub_fetch.

Referenced by __ao2_link(), __ao2_lock(), __ao2_ref(), __ao2_trylock(), __ao2_unlock(), __ast_channel_alloc_ap(), __ast_channel_internal_alloc(), __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(), _sip_tcp_helper_thread(), accept_thread(), 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(), build_peer(), cc_device_monitor_init(), cc_extension_monitor_init(), cc_interfaces_datastore_init(), cdr_object_alloc(), chan_pjsip_new(), container_destruct(), create_new_sip_etag(), 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(), handle_message(), 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(), sip_destroy_peer(), sip_new(), sip_peer_hold(), 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(), temp_peer(), transport_create(), try_merge_optimize_out(), try_swap_optimize_out(), update_stats(), and worker_thread_alloc().

763 {

◆ ast_dump_locks()

struct ast_str* ast_dump_locks ( void  )

Generate a lock dump equivalent to "core show locks".

The lock dump generated is generally too large to be output by a single ast_verbose/log/debug/etc. call. Only ast_cli() handles it properly without changing BUFSIZ in logger.c.

Note: This must be ast_free()d when you're done with it.

Return values
Anast_str containing the lock dump
NULLon error
Since
12

Definition at line 1264 of file main/utils.c.

References append_lock_information(), ast_get_version(), AST_LIST_TRAVERSE, ast_str_append(), ast_str_create, thr_lock_info::lock, lock_info, lock_infos_lock, thr_lock_info::locks, thr_lock_info::lwp, ast_mutex_info::mutex, NULL, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, str, thr_lock_info::suspended, thr_lock_info::thread_id, and thr_lock_info::thread_name.

Referenced by handle_show_locks().

1265 {
1266 #if !defined(LOW_MEMORY)
1267  struct thr_lock_info *lock_info;
1268  struct ast_str *str;
1269 
1270  if (!(str = ast_str_create(4096))) {
1271  return NULL;
1272  }
1273 
1274  ast_str_append(&str, 0, "\n"
1275  "=======================================================================\n"
1276  "=== %s\n"
1277  "=== Currently Held Locks\n"
1278  "=======================================================================\n"
1279  "===\n"
1280  "=== <pending> <lock#> (<file>): <lock type> <line num> <function> <lock name> <lock addr> (times locked)\n"
1281  "===\n", ast_get_version());
1282 
1283  if (!str) {
1284  return NULL;
1285  }
1286 
1288  AST_LIST_TRAVERSE(&lock_infos, lock_info, entry) {
1289  int i;
1290  int header_printed = 0;
1291  pthread_mutex_lock(&lock_info->lock);
1292  for (i = 0; str && i < lock_info->num_locks; i++) {
1293  /* Don't show suspended locks */
1294  if (lock_info->locks[i].suspended) {
1295  continue;
1296  }
1297 
1298  if (!header_printed) {
1299  if (lock_info->lwp != -1) {
1300  ast_str_append(&str, 0, "=== Thread ID: 0x%lx LWP:%d (%s)\n",
1301  (long unsigned) lock_info->thread_id, lock_info->lwp, lock_info->thread_name);
1302  } else {
1303  ast_str_append(&str, 0, "=== Thread ID: 0x%lx (%s)\n",
1304  (long unsigned) lock_info->thread_id, lock_info->thread_name);
1305  }
1306  header_printed = 1;
1307  }
1308 
1309  append_lock_information(&str, lock_info, i);
1310  }
1311  pthread_mutex_unlock(&lock_info->lock);
1312  if (!str) {
1313  break;
1314  }
1315  if (header_printed) {
1316  ast_str_append(&str, 0, "=== -------------------------------------------------------------------\n"
1317  "===\n");
1318  }
1319  if (!str) {
1320  break;
1321  }
1322  }
1324 
1325  if (!str) {
1326  return NULL;
1327  }
1328 
1329  ast_str_append(&str, 0, "=======================================================================\n"
1330  "\n");
1331 
1332  return str;
1333 #else /* if defined(LOW_MEMORY) */
1334  return NULL;
1335 #endif
1336 }
struct thr_lock_info::@431 locks[AST_MAX_LOCKS]
const char * ast_get_version(void)
Retrieve the Asterisk version string.
Definition: version.c:16
static void append_lock_information(struct ast_str **str, struct thr_lock_info *lock_info, int i)
Definition: main/utils.c:1174
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
unsigned int num_locks
Definition: main/utils.c:841
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
static ast_mutex_t lock_infos_lock
Locked when accessing the lock_infos list.
Definition: main/utils.c:853
#define pthread_mutex_lock
Definition: lock.h:623
static const struct ast_datastore_info lock_info
Definition: func_lock.c:115
pthread_mutex_t lock
Definition: main/utils.c:846
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
pthread_t thread_id
Definition: main/utils.c:818
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
const char * thread_name
Definition: main/utils.c:820
A list of each thread&#39;s lock info.
Definition: main/utils.c:857
Keep track of which locks a thread holds.
Definition: main/utils.c:816
pthread_mutex_t mutex
Definition: lock.h:136
Definition: search.h:40
#define pthread_mutex_unlock
Definition: lock.h:624
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ ast_find_lock_info()

int ast_find_lock_info ( void *  lock_addr,
char *  filename,
size_t  filename_size,
int *  lineno,
char *  func,
size_t  func_size,
char *  mutex_name,
size_t  mutex_name_size 
)

retrieve lock info for the specified mutex

this gets called during deadlock avoidance, so that the information may be preserved as to what location originally acquired the lock.

Definition at line 995 of file main/utils.c.

References ast_copy_string(), ast_threadstorage_get(), thr_lock_info::file, thr_lock_info::func, thr_lock_info::line_num, thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::lock_name, thr_lock_info::locks, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, and thread_lock_info.

996 {
997 #if !defined(LOW_MEMORY)
998  struct thr_lock_info *lock_info;
999  int i = 0;
1000 
1001  if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
1002  return -1;
1003 
1004  pthread_mutex_lock(&lock_info->lock);
1005 
1006  for (i = lock_info->num_locks - 1; i >= 0; i--) {
1007  if (lock_info->locks[i].lock_addr == lock_addr)
1008  break;
1009  }
1010 
1011  if (i == -1) {
1012  /* Lock not found :( */
1013  pthread_mutex_unlock(&lock_info->lock);
1014  return -1;
1015  }
1016 
1017  ast_copy_string(filename, lock_info->locks[i].file, filename_size);
1018  *lineno = lock_info->locks[i].line_num;
1019  ast_copy_string(func, lock_info->locks[i].func, func_size);
1020  ast_copy_string(mutex_name, lock_info->locks[i].lock_name, mutex_name_size);
1021 
1022  pthread_mutex_unlock(&lock_info->lock);
1023 
1024  return 0;
1025 #else /* if defined(LOW_MEMORY) */
1026  return -1;
1027 #endif
1028 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
struct thr_lock_info::@431 locks[AST_MAX_LOCKS]
const char * lock_name
Definition: main/utils.c:825
static struct ast_threadstorage thread_lock_info
Definition: main/utils.c:902
unsigned int num_locks
Definition: main/utils.c:841
void * lock_addr
Definition: main/utils.c:826
#define pthread_mutex_lock
Definition: lock.h:623
const char * func
Definition: main/utils.c:824
static const struct ast_datastore_info lock_info
Definition: func_lock.c:115
pthread_mutex_t lock
Definition: main/utils.c:846
const char * file
Definition: main/utils.c:823
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
Keep track of which locks a thread holds.
Definition: main/utils.c:816
#define pthread_mutex_unlock
Definition: lock.h:624

◆ ast_log_show_lock()

void ast_log_show_lock ( void *  this_lock_addr)

log info for the current lock with ast_log().

this function would be mostly for debug. If you come across a lock that is unexpectedly but momentarily locked, and you wonder who are fighting with for the lock, this routine could be called, IF you have the thread debugging stuff turned on.

Parameters
this_lock_addrlock address to return lock information
Since
1.6.1

This function can help you find highly temporal locks; locks that happen for a short time, but at unexpected times, usually at times that create a deadlock, Why is this thing locked right then? Who is locking it? Who am I fighting with for this lock?

To answer such questions, just call this routine before you would normally try to aquire a lock. It doesn't do anything if the lock is not acquired. If the lock is taken, it will publish a line or two to the console via ast_log().

Sometimes, the lock message is pretty uninformative. For instance, you might find that the lock is being aquired deep within the astobj2 code; this tells you little about higher level routines that call the astobj2 routines. But, using gdb, you can set a break at the ast_log below, and for that breakpoint, you can set the commands: where cont which will give a stack trace and continue. – that aught to do the job!

Definition at line 1231 of file main/utils.c.

References append_lock_information(), ast_free, AST_LIST_TRAVERSE, ast_log, ast_str_buffer(), ast_str_create, thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, lock_infos_lock, thr_lock_info::locks, LOG_NOTICE, ast_mutex_info::mutex, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, and str.

1232 {
1233 #if !defined(LOW_MEMORY)
1234  struct thr_lock_info *lock_info;
1235  struct ast_str *str;
1236 
1237  if (!(str = ast_str_create(4096))) {
1238  ast_log(LOG_NOTICE,"Could not create str\n");
1239  return;
1240  }
1241 
1242 
1244  AST_LIST_TRAVERSE(&lock_infos, lock_info, entry) {
1245  int i;
1246  pthread_mutex_lock(&lock_info->lock);
1247  for (i = 0; str && i < lock_info->num_locks; i++) {
1248  /* ONLY show info about this particular lock, if
1249  it's acquired... */
1250  if (lock_info->locks[i].lock_addr == this_lock_addr) {
1251  append_lock_information(&str, lock_info, i);
1252  ast_log(LOG_NOTICE, "%s", ast_str_buffer(str));
1253  break;
1254  }
1255  }
1256  pthread_mutex_unlock(&lock_info->lock);
1257  }
1259  ast_free(str);
1260 #endif /* ! LOW_MEMORY */
1261 }
struct thr_lock_info::@431 locks[AST_MAX_LOCKS]
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
static void append_lock_information(struct ast_str **str, struct thr_lock_info *lock_info, int i)
Definition: main/utils.c:1174
unsigned int num_locks
Definition: main/utils.c:841
const char * str
Definition: app_jack.c:147
void * lock_addr
Definition: main/utils.c:826
#define ast_log
Definition: astobj2.c:42
static ast_mutex_t lock_infos_lock
Locked when accessing the lock_infos list.
Definition: main/utils.c:853
#define pthread_mutex_lock
Definition: lock.h:623
static const struct ast_datastore_info lock_info
Definition: func_lock.c:115
pthread_mutex_t lock
Definition: main/utils.c:846
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define LOG_NOTICE
Definition: logger.h:263
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_free(a)
Definition: astmm.h:182
A list of each thread&#39;s lock info.
Definition: main/utils.c:857
Keep track of which locks a thread holds.
Definition: main/utils.c:816
pthread_mutex_t mutex
Definition: lock.h:136
Definition: search.h:40
#define pthread_mutex_unlock
Definition: lock.h:624
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ ast_mark_lock_acquired()

void ast_mark_lock_acquired ( void *  lock_addr)

◆ ast_mark_lock_failed()

void ast_mark_lock_failed ( void *  lock_addr)

◆ ast_reentrancy_lock()

static void ast_reentrancy_lock ( struct ast_lock_track lt)
inlinestatic

Definition at line 443 of file lock.h.

References pthread_mutex_lock, and ast_lock_track::reentr_mutex.

Referenced by __ast_cond_timedwait(), __ast_cond_wait(), __ast_pthread_mutex_destroy(), __ast_pthread_mutex_lock(), __ast_pthread_mutex_trylock(), __ast_pthread_mutex_unlock(), __ast_rwlock_destroy(), __ast_rwlock_rdlock(), __ast_rwlock_timedrdlock(), __ast_rwlock_timedwrlock(), __ast_rwlock_tryrdlock(), __ast_rwlock_trywrlock(), __ast_rwlock_unlock(), __ast_rwlock_wrlock(), append_lock_information(), and restore_lock_tracking().

444 {
445  int res;
446  if ((res = pthread_mutex_lock(&lt->reentr_mutex))) {
447  fprintf(stderr, "ast_reentrancy_lock failed: '%s' (%d)\n", strerror(res), res);
448 #if defined(DO_CRASH) || defined(THREAD_CRASH)
449  abort();
450 #endif
451  }
452 }
#define pthread_mutex_lock
Definition: lock.h:623
pthread_mutex_t reentr_mutex
Definition: lock.h:120

◆ ast_reentrancy_unlock()

static void ast_reentrancy_unlock ( struct ast_lock_track lt)
inlinestatic

Definition at line 454 of file lock.h.

References pthread_mutex_unlock, and ast_lock_track::reentr_mutex.

Referenced by __ast_cond_timedwait(), __ast_cond_wait(), __ast_pthread_mutex_destroy(), __ast_pthread_mutex_lock(), __ast_pthread_mutex_trylock(), __ast_pthread_mutex_unlock(), __ast_rwlock_destroy(), __ast_rwlock_rdlock(), __ast_rwlock_timedrdlock(), __ast_rwlock_timedwrlock(), __ast_rwlock_tryrdlock(), __ast_rwlock_trywrlock(), __ast_rwlock_unlock(), __ast_rwlock_wrlock(), append_lock_information(), and restore_lock_tracking().

455 {
456  int res;
457  if ((res = pthread_mutex_unlock(&lt->reentr_mutex))) {
458  fprintf(stderr, "ast_reentrancy_unlock failed: '%s' (%d)\n", strerror(res), res);
459 #if defined(DO_CRASH) || defined(THREAD_CRASH)
460  abort();
461 #endif
462  }
463 }
pthread_mutex_t reentr_mutex
Definition: lock.h:120
#define pthread_mutex_unlock
Definition: lock.h:624

◆ ast_remove_lock_info()

void ast_remove_lock_info ( void *  lock_addr,
struct ast_bt bt 
)

remove lock info for the current thread

this gets called by ast_mutex_unlock so that information on the lock can be removed from the current thread's lock info struct.

Definition at line 68 of file check_expr.c.

References __ast_bt_get_addresses(), ast_threadstorage_get(), thr_lock_info::backtrace, thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::locks, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, thread_lock_info, and thr_lock_info::times_locked.

Referenced by __ast_pthread_mutex_lock(), __ast_pthread_mutex_unlock(), __ast_rwlock_rdlock(), __ast_rwlock_timedrdlock(), __ast_rwlock_timedwrlock(), __ast_rwlock_unlock(), __ast_rwlock_wrlock(), and ast_store_lock_info().

69 {
70  /* not a lot to do in a standalone w/o threading! */
71 }

◆ ast_restore_lock_info()

void ast_restore_lock_info ( void *  lock_addr)

Definition at line 1059 of file main/utils.c.

References ast_mark_lock_acquired(), ast_threadstorage_get(), thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::locks, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, thr_lock_info::suspended, and thread_lock_info.

Referenced by __ast_cond_timedwait(), and __ast_cond_wait().

1060 {
1061 #if !defined(LOW_MEMORY)
1062  struct thr_lock_info *lock_info;
1063  int i = 0;
1064 
1065  if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
1066  return;
1067 
1068  pthread_mutex_lock(&lock_info->lock);
1069 
1070  for (i = lock_info->num_locks - 1; i >= 0; i--) {
1071  if (lock_info->locks[i].lock_addr == lock_addr)
1072  break;
1073  }
1074 
1075  if (i == -1) {
1076  /* Lock not found :( */
1077  pthread_mutex_unlock(&lock_info->lock);
1078  return;
1079  }
1080 
1081  lock_info->locks[i].suspended = 0;
1082 
1083  pthread_mutex_unlock(&lock_info->lock);
1084 #endif /* ! LOW_MEMORY */
1085 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
struct thr_lock_info::@431 locks[AST_MAX_LOCKS]
static struct ast_threadstorage thread_lock_info
Definition: main/utils.c:902
unsigned int num_locks
Definition: main/utils.c:841
void * lock_addr
Definition: main/utils.c:826
#define pthread_mutex_lock
Definition: lock.h:623
static const struct ast_datastore_info lock_info
Definition: func_lock.c:115
pthread_mutex_t lock
Definition: main/utils.c:846
Keep track of which locks a thread holds.
Definition: main/utils.c:816
#define pthread_mutex_unlock
Definition: lock.h:624

◆ ast_store_lock_info()

void ast_store_lock_info ( enum ast_lock_type  type,
const char *  filename,
int  line_num,
const char *  func,
const char *  lock_name,
void *  lock_addr,
struct ast_bt bt 
)

Store lock info for the current thread.

This function gets called in ast_mutex_lock() and ast_mutex_trylock() so that information about this lock can be stored in this thread's lock info struct. The lock is marked as pending as the thread is waiting on the lock. ast_mark_lock_acquired() will mark it as held by this thread.

Definition at line 61 of file check_expr.c.

References AST_MAX_LOCKS, ast_remove_lock_info(), ast_threadstorage_get(), thr_lock_info::backtrace, thr_lock_info::file, thr_lock_info::func, thr_lock_info::line_num, thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::lock_name, thr_lock_info::locks, thr_lock_info::num_locks, thr_lock_info::pending, pthread_mutex_lock, pthread_mutex_unlock, thread_lock_info, thr_lock_info::times_locked, and thr_lock_info::type.

Referenced by __ast_pthread_mutex_lock(), __ast_pthread_mutex_trylock(), __ast_rwlock_rdlock(), __ast_rwlock_timedrdlock(), __ast_rwlock_timedwrlock(), __ast_rwlock_tryrdlock(), __ast_rwlock_trywrlock(), and __ast_rwlock_wrlock().

63 {
64  /* not a lot to do in a standalone w/o threading! */
65 }

◆ ast_suspend_lock_info()

void ast_suspend_lock_info ( void *  lock_addr)

Definition at line 1030 of file main/utils.c.

References ast_threadstorage_get(), thr_lock_info::lock, thr_lock_info::lock_addr, lock_info, thr_lock_info::locks, thr_lock_info::num_locks, pthread_mutex_lock, pthread_mutex_unlock, thr_lock_info::suspended, and thread_lock_info.

Referenced by __ast_cond_timedwait(), and __ast_cond_wait().

1031 {
1032 #if !defined(LOW_MEMORY)
1033  struct thr_lock_info *lock_info;
1034  int i = 0;
1035 
1036  if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info)))) {
1037  return;
1038  }
1039 
1040  pthread_mutex_lock(&lock_info->lock);
1041 
1042  for (i = lock_info->num_locks - 1; i >= 0; i--) {
1043  if (lock_info->locks[i].lock_addr == lock_addr)
1044  break;
1045  }
1046 
1047  if (i == -1) {
1048  /* Lock not found :( */
1049  pthread_mutex_unlock(&lock_info->lock);
1050  return;
1051  }
1052 
1053  lock_info->locks[i].suspended = 1;
1054 
1055  pthread_mutex_unlock(&lock_info->lock);
1056 #endif /* ! LOW_MEMORY */
1057 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
struct thr_lock_info::@431 locks[AST_MAX_LOCKS]
static struct ast_threadstorage thread_lock_info
Definition: main/utils.c:902
unsigned int num_locks
Definition: main/utils.c:841
void * lock_addr
Definition: main/utils.c:826
#define pthread_mutex_lock
Definition: lock.h:623
static const struct ast_datastore_info lock_info
Definition: func_lock.c:115
pthread_mutex_t lock
Definition: main/utils.c:846
Keep track of which locks a thread holds.
Definition: main/utils.c:816
#define pthread_mutex_unlock
Definition: lock.h:624