lock.h File Reference

Asterisk locking-related definitions: More...

#include <pthread.h>
#include <time.h>
#include <sys/param.h>
#include "asterisk/backtrace.h"
#include "asterisk/logger.h"
#include "asterisk/compiler.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_mutex_info
 Structure for mutex and tracking information. More...
struct  ast_rwlock_info
 Structure for rwlock and tracking information. More...

Defines

#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   {0}
#define AO2_DEADLOCK_AVOIDANCE(obj)
#define ast_cond_broadcast(cond)   __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define ast_cond_destroy(cond)   __ast_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define ast_cond_init(cond, attr)   __ast_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr)
#define ast_cond_signal(cond)   __ast_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define ast_cond_timedwait(cond, mutex, time)   __ast_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time)
#define ast_cond_wait(cond, mutex)   __ast_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex)
#define AST_LOCK_TRACK_INIT_VALUE   { { NULL }, { 0 }, 0, { NULL }, { 0 }, 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 }
#define AST_MUTEX_INIT_VALUE_NOTRACKING   { PTHREAD_MUTEX_INIT_VALUE, NULL, 0 }
#define AST_MUTEX_INITIALIZER   __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__
#define AST_MUTEX_KIND   PTHREAD_MUTEX_RECURSIVE
#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
#define ast_rwlock_init_notracking(rwlock)   __ast_rwlock_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
 wrapper for ast_rwlock_init with tracking disabled
#define AST_RWLOCK_INIT_VALUE   { __AST_RWLOCK_INIT_VALUE, NULL, 1 }
#define AST_RWLOCK_INIT_VALUE_NOTRACKING   { __AST_RWLOCK_INIT_VALUE, NULL, 0 }
#define ast_rwlock_rdlock(a)   __ast_rwlock_rdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define ast_rwlock_timedrdlock(a, b)   __ast_rwlock_timedrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a, b)
#define ast_rwlock_timedwrlock(a, b)   __ast_rwlock_timedwrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a, b)
#define ast_rwlock_tryrdlock(a)   __ast_rwlock_tryrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define ast_rwlock_trywrlock(a)   __ast_rwlock_trywrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define ast_rwlock_unlock(a)   __ast_rwlock_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define ast_rwlock_wrlock(a)   __ast_rwlock_wrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define CHANNEL_DEADLOCK_AVOIDANCE(chan)
#define DEADLOCK_AVOIDANCE(lock)
#define DLA_LOCK(lock)   ast_mutex_lock(lock)
#define DLA_UNLOCK(lock)   ast_mutex_unlock(lock)
#define gethostbyname   __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__
#define pthread_cond_broadcast   use_ast_cond_broadcast_instead_of_pthread_cond_broadcast
#define pthread_cond_destroy   use_ast_cond_destroy_instead_of_pthread_cond_destroy
#define pthread_cond_init   use_ast_cond_init_instead_of_pthread_cond_init
#define pthread_cond_signal   use_ast_cond_signal_instead_of_pthread_cond_signal
#define pthread_cond_t   use_ast_cond_t_instead_of_pthread_cond_t
#define pthread_cond_timedwait   use_ast_cond_timedwait_instead_of_pthread_cond_timedwait
#define pthread_cond_wait   use_ast_cond_wait_instead_of_pthread_cond_wait
#define pthread_create   __use_ast_pthread_create_instead__
#define pthread_mutex_destroy   use_ast_mutex_destroy_instead_of_pthread_mutex_destroy
#define pthread_mutex_init   use_ast_mutex_init_instead_of_pthread_mutex_init
#define PTHREAD_MUTEX_INIT_VALUE   PTHREAD_MUTEX_INITIALIZER
#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.
#define SCOPED_AO2RDLOCK(varname, obj)   SCOPED_LOCK(varname, (obj), ao2_rdlock, ao2_unlock)
 scoped lock specialization for ao2 read locks.
#define SCOPED_AO2WRLOCK(varname, obj)   SCOPED_LOCK(varname, (obj), ao2_wrlock, ao2_unlock)
 scoped lock specialization for ao2 write locks.
#define SCOPED_CHANNELLOCK(varname, chan)   SCOPED_LOCK(varname, (chan), ast_channel_lock, ast_channel_unlock)
 scoped lock specialization for channels.
#define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc)   RAII_VAR(typeof((lock)), varname, ({lockfunc((lock)); (lock); }), unlockfunc)
 Scoped Locks.
#define SCOPED_MUTEX(varname, lock)   SCOPED_LOCK(varname, (lock), ast_mutex_lock, ast_mutex_unlock)
 scoped lock specialization for mutexes
#define SCOPED_RDLOCK(varname, lock)   SCOPED_LOCK(varname, (lock), ast_rwlock_rdlock, ast_rwlock_unlock)
 scoped lock specialization for read locks
#define SCOPED_WRLOCK(varname, lock)   SCOPED_LOCK(varname, (lock), ast_rwlock_wrlock, ast_rwlock_unlock)
 scoped lock specialization for write locks

Typedefs

typedef pthread_cond_t ast_cond_t
typedef struct ast_mutex_info ast_mutex_t
typedef struct ast_rwlock_info ast_rwlock_t

Functions

int __ast_cond_broadcast (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond)
int __ast_cond_destroy (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond)
int __ast_cond_init (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond, pthread_condattr_t *cond_attr)
int __ast_cond_signal (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond)
int __ast_cond_timedwait (const char *filename, int lineno, const char *func, const char *cond_name, const char *mutex_name, ast_cond_t *cond, ast_mutex_t *t, const struct timespec *abstime)
int __ast_cond_wait (const char *filename, int lineno, const char *func, const char *cond_name, const char *mutex_name, ast_cond_t *cond, ast_mutex_t *t)
int __ast_pthread_mutex_destroy (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_pthread_mutex_init (int tracking, const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_pthread_mutex_lock (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_pthread_mutex_trylock (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_pthread_mutex_unlock (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_rwlock_destroy (const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
int __ast_rwlock_init (int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
int __ast_rwlock_rdlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int __ast_rwlock_timedrdlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name, const struct timespec *abs_timeout)
int __ast_rwlock_timedwrlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name, const struct timespec *abs_timeout)
int __ast_rwlock_tryrdlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int __ast_rwlock_trywrlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int __ast_rwlock_unlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int __ast_rwlock_wrlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int ast_atomic_dec_and_test (volatile int *p)
 decrement *p by 1 and return true if the variable has reached 0. Useful e.g. to check if a refcount has reached 0.
int ast_atomic_fetchadd_int (volatile int *p, int v)
 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.
int ast_atomic_fetchadd_int_slow (volatile int *p, int v)


Detailed Description

Asterisk locking-related definitions:

Definition in file lock.h.


Define Documentation

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

Definition at line 533 of file lock.h.

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

Definition at line 556 of file lock.h.

#define __AST_RWLOCK_INIT_VALUE   {0}

Definition at line 86 of file lock.h.

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

#define AO2_DEADLOCK_AVOIDANCE ( obj   ) 

Value:

ao2_unlock(obj); \
   usleep(1); \
   ao2_lock(obj);

Definition at line 485 of file lock.h.

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

Definition at line 176 of file lock.h.

Referenced by _unload_module(), analog_ss_thread(), ast_audiohook_update_status(), ast_audiohook_write_frame(), ast_autoservice_start(), ast_devstate_changed_literal(), ast_log_full(), ast_sched_add_variable(), ast_sched_del(), ast_sched_runq(), ast_sem_post(), ast_sip_session_unsuspend(), async_callback(), autoservice_shutdown(), bridge_channel_internal_unsuspend_nolock(), bridge_manager_destroy(), bridge_manager_service_req(), calendar_destructor(), close_logger(), command_complete(), complex_task(), conf_free(), conf_run(), consumer_exec(), db_sync(), defer_full_frame(), dial_trunk(), dispatch_exec_sync(), dns_synchronous_resolve_callback(), exec_command_on_condition(), load_task(), lock_broker(), message_sink_cb(), mixmonitor_ds_destroy(), mock_cdr_backend_cb(), my_decrease_ss_count(), onCallCleared(), onNewCallCreated(), pbx_outgoing_exec(), poke_worker(), pthread_timer_open(), recurring_cancel(), resolution_thread(), run_station(), sched_thread_destroy(), schedule_calendar_event(), shutdown_poke(), shutdown_task_exec(), signal_condition(), simple_task(), sip_outbound_publish_client_destroy(), 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(), stimulate_attended_transfer(), stop_mixmonitor_full(), stop_poll_thread(), submit_unscheduled_batch(), subscription_invoke(), sync_task(), task(), test_cancel(), test_emptied(), test_msg_handle_msg_cb(), test_state_changed(), test_sub(), test_task_pushed(), tps_ping_handler(), unload_module(), user_event_hook_cb(), and worker_set_state().

#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 }, PTHREAD_MUTEX_INIT_VALUE }

Definition at line 92 of file lock.h.

#define AST_MAX_REENTRANCY   10

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

Definition at line 536 of file lock.h.

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

Definition at line 537 of file lock.h.

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

Definition at line 161 of file lock.h.

Referenced by __ast_internal_context_destroy(), __unload_module(), ast_audiohook_destroy(), ast_dial_destroy(), ast_dnsmgr_release(), ast_rtp_destroy(), ast_sched_context_destroy(), ast_sem_destroy(), ast_sip_push_task_synchronous(), ast_speech_destroy(), ast_speech_new(), AST_TEST_DEFINE(), async_data_destructor(), auth_http_callback(), build_conf(), build_gateway(), cel_verify_and_cleanup_cb(), chan_list_destructor(), close_client(), command_dtor(), conf_free(), delete_peers(), delete_users(), destroy_conference_bridge(), 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(), iax2_process_thread_cleanup(), init_logger(), internal_ao2_ref(), json_mem_free(), load_module(), mgcp_prune_realtime_gateway(), misdn_cfg_destroy(), misdn_jb_destroy(), mixmonitor_free(), ooh323_destroy(), ooh323c_call_thread(), ooh323c_start_call_thread(), recurring_data_destructor(), reload_config(), resolver_data_cleanup(), session_do(), setup_mixmonitor_ds(), shutdown_data_dtor(), 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(), and worker_thread_destroy().

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

Definition at line 159 of file lock.h.

Referenced by __ast_context_create(), accept_thread(), add_notify(), alloc_profile(), alloc_smdi_interface(), ast_audiohook_init(), ast_context_find_or_create(), ast_dial_create(), ast_dns_resolve(), ast_dnsmgr_get_family(), ast_json_malloc(), ast_rtp_new(), ast_sched_context_create(), ast_sem_init(), ast_sip_push_task_synchronous(), ast_speech_new(), ast_ssl_init(), AST_TEST_DEFINE(), async_data_alloc(), auth_http_callback(), build_conf(), build_device(), build_gateway(), 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(), ical_load_calendar(), init_logger(), init_timing_thread(), internal_ao2_alloc(), join_conference_bridge(), load_config(), load_module(), mbl_load_device(), misdn_cfg_init(), misdn_jb_init(), mkintf(), ooh323_alloc(), ooh323c_start_call_thread(), parse_config(), rcv_mac_addr(), read_config(), recurring_data_alloc(), resolver_data_init(), 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(), unload_module(), and worker_thread_alloc().

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

Definition at line 160 of file lock.h.

#define AST_MUTEX_INIT_VALUE   { PTHREAD_MUTEX_INIT_VALUE, NULL, 1 }

Definition at line 95 of file lock.h.

#define AST_MUTEX_INIT_VALUE_NOTRACKING   { PTHREAD_MUTEX_INIT_VALUE, NULL, 0 }

Definition at line 96 of file lock.h.

#define AST_MUTEX_INITIALIZER   __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__

Definition at line 653 of file lock.h.

#define AST_MUTEX_KIND   PTHREAD_MUTEX_RECURSIVE

Definition at line 80 of file lock.h.

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

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

Definition at line 162 of file lock.h.

Referenced by __attempt_transmit(), __auth_reject(), __auto_congest(), __auto_hangup(), __dahdi_exception(), __find_callno(), __get_from_jb(), __iax2_poke_noanswer(), __reload(), __send_lagrq(), __send_ping(), __unload_module(), _unload_module(), acf_channel_read(), acf_jabberreceive_read(), acl_change_stasis_cb(), action_dahdishowchannels(), 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(), analog_ss_thread(), announce_thread(), answer_exec_run(), app_exec(), append_mailbox_mapping(), ast_ari_remove_handler(), ast_atomic_fetchadd_int_slow(), ast_begin_shutdown(), ast_cancel_shutdown(), ast_cli_netstats(), ast_context_lockmacro(), ast_db_del(), ast_db_deltree(), ast_db_gettree(), ast_db_put(), ast_dial_join(), ast_dns_get_nameservers(), ast_dns_resolve(), ast_dnsmgr_changed(), ast_get_enum(), ast_iax2_new(), ast_merge_contexts_and_delete(), ast_monitor_start(), ast_random(), ast_rdlock_contexts(), ast_replace_sigchld(), ast_rtp_destroy(), ast_rtp_stop(), 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_synchronous(), 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(), attempt_transfer(), auth_reject(), authenticate_reply(), auto_hangup(), blr_ebl(), blr_txt(), bridge_agent_hold_deferred_create(), build_device(), build_reply_digest(), caldav_load_calendar(), can_safely_quit(), cb_events(), cdr_detach(), cdr_enable_batch_mode(), cdr_handler(), cdr_submit_batch(), channel_to_session(), check_unloading(), cl_dequeue_chan(), cl_queue_chan(), cli_tps_ping(), close_client(), close_mailbox(), close_rtp_connection(), close_udptl_connection(), 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_channels_data_provider_get(), 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_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(), 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_endpoint(), destroy_monitor_audiohook(), destroy_pgsql(), destroy_session(), destroy_table(), device_state_cb(), dial_trunk(), dispatch_exec_sync(), dispatch_message(), dns_synchronous_resolve_callback(), dnsmgr_refresh(), dnsmgr_shutdown(), 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(), 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(), get_chan_by_ast_name(), get_lock(), get_unused_callno(), gethostbyname_r(), handle_capabilities_res_message(), 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_misdn_show_channel(), handle_cli_misdn_show_channels(), handle_cli_mobile_cusd(), handle_cli_mobile_rfcomm(), handle_cli_mobile_show_devices(), 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_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(), headset_send_ring(), iax2_call(), iax2_do_register(), iax2_fixup(), iax2_hangup(), iax2_indicate(), iax2_key_rotate(), 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(), json_mem_lock(), key_main_page(), key_select_extension(), leave_voicemail(), load_config(), load_module(), lock_broker(), 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(), 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(), notify_daemon(), 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(), play_message(), play_message_by_id_helper(), play_sound_helper(), presence_state_cb(), private_enum_init(), prune_gateways(), pthread_timer_open(), pvt_destructor(), 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(), release_chan(), release_chan_early(), reload(), reload_config(), reload_followme(), reload_module(), replace_callno(), reqprep(), require_mysql(), require_pgsql(), resolution_thread(), restart_monitor(), restart_pktc_thread(), retrans_pkt(), run_station(), save_to_folder(), sched_run(), sched_thread_destroy(), schedule_calendar_event(), scheduled_destroy(), sco_accept(), send_client(), send_command_locked(), send_lagrq(), send_ping(), 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_outbound_publish_client_destroy(), 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_video(), softmix_bridge_write_voice(), softmix_mixing_loop(), softmix_mixing_thread(), softmix_poke_thread(), spandsp_fax_cli_show_stats(), speech_background(), sqlite_log(), start_network_thread(), start_rtp(), stop_mixmonitor_full(), stop_poll_thread(), store_pgsql(), stun_monitor_request(), stun_stop_monitor(), submit_scheduled_batch(), submit_unscheduled_batch(), sync_task(), syslog_log(), 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(), update2_ldap(), update_ldap(), update_pgsql(), update_registry(), user_event_hook_cb(), user_event_wait_for_events(), vm_execmain(), vm_instructions_en(), vm_instructions_ja(), wait_for_resolution(), worker_start(), write_cdr(), write_cel(), writefile(), and xmpp_pak_message().

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

Definition at line 163 of file lock.h.

Referenced by __attempt_transmit(), __auth_reject(), __auto_congest(), __auto_hangup(), __dahdi_exception(), __find_callno(), __get_from_jb(), __iax2_poke_noanswer(), __reload(), __send_lagrq(), __send_ping(), __unload_module(), _unload_module(), acf_channel_read(), acf_jabberreceive_read(), acl_change_stasis_cb(), action_dahdishowchannels(), 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(), analog_ss_thread(), announce_thread(), answer_exec_run(), app_exec(), append_mailbox_mapping(), ast_ari_remove_handler(), ast_atomic_fetchadd_int_slow(), ast_begin_shutdown(), ast_cancel_shutdown(), ast_cli_netstats(), ast_cli_perms_init(), ast_context_unlockmacro(), ast_db_del(), ast_db_deltree(), ast_db_gettree(), ast_db_put(), ast_dial_join(), ast_dns_get_nameservers(), ast_dns_resolve(), ast_dnsmgr_changed(), ast_get_enum(), ast_iax2_new(), ast_merge_contexts_and_delete(), ast_module_reload(), ast_monitor_start(), ast_random(), ast_replace_sigchld(), ast_rtp_destroy(), ast_rtp_stop(), 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_synchronous(), 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(), attempt_transfer(), auth_reject(), authenticate_reply(), auto_hangup(), blr_ebl(), blr_txt(), bridge_agent_hold_deferred_create(), build_device(), build_reply_digest(), cache_get_callno_locked(), caldav_load_calendar(), can_safely_quit(), cb_events(), cdr_detach(), cdr_enable_batch_mode(), cdr_handler(), cdr_submit_batch(), channel_to_session(), check_unloading(), cl_dequeue_chan(), cl_queue_chan(), cli_tps_ping(), close_client(), close_mailbox(), close_rtp_connection(), close_udptl_connection(), 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_channels_data_provider_get(), 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_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(), 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_endpoint(), destroy_monitor_audiohook(), destroy_pgsql(), destroy_session(), destroy_table(), device_state_cb(), dial_trunk(), dispatch_exec_sync(), dispatch_message(), dns_synchronous_resolve_callback(), dnsmgr_refresh(), dnsmgr_shutdown(), 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(), 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(), get_chan_by_ast_name(), get_lock(), get_unused_callno(), gethostbyname_r(), handle_capabilities_res_message(), 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_misdn_show_channel(), handle_cli_misdn_show_channels(), handle_cli_mobile_cusd(), handle_cli_mobile_rfcomm(), handle_cli_mobile_show_devices(), 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_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(), headset_send_ring(), iax2_call(), iax2_do_register(), iax2_fixup(), iax2_hangup(), iax2_indicate(), iax2_key_rotate(), 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(), json_mem_unlock(), key_main_page(), key_select_extension(), ldap_loadentry(), leave_voicemail(), load_config(), load_module(), lock_broker(), 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(), 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(), notify_daemon(), 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(), play_message(), play_message_by_id_helper(), play_sound_helper(), presence_state_cb(), private_enum_init(), prune_gateways(), pthread_timer_open(), pvt_destructor(), 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(), release_chan(), release_chan_early(), release_table(), reload(), reload_config(), reload_followme(), reload_module(), replace_callno(), reqprep(), require_mysql(), require_pgsql(), resolution_thread(), restart_monitor(), restart_pktc_thread(), retrans_pkt(), run_station(), save_to_folder(), sched_run(), sched_thread_destroy(), schedule_calendar_event(), scheduled_destroy(), sco_accept(), send_client(), send_command_locked(), send_lagrq(), send_ping(), 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_outbound_publish_client_destroy(), 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_video(), softmix_bridge_write_voice(), softmix_mixing_loop(), softmix_mixing_thread(), softmix_poke_thread(), spandsp_fax_cli_show_stats(), speech_background(), sqlite_log(), start_network_thread(), start_rtp(), stop_mixmonitor_full(), stop_poll_thread(), store_pgsql(), stun_monitor_request(), stun_stop_monitor(), submit_scheduled_batch(), submit_unscheduled_batch(), sync_task(), syslog_log(), 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(), update2_ldap(), update2_pgsql(), update_ldap(), update_pgsql(), update_registry(), user_event_hook_cb(), user_event_wait_for_events(), vm_execmain(), vm_instructions_en(), vm_instructions_ja(), wait_for_resolution(), worker_start(), write_cdr(), write_cel(), writefile(), and xmpp_pak_message().

#define AST_PTHREADT_NULL   (pthread_t) -1

Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 66 of file lock.h.

Referenced by __allocate_taskprocessor(), __ast_manager_event_multichan(), __ast_rwlock_unlock(), __sip_reliable_xmit(), __unload_module(), _unload_module(), action_waitevent(), actual_load_config(), add_notify(), ast_autoservice_start(), ast_autoservice_stop(), ast_devstate_changed_literal(), ast_dial_create(), ast_dial_join(), ast_localtime_wakeup_monitor(), ast_log_full(), ast_safe_fork(), ast_sched_start_thread(), ast_taskprocessor_execute(), ast_tcptls_server_start(), ast_tcptls_server_stop(), ast_xmpp_client_disconnect(), 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(), console_verboser(), dahdi_restart(), default_listener_pvt_alloc(), default_listener_shutdown(), dnsmgr_shutdown(), do_reload(), finalize_batch_mode(), generic_http_callback(), get_input(), handle_call_outgoing(), init_pvt(), keepalive_global_loaded(), load_module(), mbl_load_device(), meetme_menu_admin_extended(), moh_class_destructor(), monitor_sig_flags(), network_thread(), notify_daemon(), ooh323c_stop_call_thread(), ooh323c_stop_stack_thread(), process_clearcache(), process_precache(), 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(), 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().

#define AST_PTHREADT_STOP   (pthread_t) -2

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

Definition at line 559 of file lock.h.

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

Definition at line 560 of file lock.h.

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

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

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

wrapper for ast_rwlock_init with tracking disabled

Returns:
0 on success, non zero for error
Since:
1.6.1

Definition at line 204 of file lock.h.

#define AST_RWLOCK_INIT_VALUE   { __AST_RWLOCK_INIT_VALUE, NULL, 1 }

Definition at line 98 of file lock.h.

#define AST_RWLOCK_INIT_VALUE_NOTRACKING   { __AST_RWLOCK_INIT_VALUE, NULL, 0 }

Definition at line 99 of file lock.h.

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

Definition at line 208 of file lock.h.

Referenced by action_messagesend(), 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_hashtab_start_traversal(), 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_payload_code(), ast_rtp_codecs_payload_formats(), ast_rtp_codecs_payloads_copy(), 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(), codec_to_index(), corosync_ping(), corosync_show_config(), cpg_confchg_cb(), cpg_deliver_cb(), find_table(), get_active_pvt(), get_general_options(), get_subscription(), handle_msg_cb(), handle_show_globals(), has_destination_cb(), index2codec(), manager_log(), msg_q_cb(), msg_send_exec(), pbx_builtin_getvar_helper(), and pbx_retrieve_variable().

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

Definition at line 212 of file lock.h.

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

Definition at line 213 of file lock.h.

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

Definition at line 210 of file lock.h.

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

Definition at line 211 of file lock.h.

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

Definition at line 207 of file lock.h.

Referenced by action_messagesend(), add_codec2index(), add_static_payload(), 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_hashtab_destroy(), ast_hashtab_end_traversal(), ast_hashtab_get_stats(), ast_hashtab_insert_immediate(), ast_hashtab_insert_safe(), 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_payload_code(), 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_set_framing(), ast_rtp_engine_unload_format(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), ast_str_retrieve_variable(), ast_unlock_context(), ast_unlock_contexts(), cleanup_module(), codec_to_index(), corosync_ping(), corosync_show_config(), cpg_confchg_cb(), cpg_deliver_cb(), destroy_pvts(), destroy_table(), get_active_pvt(), get_general_options(), get_or_create_subscription(), get_subscription(), handle_msg_cb(), handle_show_globals(), has_destination_cb(), index2codec(), load_config(), load_general_config(), 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(), pbx_retrieve_variable(), rtp_engine_shutdown(), set_active(), set_general_options(), set_next_mime_type(), and translate_shutdown().

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

#define CHANNEL_DEADLOCK_AVOIDANCE ( chan   ) 

Value:

ast_channel_unlock(chan); \
   usleep(1); \
   ast_channel_lock(chan);

Definition at line 490 of file lock.h.

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

#define DEADLOCK_AVOIDANCE ( lock   ) 

#define DLA_LOCK ( lock   )     ast_mutex_lock(lock)

Definition at line 508 of file lock.h.

Referenced by dahdi_handle_event().

#define DLA_UNLOCK ( lock   )     ast_mutex_unlock(lock)

Definition at line 506 of file lock.h.

Referenced by dahdi_handle_event().

#define gethostbyname   __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__

#define pthread_cond_broadcast   use_ast_cond_broadcast_instead_of_pthread_cond_broadcast

Definition at line 649 of file lock.h.

Referenced by __ast_cond_broadcast().

#define pthread_cond_destroy   use_ast_cond_destroy_instead_of_pthread_cond_destroy

Definition at line 647 of file lock.h.

Referenced by __ast_cond_destroy().

#define pthread_cond_init   use_ast_cond_init_instead_of_pthread_cond_init

Definition at line 646 of file lock.h.

Referenced by __ast_cond_init().

#define pthread_cond_signal   use_ast_cond_signal_instead_of_pthread_cond_signal

Definition at line 648 of file lock.h.

Referenced by __ast_cond_signal().

#define pthread_cond_t   use_ast_cond_t_instead_of_pthread_cond_t

Definition at line 639 of file lock.h.

#define pthread_cond_timedwait   use_ast_cond_timedwait_instead_of_pthread_cond_timedwait

Definition at line 651 of file lock.h.

Referenced by __ast_cond_timedwait().

#define pthread_cond_wait   use_ast_cond_wait_instead_of_pthread_cond_wait

Definition at line 650 of file lock.h.

Referenced by __ast_cond_wait().

#define pthread_create   __use_ast_pthread_create_instead__

Definition at line 658 of file lock.h.

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

#define pthread_mutex_destroy   use_ast_mutex_destroy_instead_of_pthread_mutex_destroy

Definition at line 645 of file lock.h.

Referenced by __ast_pthread_mutex_destroy(), ast_spinlock_destroy(), and stack_destroy().

#define pthread_mutex_init   use_ast_mutex_init_instead_of_pthread_mutex_init

#define PTHREAD_MUTEX_INIT_VALUE   PTHREAD_MUTEX_INITIALIZER

Definition at line 79 of file lock.h.

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

Definition at line 620 of file lock.h.

Referenced by app_control_register_rule(), app_control_unregister_rule(), app_deactivate(), app_is_active(), app_is_finished(), app_send(), app_shutdown(), app_subscribe_bridge(), app_subscribe_channel(), app_subscribe_endpoint(), app_update(), apply_menu_to_user(), ast_cdr_fork(), ast_endpoint_snapshot_create(), 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(), bridge_after_cb(), bridge_candidate_process(), 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(), control_add_channel_to_bridge(), find_route(), generic_mute_unmute_helper(), get_wait_bridge_wrapper(), 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(), recording_set_state(), remove_stasis_subscriptions(), session_register_app(), session_shutdown(), sip_outbound_publish_callback(), sip_publish_client_service_queue(), stasis_app_bridge_moh_channel(), stasis_app_control_record(), stasis_app_get_bridge(), stasis_app_playback_get_state(), stasis_app_playback_operation(), stasis_app_recording_operation(), stasis_subscription_is_done(), stasis_subscription_is_subscribed(), stasis_subscription_join(), stasis_topic_pool_get_topic(), subscription_invoke(), threadpool_active_thread_idle(), threadpool_idle_thread_dead(), threadpool_tps_emptied(), threadpool_tps_task_pushed(), threadpool_zombie_thread_dead(), topic_add_subscription(), topic_remove_subscription(), and unsubscribe().

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

scoped lock specialization for ao2 read locks.

Definition at line 625 of file lock.h.

Referenced by bucket_file_wizard_retrieve(), and bucket_wizard_retrieve().

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

scoped lock specialization for ao2 write locks.

Definition at line 630 of file lock.h.

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

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

#define SCOPED_LOCK ( varname,
lock,
lockfunc,
unlockfunc   )     RAII_VAR(typeof((lock)), varname, ({lockfunc((lock)); (lock); }), unlockfunc)

Scoped Locks.

Scoped locks provide a way to use RAII locks. In other words, declaration of a scoped lock will automatically define and lock the lock. When the lock goes out of scope, it will automatically be unlocked.

 int some_function(struct ast_channel *chan)
 {
     SCOPED_LOCK(lock, chan, ast_channel_lock, ast_channel_unlock);

     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:
varname The unique name to give to the scoped lock. You are not likely to reference this outside of the SCOPED_LOCK invocation.
lock The variable to lock. This can be anything that can be passed to a locking or unlocking function.
lockfunc The function to call to lock the lock
unlockfunc The function to call to unlock the lock

Definition at line 599 of file lock.h.

Referenced by add_headers_to_message(), add_subscription(), add_supplements(), app_event_source_find(), app_event_sources_to_json(), ast_bridge_basic_set_flags(), ast_bridge_transfer_attended(), ast_bridge_transfer_blind(), ast_channel_get_manager_vars(), ast_sip_dialog_get_endpoint(), ast_sip_dialog_set_endpoint(), ast_sip_dialog_set_serializer(), ast_sip_format_endpoint_ami(), ast_sip_identify_endpoint(), ast_sip_pubsub_unregister_body_generator(), ast_sip_pubsub_unregister_body_supplement(), ast_sip_register_endpoint_identifier_with_name(), ast_sip_register_event_publisher_handler(), ast_sip_register_supplement(), ast_sip_session_register_supplement(), ast_sip_session_unregister_supplement(), ast_sip_unregister_endpoint_identifier(), ast_sip_unregister_event_publisher_handler(), ast_sip_unregister_publish_handler(), ast_sip_unregister_subscription_handler(), ast_sip_unregister_supplement(), AST_TEST_DEFINE(), bridge_basic_change_personality(), cdr_enable_batch_mode(), cli_show_endpoint_identifiers(), complete_bridge_participant(), find_body_generator_type_subtype(), find_pub_handler(), find_sub_handler_for_event_name(), for_each_subscription(), get_sip_pvt_from_replaces(), handle_request_invite(), internal_sip_register_endpoint_formatter(), internal_sip_unregister_endpoint_formatter(), publish_add_handler(), remove_hooks_on_personality_change(), remove_subscription(), stasis_app_register_event_source(), stasis_app_unregister_event_source(), and sub_add_handler().

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

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

scoped lock specialization for read locks

Definition at line 610 of file lock.h.

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

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

scoped lock specialization for write locks

Definition at line 615 of file lock.h.

Referenced by ast_clear_mixmonitor_methods(), and ast_set_mixmonitor_methods().


Typedef Documentation

typedef pthread_cond_t ast_cond_t

Definition at line 151 of file lock.h.

typedef struct ast_mutex_info ast_mutex_t

Definition at line 147 of file lock.h.

typedef struct ast_rwlock_info ast_rwlock_t

Definition at line 149 of file lock.h.


Function Documentation

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

Definition at line 511 of file lock.c.

References pthread_cond_broadcast.

00513 {
00514    return pthread_cond_broadcast(cond);
00515 }

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

Definition at line 517 of file lock.c.

References pthread_cond_destroy.

00519 {
00520    return pthread_cond_destroy(cond);
00521 }

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

References pthread_cond_init.

00501 {
00502    return pthread_cond_init(cond, cond_attr);
00503 }

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

Definition at line 505 of file lock.c.

References pthread_cond_signal.

00507 {
00508    return pthread_cond_signal(cond);
00509 }

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

References ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_cond_timedwait, pthread_mutex_t, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

00617 {
00618    int res;
00619 
00620 #ifdef DEBUG_THREADS
00621    struct ast_lock_track *lt = NULL;
00622    struct ast_lock_track lt_orig;
00623    int canlog = t->tracking && strcmp(filename, "logger.c");
00624 
00625 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00626    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00627       __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
00628                filename, lineno, func, mutex_name);
00629       DO_THREAD_CRASH;
00630       return EINVAL;
00631    }
00632 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00633 
00634    if (t->tracking) {
00635       lt = ast_get_reentrancy(&t->track);
00636    }
00637 
00638    if (lt) {
00639       ast_reentrancy_lock(lt);
00640       if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
00641          __ast_mutex_logger("%s line %d (%s): attempted wait using mutex '%s' without owning it!\n",
00642                   filename, lineno, func, mutex_name);
00643          __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
00644                   lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
00645 #ifdef HAVE_BKTR
00646          __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00647 #endif
00648          DO_THREAD_CRASH;
00649       } else if (lt->reentrancy <= 0) {
00650          __ast_mutex_logger("%s line %d (%s): attempted wait using an unlocked mutex '%s'\n",
00651                   filename, lineno, func, mutex_name);
00652          DO_THREAD_CRASH;
00653       }
00654 
00655       /* Waiting on a condition completely suspends a recursive mutex,
00656        * even if it's been recursively locked multiple times. Make a
00657        * copy of the lock tracking, and reset reentrancy to zero */
00658       lt_orig = *lt;
00659       lt->reentrancy = 0;
00660       ast_reentrancy_unlock(lt);
00661 
00662       ast_suspend_lock_info(t);
00663    }
00664 #endif /* DEBUG_THREADS */
00665 
00666    res = pthread_cond_timedwait(cond, &t->mutex, abstime);
00667 
00668 #ifdef DEBUG_THREADS
00669    if (res && (res != ETIMEDOUT)) {
00670       __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
00671                filename, lineno, func, strerror(res));
00672       DO_THREAD_CRASH;
00673    } else if (lt) {
00674       restore_lock_tracking(lt, &lt_orig);
00675       ast_restore_lock_info(t);
00676    }
00677 #endif /* DEBUG_THREADS */
00678 
00679    return res;
00680 }

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

References ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_cond_wait, pthread_mutex_t, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

00549 {
00550    int res;
00551 
00552 #ifdef DEBUG_THREADS
00553    struct ast_lock_track *lt = NULL;
00554    struct ast_lock_track lt_orig;
00555    int canlog = t->tracking && strcmp(filename, "logger.c");
00556 
00557 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00558    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00559       __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
00560                filename, lineno, func, mutex_name);
00561       DO_THREAD_CRASH;
00562       return EINVAL;
00563    }
00564 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00565 
00566    if (t->tracking) {
00567       lt = ast_get_reentrancy(&t->track);
00568    }
00569 
00570    if (lt) {
00571       ast_reentrancy_lock(lt);
00572       if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
00573          __ast_mutex_logger("%s line %d (%s): attempted wait using mutex '%s' without owning it!\n",
00574                   filename, lineno, func, mutex_name);
00575          __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
00576                   lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
00577 #ifdef HAVE_BKTR
00578          __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00579 #endif
00580          DO_THREAD_CRASH;
00581       } else if (lt->reentrancy <= 0) {
00582          __ast_mutex_logger("%s line %d (%s): attempted wait using an unlocked mutex '%s'\n",
00583                   filename, lineno, func, mutex_name);
00584          DO_THREAD_CRASH;
00585       }
00586 
00587       /* Waiting on a condition completely suspends a recursive mutex,
00588        * even if it's been recursively locked multiple times. Make a
00589        * copy of the lock tracking, and reset reentrancy to zero */
00590       lt_orig = *lt;
00591       lt->reentrancy = 0;
00592       ast_reentrancy_unlock(lt);
00593 
00594       ast_suspend_lock_info(t);
00595    }
00596 #endif /* DEBUG_THREADS */
00597 
00598    res = pthread_cond_wait(cond, &t->mutex);
00599 
00600 #ifdef DEBUG_THREADS
00601    if (res) {
00602       __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
00603                filename, lineno, func, strerror(res));
00604       DO_THREAD_CRASH;
00605    } else if (lt) {
00606       restore_lock_tracking(lt, &lt_orig);
00607       ast_restore_lock_info(t);
00608    }
00609 #endif /* DEBUG_THREADS */
00610 
00611    return res;
00612 }

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

Definition at line 155 of file lock.c.

References ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, pthread_mutex_destroy, pthread_mutex_t, pthread_mutex_trylock, pthread_mutex_unlock, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

00157 {
00158    int res;
00159 
00160 #ifdef DEBUG_THREADS
00161    struct ast_lock_track *lt = t->track;
00162    int canlog = t->tracking && strcmp(filename, "logger.c");
00163 
00164 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00165    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00166       /* Don't try to uninitialize an uninitialized mutex
00167        * This may have no effect on linux
00168        * but it always generates a core on *BSD when
00169        * linked with libpthread.
00170        * This is not an error condition if the mutex is created on the fly.
00171        */
00172       __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n",
00173                filename, lineno, func, mutex_name);
00174       DO_THREAD_CRASH;
00175       res = EINVAL;
00176       goto lt_cleanup;
00177    }
00178 #endif
00179 
00180    res = pthread_mutex_trylock(&t->mutex);
00181    switch (res) {
00182    case 0:
00183       pthread_mutex_unlock(&t->mutex);
00184       break;
00185    case EINVAL:
00186       __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",
00187               filename, lineno, func, mutex_name);
00188       break;
00189    case EBUSY:
00190       __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",
00191                filename, lineno, func, mutex_name);
00192       if (lt) {
00193          ast_reentrancy_lock(lt);
00194          __ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",
00195                 lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
00196 #ifdef HAVE_BKTR
00197          __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00198 #endif
00199          ast_reentrancy_unlock(lt);
00200       }
00201       break;
00202    }
00203 #endif /* DEBUG_THREADS */
00204 
00205    res = pthread_mutex_destroy(&t->mutex);
00206 
00207 #ifdef DEBUG_THREADS
00208    if (res) {
00209       __ast_mutex_logger("%s line %d (%s): Error destroying mutex %s: %s\n",
00210                filename, lineno, func, mutex_name, strerror(res));
00211    }
00212 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00213 lt_cleanup:
00214 #endif
00215    if (lt) {
00216       ast_reentrancy_lock(lt);
00217       lt->file[0] = filename;
00218       lt->lineno[0] = lineno;
00219       lt->func[0] = func;
00220       lt->reentrancy = 0;
00221       lt->thread[0] = 0;
00222 #ifdef HAVE_BKTR
00223       memset(&lt->backtrace[0], 0, sizeof(lt->backtrace[0]));
00224 #endif
00225       ast_reentrancy_unlock(lt);
00226       delete_reentrancy_cs(&t->track);
00227    }
00228 #endif /* DEBUG_THREADS */
00229 
00230    return res;
00231 }

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

References AST_MUTEX_KIND, ast_mutex_info::mutex, NULL, pthread_mutex_init, pthread_mutex_t, ast_mutex_info::track, and ast_mutex_info::tracking.

00127 {
00128    int res;
00129    pthread_mutexattr_t  attr;
00130 
00131 #ifdef DEBUG_THREADS
00132 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00133    if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00134       int canlog = tracking && strcmp(filename, "logger.c");
00135 
00136       __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is already initialized.\n",
00137                filename, lineno, func, mutex_name);
00138       DO_THREAD_CRASH;
00139       return EBUSY;
00140    }
00141 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00142 
00143    t->track = NULL;
00144    t->tracking = tracking;
00145 #endif /* DEBUG_THREADS */
00146 
00147    pthread_mutexattr_init(&attr);
00148    pthread_mutexattr_settype(&attr, AST_MUTEX_KIND);
00149    res = pthread_mutex_init(&t->mutex, &attr);
00150    pthread_mutexattr_destroy(&attr);
00151 
00152    return res;
00153 }

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

Definition at line 233 of file lock.c.

References ast_bt_get_addresses, ast_mark(), AST_MAX_REENTRANCY, AST_MUTEX, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_mutex_lock, pthread_mutex_trylock, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

Referenced by __ao2_lock().

00235 {
00236    int res;
00237 
00238 #ifdef DEBUG_THREADS
00239    struct ast_lock_track *lt = NULL;
00240    int canlog = t->tracking && strcmp(filename, "logger.c");
00241 #ifdef HAVE_BKTR
00242    struct ast_bt *bt = NULL;
00243 #endif
00244 
00245    if (t->tracking) {
00246       lt = ast_get_reentrancy(&t->track);
00247    }
00248 
00249    if (lt) {
00250 #ifdef HAVE_BKTR
00251       struct ast_bt tmp;
00252 
00253       /* The implementation of backtrace() may have its own locks.
00254        * Capture the backtrace outside of the reentrancy lock to
00255        * avoid deadlocks. See ASTERISK-22455. */
00256       ast_bt_get_addresses(&tmp);
00257 
00258       ast_reentrancy_lock(lt);
00259       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00260          lt->backtrace[lt->reentrancy] = tmp;
00261          bt = &lt->backtrace[lt->reentrancy];
00262       }
00263       ast_reentrancy_unlock(lt);
00264 
00265       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
00266 #else
00267       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
00268 #endif
00269    }
00270 #endif /* DEBUG_THREADS */
00271 
00272 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
00273    {
00274       time_t seconds = time(NULL);
00275       time_t wait_time, reported_wait = 0;
00276       do {
00277 #ifdef   HAVE_MTX_PROFILE
00278          ast_mark(mtx_prof, 1);
00279 #endif
00280          res = pthread_mutex_trylock(&t->mutex);
00281 #ifdef   HAVE_MTX_PROFILE
00282          ast_mark(mtx_prof, 0);
00283 #endif
00284          if (res == EBUSY) {
00285             wait_time = time(NULL) - seconds;
00286             if (wait_time > reported_wait && (wait_time % 5) == 0) {
00287                __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
00288                         filename, lineno, func, (int) wait_time, mutex_name);
00289                ast_reentrancy_lock(lt);
00290 #ifdef HAVE_BKTR
00291                __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
00292 #endif
00293                __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
00294                         lt->file[ROFFSET], lt->lineno[ROFFSET],
00295                         lt->func[ROFFSET], mutex_name);
00296 #ifdef HAVE_BKTR
00297                __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00298 #endif
00299                ast_reentrancy_unlock(lt);
00300                reported_wait = wait_time;
00301             }
00302             usleep(200);
00303          }
00304       } while (res == EBUSY);
00305    }
00306 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
00307 #ifdef   HAVE_MTX_PROFILE
00308    ast_mark(mtx_prof, 1);
00309    res = pthread_mutex_trylock(&t->mutex);
00310    ast_mark(mtx_prof, 0);
00311    if (res)
00312 #endif
00313    res = pthread_mutex_lock(&t->mutex);
00314 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
00315 
00316 #ifdef DEBUG_THREADS
00317    if (lt && !res) {
00318       ast_reentrancy_lock(lt);
00319       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00320          lt->file[lt->reentrancy] = filename;
00321          lt->lineno[lt->reentrancy] = lineno;
00322          lt->func[lt->reentrancy] = func;
00323          lt->thread[lt->reentrancy] = pthread_self();
00324          lt->reentrancy++;
00325       } else {
00326          __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
00327                         filename, lineno, func, mutex_name);
00328       }
00329       ast_reentrancy_unlock(lt);
00330       ast_mark_lock_acquired(t);
00331    } else if (lt) {
00332 #ifdef HAVE_BKTR
00333       if (lt->reentrancy) {
00334          ast_reentrancy_lock(lt);
00335          bt = &lt->backtrace[lt->reentrancy-1];
00336          ast_reentrancy_unlock(lt);
00337       } else {
00338          bt = NULL;
00339       }
00340       ast_remove_lock_info(t, bt);
00341 #else
00342       ast_remove_lock_info(t);
00343 #endif
00344    }
00345    if (res) {
00346       __ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",
00347                filename, lineno, func, strerror(res));
00348       DO_THREAD_CRASH;
00349    }
00350 #endif /* DEBUG_THREADS */
00351 
00352    return res;
00353 }

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

Definition at line 355 of file lock.c.

References ast_bt_get_addresses, ast_mark_lock_failed(), AST_MAX_REENTRANCY, AST_MUTEX, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_mutex_trylock, ast_lock_track::reentrancy, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

Referenced by __ao2_trylock().

00357 {
00358    int res;
00359 
00360 #ifdef DEBUG_THREADS
00361    struct ast_lock_track *lt = NULL;
00362    int canlog = t->tracking && strcmp(filename, "logger.c");
00363 #ifdef HAVE_BKTR
00364    struct ast_bt *bt = NULL;
00365 #endif
00366 
00367    if (t->tracking) {
00368       lt = ast_get_reentrancy(&t->track);
00369    }
00370 
00371    if (lt) {
00372 #ifdef HAVE_BKTR
00373       struct ast_bt tmp;
00374 
00375       /* The implementation of backtrace() may have its own locks.
00376        * Capture the backtrace outside of the reentrancy lock to
00377        * avoid deadlocks. See ASTERISK-22455. */
00378       ast_bt_get_addresses(&tmp);
00379 
00380       ast_reentrancy_lock(lt);
00381       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00382          lt->backtrace[lt->reentrancy] = tmp;
00383          bt = &lt->backtrace[lt->reentrancy];
00384       }
00385       ast_reentrancy_unlock(lt);
00386 
00387       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
00388 #else
00389       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
00390 #endif
00391    }
00392 #endif /* DEBUG_THREADS */
00393 
00394    res = pthread_mutex_trylock(&t->mutex);
00395 
00396 #ifdef DEBUG_THREADS
00397    if (lt && !res) {
00398       ast_reentrancy_lock(lt);
00399       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00400          lt->file[lt->reentrancy] = filename;
00401          lt->lineno[lt->reentrancy] = lineno;
00402          lt->func[lt->reentrancy] = func;
00403          lt->thread[lt->reentrancy] = pthread_self();
00404          lt->reentrancy++;
00405       } else {
00406          __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
00407                   filename, lineno, func, mutex_name);
00408       }
00409       ast_reentrancy_unlock(lt);
00410       ast_mark_lock_acquired(t);
00411    } else if (lt) {
00412       ast_mark_lock_failed(t);
00413    }
00414 #endif /* DEBUG_THREADS */
00415 
00416    return res;
00417 }

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

Definition at line 419 of file lock.c.

References AST_MAX_REENTRANCY, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, NULL, pthread_mutex_t, pthread_mutex_unlock, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

Referenced by __ao2_unlock().

00421 {
00422    int res;
00423 
00424 #ifdef DEBUG_THREADS
00425    struct ast_lock_track *lt = NULL;
00426    int canlog = t->tracking && strcmp(filename, "logger.c");
00427 #ifdef HAVE_BKTR
00428    struct ast_bt *bt = NULL;
00429 #endif
00430 
00431 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00432    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00433       __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
00434                filename, lineno, func, mutex_name);
00435       DO_THREAD_CRASH;
00436       return EINVAL;
00437    }
00438 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00439 
00440    if (t->tracking) {
00441       lt = ast_get_reentrancy(&t->track);
00442    }
00443 
00444    if (lt) {
00445       ast_reentrancy_lock(lt);
00446       if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
00447          __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
00448                   filename, lineno, func, mutex_name);
00449          __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
00450                   lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
00451 #ifdef HAVE_BKTR
00452          __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00453 #endif
00454          DO_THREAD_CRASH;
00455       }
00456 
00457       if (--lt->reentrancy < 0) {
00458          __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
00459                   filename, lineno, func, mutex_name);
00460          lt->reentrancy = 0;
00461       }
00462 
00463       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00464          lt->file[lt->reentrancy] = NULL;
00465          lt->lineno[lt->reentrancy] = 0;
00466          lt->func[lt->reentrancy] = NULL;
00467          lt->thread[lt->reentrancy] = 0;
00468       }
00469 
00470 #ifdef HAVE_BKTR
00471       if (lt->reentrancy) {
00472          bt = &lt->backtrace[lt->reentrancy - 1];
00473       }
00474 #endif
00475       ast_reentrancy_unlock(lt);
00476 
00477 #ifdef HAVE_BKTR
00478       ast_remove_lock_info(t, bt);
00479 #else
00480       ast_remove_lock_info(t);
00481 #endif
00482    }
00483 #endif /* DEBUG_THREADS */
00484 
00485    res = pthread_mutex_unlock(&t->mutex);
00486 
00487 #ifdef DEBUG_THREADS
00488    if (res) {
00489       __ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n",
00490                filename, lineno, func, strerror(res));
00491       DO_THREAD_CRASH;
00492    }
00493 #endif /* DEBUG_THREADS */
00494 
00495    return res;
00496 }

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

Definition at line 713 of file lock.c.

References __AST_RWLOCK_INIT_VALUE, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, ast_lock_track::reentrancy, ast_lock_track::thread, ast_rwlock_info::track, and ast_rwlock_info::tracking.

00714 {
00715    int res;
00716 
00717 #ifdef DEBUG_THREADS
00718    struct ast_lock_track *lt = t->track;
00719    int canlog = t->tracking && strcmp(filename, "logger.c");
00720 
00721 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00722    if (t->lock == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
00723       __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
00724                filename, lineno, func, rwlock_name);
00725       DO_THREAD_CRASH;
00726       res = EINVAL;
00727       goto lt_cleanup;
00728    }
00729 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00730 #endif /* DEBUG_THREADS */
00731 
00732    res = pthread_rwlock_destroy(&t->lock);
00733 
00734 #ifdef DEBUG_THREADS
00735    if (res) {
00736       __ast_mutex_logger("%s line %d (%s): Error destroying rwlock %s: %s\n",
00737             filename, lineno, func, rwlock_name, strerror(res));
00738    }
00739 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00740 lt_cleanup:
00741 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00742    if (lt) {
00743       ast_reentrancy_lock(lt);
00744       lt->file[0] = filename;
00745       lt->lineno[0] = lineno;
00746       lt->func[0] = func;
00747       lt->reentrancy = 0;
00748       lt->thread[0] = 0;
00749 #ifdef HAVE_BKTR
00750       memset(&lt->backtrace[0], 0, sizeof(lt->backtrace[0]));
00751 #endif
00752       ast_reentrancy_unlock(lt);
00753       delete_reentrancy_cs(&t->track);
00754    }
00755 #endif /* DEBUG_THREADS */
00756 
00757    return res;
00758 }

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

References __AST_RWLOCK_INIT_VALUE, ast_rwlock_info::lock, NULL, ast_rwlock_info::track, and ast_rwlock_info::tracking.

00683 {
00684    int res;
00685    pthread_rwlockattr_t attr;
00686 
00687 #ifdef DEBUG_THREADS
00688 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00689    if (t->lock != ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
00690       int canlog = tracking && strcmp(filename, "logger.c");
00691 
00692       __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is already initialized.\n",
00693             filename, lineno, func, rwlock_name);
00694       DO_THREAD_CRASH;
00695       return EBUSY;
00696    }
00697 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00698 
00699    t->track = NULL;
00700    t->tracking = tracking;
00701 #endif /* DEBUG_THREADS */
00702 
00703    pthread_rwlockattr_init(&attr);
00704 #ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
00705    pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP);
00706 #endif
00707    res = pthread_rwlock_init(&t->lock, &attr);
00708    pthread_rwlockattr_destroy(&attr);
00709 
00710    return res;
00711 }

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

Definition at line 840 of file lock.c.

References ast_bt_get_addresses, AST_MAX_REENTRANCY, AST_RDLOCK, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, NULL, ast_lock_track::reentrancy, ast_lock_track::thread, ast_rwlock_info::track, and ast_rwlock_info::tracking.

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

00841 {
00842    int res;
00843 
00844 #ifdef DEBUG_THREADS
00845    struct ast_lock_track *lt = NULL;
00846    int canlog = t->tracking && strcmp(filename, "logger.c");
00847 #ifdef HAVE_BKTR
00848    struct ast_bt *bt = NULL;
00849 #endif
00850 
00851    if (t->tracking) {
00852       lt = ast_get_reentrancy(&t->track);
00853    }
00854 
00855    if (lt) {
00856 #ifdef HAVE_BKTR
00857       struct ast_bt tmp;
00858 
00859       /* The implementation of backtrace() may have its own locks.
00860        * Capture the backtrace outside of the reentrancy lock to
00861        * avoid deadlocks. See ASTERISK-22455. */
00862       ast_bt_get_addresses(&tmp);
00863 
00864       ast_reentrancy_lock(lt);
00865       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00866          lt->backtrace[lt->reentrancy] = tmp;
00867          bt = &lt->backtrace[lt->reentrancy];
00868       }
00869       ast_reentrancy_unlock(lt);
00870 
00871       ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
00872 #else
00873       ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
00874 #endif
00875    }
00876 #endif /* DEBUG_THREADS */
00877 
00878 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
00879    {
00880       time_t seconds = time(NULL);
00881       time_t wait_time, reported_wait = 0;
00882       do {
00883          res = pthread_rwlock_tryrdlock(&t->lock);
00884          if (res == EBUSY) {
00885             wait_time = time(NULL) - seconds;
00886             if (wait_time > reported_wait && (wait_time % 5) == 0) {
00887                __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for readlock '%s'?\n",
00888                   filename, line, func, (int)wait_time, name);
00889                if (lt) {
00890                   ast_reentrancy_lock(lt);
00891 #ifdef HAVE_BKTR
00892                   __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
00893 #endif
00894                   __ast_mutex_logger("%s line %d (%s): '%s' was locked  here.\n",
00895                         lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
00896                         lt->func[lt->reentrancy-1], name);
00897 #ifdef HAVE_BKTR
00898                   __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
00899 #endif
00900                   ast_reentrancy_unlock(lt);
00901                }
00902                reported_wait = wait_time;
00903             }
00904             usleep(200);
00905          }
00906       } while (res == EBUSY);
00907    }
00908 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
00909    res = pthread_rwlock_rdlock(&t->lock);
00910 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
00911 
00912 #ifdef DEBUG_THREADS
00913    if (!res && lt) {
00914       ast_reentrancy_lock(lt);
00915       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00916          lt->file[lt->reentrancy] = filename;
00917          lt->lineno[lt->reentrancy] = line;
00918          lt->func[lt->reentrancy] = func;
00919          lt->thread[lt->reentrancy] = pthread_self();
00920          lt->reentrancy++;
00921       }
00922       ast_reentrancy_unlock(lt);
00923       ast_mark_lock_acquired(t);
00924    } else if (lt) {
00925 #ifdef HAVE_BKTR
00926       if (lt->reentrancy) {
00927          ast_reentrancy_lock(lt);
00928          bt = &lt->backtrace[lt->reentrancy-1];
00929          ast_reentrancy_unlock(lt);
00930       } else {
00931          bt = NULL;
00932       }
00933       ast_remove_lock_info(t, bt);
00934 #else
00935       ast_remove_lock_info(t);
00936 #endif
00937    }
00938 
00939    if (res) {
00940       __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
00941             filename, line, func, strerror(res));
00942       DO_THREAD_CRASH;
00943    }
00944 #endif /* DEBUG_THREADS */
00945 
00946    return res;
00947 }

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

References ast_bt_get_addresses, AST_MAX_REENTRANCY, ast_tvnow(), AST_WRLOCK, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, NULL, ast_lock_track::reentrancy, ast_lock_track::thread, ast_rwlock_info::track, and ast_rwlock_info::tracking.

01059 {
01060    int res;
01061 
01062 #ifdef DEBUG_THREADS
01063    struct ast_lock_track *lt = NULL;
01064    int canlog = t->tracking && strcmp(filename, "logger.c");
01065 #ifdef HAVE_BKTR
01066    struct ast_bt *bt = NULL;
01067 #endif
01068 
01069    if (t->tracking) {
01070       lt = ast_get_reentrancy(&t->track);
01071    }
01072 
01073    if (lt) {
01074 #ifdef HAVE_BKTR
01075       struct ast_bt tmp;
01076 
01077       /* The implementation of backtrace() may have its own locks.
01078        * Capture the backtrace outside of the reentrancy lock to
01079        * avoid deadlocks. See ASTERISK-22455. */
01080       ast_bt_get_addresses(&tmp);
01081 
01082       ast_reentrancy_lock(lt);
01083       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01084          lt->backtrace[lt->reentrancy] = tmp;
01085          bt = &lt->backtrace[lt->reentrancy];
01086       }
01087       ast_reentrancy_unlock(lt);
01088 
01089       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
01090 #else
01091       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
01092 #endif
01093    }
01094 #endif /* DEBUG_THREADS */
01095 
01096 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
01097    res = pthread_rwlock_timedrdlock(&t->lock, abs_timeout);
01098 #else
01099    do {
01100       struct timeval _now;
01101       for (;;) {
01102          if (!(res = pthread_rwlock_tryrdlock(&t->lock))) {
01103             break;
01104          }
01105          _now = ast_tvnow();
01106          if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
01107             break;
01108          }
01109          usleep(1);
01110       }
01111    } while (0);
01112 #endif
01113 
01114 #ifdef DEBUG_THREADS
01115    if (!res && lt) {
01116       ast_reentrancy_lock(lt);
01117       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01118          lt->file[lt->reentrancy] = filename;
01119          lt->lineno[lt->reentrancy] = line;
01120          lt->func[lt->reentrancy] = func;
01121          lt->thread[lt->reentrancy] = pthread_self();
01122          lt->reentrancy++;
01123       }
01124       ast_reentrancy_unlock(lt);
01125       ast_mark_lock_acquired(t);
01126    } else if (lt) {
01127 #ifdef HAVE_BKTR
01128       if (lt->reentrancy) {
01129          ast_reentrancy_lock(lt);
01130          bt = &lt->backtrace[lt->reentrancy-1];
01131          ast_reentrancy_unlock(lt);
01132       } else {
01133          bt = NULL;
01134       }
01135       ast_remove_lock_info(t, bt);
01136 #else
01137       ast_remove_lock_info(t);
01138 #endif
01139    }
01140    if (res) {
01141       __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
01142             filename, line, func, strerror(res));
01143       DO_THREAD_CRASH;
01144    }
01145 #endif /* DEBUG_THREADS */
01146 
01147    return res;
01148 }

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

References ast_bt_get_addresses, AST_MAX_REENTRANCY, ast_tvnow(), AST_WRLOCK, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, NULL, ast_lock_track::reentrancy, ast_lock_track::thread, ast_rwlock_info::track, and ast_rwlock_info::tracking.

01152 {
01153    int res;
01154 
01155 #ifdef DEBUG_THREADS
01156    struct ast_lock_track *lt = NULL;
01157    int canlog = t->tracking && strcmp(filename, "logger.c");
01158 #ifdef HAVE_BKTR
01159    struct ast_bt *bt = NULL;
01160 #endif
01161 
01162    if (t->tracking) {
01163       lt = ast_get_reentrancy(&t->track);
01164    }
01165 
01166    if (lt) {
01167 #ifdef HAVE_BKTR
01168       struct ast_bt tmp;
01169 
01170       /* The implementation of backtrace() may have its own locks.
01171        * Capture the backtrace outside of the reentrancy lock to
01172        * avoid deadlocks. See ASTERISK-22455. */
01173       ast_bt_get_addresses(&tmp);
01174 
01175       ast_reentrancy_lock(lt);
01176       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01177          lt->backtrace[lt->reentrancy] = tmp;
01178          bt = &lt->backtrace[lt->reentrancy];
01179       }
01180       ast_reentrancy_unlock(lt);
01181 
01182       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
01183 #else
01184       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
01185 #endif
01186    }
01187 #endif /* DEBUG_THREADS */
01188 
01189 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
01190    res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout);
01191 #else
01192    do {
01193       struct timeval _now;
01194       for (;;) {
01195          if (!(res = pthread_rwlock_trywrlock(&t->lock))) {
01196             break;
01197          }
01198          _now = ast_tvnow();
01199          if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
01200             break;
01201          }
01202          usleep(1);
01203       }
01204    } while (0);
01205 #endif
01206 
01207 #ifdef DEBUG_THREADS
01208    if (!res && lt) {
01209       ast_reentrancy_lock(lt);
01210       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01211          lt->file[lt->reentrancy] = filename;
01212          lt->lineno[lt->reentrancy] = line;
01213          lt->func[lt->reentrancy] = func;
01214          lt->thread[lt->reentrancy] = pthread_self();
01215          lt->reentrancy++;
01216       }
01217       ast_reentrancy_unlock(lt);
01218       ast_mark_lock_acquired(t);
01219    } else if (lt) {
01220 #ifdef HAVE_BKTR
01221       if (lt->reentrancy) {
01222          ast_reentrancy_lock(lt);
01223          bt = &lt->backtrace[lt->reentrancy-1];
01224          ast_reentrancy_unlock(lt);
01225       } else {
01226          bt = NULL;
01227       }
01228       ast_remove_lock_info(t, bt);
01229 #else
01230       ast_remove_lock_info(t);
01231 #endif
01232    }
01233    if (res) {
01234       __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
01235             filename, line, func, strerror(res));
01236       DO_THREAD_CRASH;
01237    }
01238 #endif /* DEBUG_THREADS */
01239 
01240    return res;
01241 }

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

Definition at line 1243 of file lock.c.

References ast_bt_get_addresses, ast_mark_lock_failed(), AST_MAX_REENTRANCY, AST_RDLOCK, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, NULL, ast_lock_track::reentrancy, ast_lock_track::thread, ast_rwlock_info::track, and ast_rwlock_info::tracking.

Referenced by __ao2_trylock().

01244 {
01245    int res;
01246 
01247 #ifdef DEBUG_THREADS
01248    struct ast_lock_track *lt = NULL;
01249 #ifdef HAVE_BKTR
01250    struct ast_bt *bt = NULL;
01251 #endif
01252 
01253    if (t->tracking) {
01254       lt = ast_get_reentrancy(&t->track);
01255    }
01256 
01257    if (lt) {
01258 #ifdef HAVE_BKTR
01259       struct ast_bt tmp;
01260 
01261       /* The implementation of backtrace() may have its own locks.
01262        * Capture the backtrace outside of the reentrancy lock to
01263        * avoid deadlocks. See ASTERISK-22455. */
01264       ast_bt_get_addresses(&tmp);
01265 
01266       ast_reentrancy_lock(lt);
01267       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01268          lt->backtrace[lt->reentrancy] = tmp;
01269          bt = &lt->backtrace[lt->reentrancy];
01270       }
01271       ast_reentrancy_unlock(lt);
01272 
01273       ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
01274 #else
01275       ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
01276 #endif
01277    }
01278 #endif /* DEBUG_THREADS */
01279 
01280    res = pthread_rwlock_tryrdlock(&t->lock);
01281 
01282 #ifdef DEBUG_THREADS
01283    if (!res && lt) {
01284       ast_reentrancy_lock(lt);
01285       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01286          lt->file[lt->reentrancy] = filename;
01287          lt->lineno[lt->reentrancy] = line;
01288          lt->func[lt->reentrancy] = func;
01289          lt->thread[lt->reentrancy] = pthread_self();
01290          lt->reentrancy++;
01291       }
01292       ast_reentrancy_unlock(lt);
01293       ast_mark_lock_acquired(t);
01294    } else if (lt) {
01295       ast_mark_lock_failed(t);
01296    }
01297 #endif /* DEBUG_THREADS */
01298 
01299    return res;
01300 }

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

Definition at line 1302 of file lock.c.

References ast_bt_get_addresses, ast_mark_lock_failed(), AST_MAX_REENTRANCY, AST_WRLOCK, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, NULL, ast_lock_track::reentrancy, ast_lock_track::thread, ast_rwlock_info::track, and ast_rwlock_info::tracking.

Referenced by __ao2_trylock().

01303 {
01304    int res;
01305 
01306 #ifdef DEBUG_THREADS
01307    struct ast_lock_track *lt = NULL;
01308 #ifdef HAVE_BKTR
01309    struct ast_bt *bt = NULL;
01310 #endif
01311 
01312    if (t->tracking) {
01313       lt = ast_get_reentrancy(&t->track);
01314    }
01315 
01316    if (lt) {
01317 #ifdef HAVE_BKTR
01318       struct ast_bt tmp;
01319 
01320       /* The implementation of backtrace() may have its own locks.
01321        * Capture the backtrace outside of the reentrancy lock to
01322        * avoid deadlocks. See ASTERISK-22455. */
01323       ast_bt_get_addresses(&tmp);
01324 
01325       ast_reentrancy_lock(lt);
01326       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01327          lt->backtrace[lt->reentrancy] = tmp;
01328          bt = &lt->backtrace[lt->reentrancy];
01329       }
01330       ast_reentrancy_unlock(lt);
01331 
01332       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
01333 #else
01334       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
01335 #endif
01336    }
01337 #endif /* DEBUG_THREADS */
01338 
01339    res = pthread_rwlock_trywrlock(&t->lock);
01340 
01341 #ifdef DEBUG_THREADS
01342    if (!res && lt) {
01343       ast_reentrancy_lock(lt);
01344       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01345          lt->file[lt->reentrancy] = filename;
01346          lt->lineno[lt->reentrancy] = line;
01347          lt->func[lt->reentrancy] = func;
01348          lt->thread[lt->reentrancy] = pthread_self();
01349          lt->reentrancy++;
01350       }
01351       ast_reentrancy_unlock(lt);
01352       ast_mark_lock_acquired(t);
01353    } else if (lt) {
01354       ast_mark_lock_failed(t);
01355    }
01356 #endif /* DEBUG_THREADS */
01357 
01358    return res;
01359 }

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

Definition at line 760 of file lock.c.

References __AST_RWLOCK_INIT_VALUE, AST_PTHREADT_NULL, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, NULL, ast_lock_track::reentrancy, ast_lock_track::thread, ast_rwlock_info::track, and ast_rwlock_info::tracking.

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

00761 {
00762    int res;
00763 
00764 #ifdef DEBUG_THREADS
00765    struct ast_lock_track *lt = NULL;
00766    int canlog = t->tracking && strcmp(filename, "logger.c");
00767 #ifdef HAVE_BKTR
00768    struct ast_bt *bt = NULL;
00769 #endif
00770    int lock_found = 0;
00771 
00772 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00773    if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
00774       __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
00775                filename, line, func, name);
00776       DO_THREAD_CRASH;
00777       return EINVAL;
00778    }
00779 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00780 
00781    if (t->tracking) {
00782       lt = ast_get_reentrancy(&t->track);
00783    }
00784 
00785    if (lt) {
00786       ast_reentrancy_lock(lt);
00787       if (lt->reentrancy) {
00788          int i;
00789          pthread_t self = pthread_self();
00790          for (i = lt->reentrancy - 1; i >= 0; --i) {
00791             if (lt->thread[i] == self) {
00792                lock_found = 1;
00793                if (i != lt->reentrancy - 1) {
00794                   lt->file[i] = lt->file[lt->reentrancy - 1];
00795                   lt->lineno[i] = lt->lineno[lt->reentrancy - 1];
00796                   lt->func[i] = lt->func[lt->reentrancy - 1];
00797                   lt->thread[i] = lt->thread[lt->reentrancy - 1];
00798                }
00799 #ifdef HAVE_BKTR
00800                bt = &lt->backtrace[i];
00801 #endif
00802                lt->file[lt->reentrancy - 1] = NULL;
00803                lt->lineno[lt->reentrancy - 1] = 0;
00804                lt->func[lt->reentrancy - 1] = NULL;
00805                lt->thread[lt->reentrancy - 1] = AST_PTHREADT_NULL;
00806                break;
00807             }
00808          }
00809       }
00810 
00811       if (lock_found && --lt->reentrancy < 0) {
00812          __ast_mutex_logger("%s line %d (%s): rwlock '%s' freed more times than we've locked!\n",
00813                filename, line, func, name);
00814          lt->reentrancy = 0;
00815       }
00816 
00817       ast_reentrancy_unlock(lt);
00818 
00819 #ifdef HAVE_BKTR
00820       ast_remove_lock_info(t, bt);
00821 #else
00822       ast_remove_lock_info(t);
00823 #endif
00824    }
00825 #endif /* DEBUG_THREADS */
00826 
00827    res = pthread_rwlock_unlock(&t->lock);
00828 
00829 #ifdef DEBUG_THREADS
00830    if (res) {
00831       __ast_mutex_logger("%s line %d (%s): Error releasing rwlock: %s\n",
00832             filename, line, func, strerror(res));
00833       DO_THREAD_CRASH;
00834    }
00835 #endif /* DEBUG_THREADS */
00836 
00837    return res;
00838 }

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

Definition at line 949 of file lock.c.

References ast_bt_get_addresses, AST_MAX_REENTRANCY, AST_WRLOCK, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, NULL, ast_lock_track::reentrancy, ast_lock_track::thread, ast_rwlock_info::track, and ast_rwlock_info::tracking.

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

00950 {
00951    int res;
00952 
00953 #ifdef DEBUG_THREADS
00954    struct ast_lock_track *lt = NULL;
00955    int canlog = t->tracking && strcmp(filename, "logger.c");
00956 #ifdef HAVE_BKTR
00957    struct ast_bt *bt = NULL;
00958 #endif
00959 
00960    if (t->tracking) {
00961       lt = ast_get_reentrancy(&t->track);
00962    }
00963 
00964    if (lt) {
00965 #ifdef HAVE_BKTR
00966       struct ast_bt tmp;
00967 
00968       /* The implementation of backtrace() may have its own locks.
00969        * Capture the backtrace outside of the reentrancy lock to
00970        * avoid deadlocks. See ASTERISK-22455. */
00971       ast_bt_get_addresses(&tmp);
00972 
00973       ast_reentrancy_lock(lt);
00974       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00975          lt->backtrace[lt->reentrancy] = tmp;
00976          bt = &lt->backtrace[lt->reentrancy];
00977       }
00978       ast_reentrancy_unlock(lt);
00979 
00980       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
00981 #else
00982       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
00983 #endif
00984    }
00985 #endif /* DEBUG_THREADS */
00986 
00987 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
00988    {
00989       time_t seconds = time(NULL);
00990       time_t wait_time, reported_wait = 0;
00991       do {
00992          res = pthread_rwlock_trywrlock(&t->lock);
00993          if (res == EBUSY) {
00994             wait_time = time(NULL) - seconds;
00995             if (wait_time > reported_wait && (wait_time % 5) == 0) {
00996                __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for writelock '%s'?\n",
00997                   filename, line, func, (int)wait_time, name);
00998                if (lt) {
00999                   ast_reentrancy_lock(lt);
01000 #ifdef HAVE_BKTR
01001                   __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
01002 #endif
01003                   __ast_mutex_logger("%s line %d (%s): '%s' was locked  here.\n",
01004                         lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
01005                         lt->func[lt->reentrancy-1], name);
01006 #ifdef HAVE_BKTR
01007                   __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
01008 #endif
01009                   ast_reentrancy_unlock(lt);
01010                }
01011                reported_wait = wait_time;
01012             }
01013             usleep(200);
01014          }
01015       } while (res == EBUSY);
01016    }
01017 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
01018    res = pthread_rwlock_wrlock(&t->lock);
01019 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
01020 
01021 #ifdef DEBUG_THREADS
01022    if (!res && lt) {
01023       ast_reentrancy_lock(lt);
01024       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01025          lt->file[lt->reentrancy] = filename;
01026          lt->lineno[lt->reentrancy] = line;
01027          lt->func[lt->reentrancy] = func;
01028          lt->thread[lt->reentrancy] = pthread_self();
01029          lt->reentrancy++;
01030       }
01031       ast_reentrancy_unlock(lt);
01032       ast_mark_lock_acquired(t);
01033    } else if (lt) {
01034 #ifdef HAVE_BKTR
01035       if (lt->reentrancy) {
01036          ast_reentrancy_lock(lt);
01037          bt = &lt->backtrace[lt->reentrancy-1];
01038          ast_reentrancy_unlock(lt);
01039       } else {
01040          bt = NULL;
01041       }
01042       ast_remove_lock_info(t, bt);
01043 #else
01044       ast_remove_lock_info(t);
01045 #endif
01046    }
01047    if (res) {
01048       __ast_mutex_logger("%s line %d (%s): Error obtaining write lock: %s\n",
01049             filename, line, func, strerror(res));
01050       DO_THREAD_CRASH;
01051    }
01052 #endif /* DEBUG_THREADS */
01053 
01054    return res;
01055 }

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 751 of file lock.h.

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

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 725 of file lock.h.

Referenced by __ao2_lock(), __ao2_trylock(), __ao2_unlock(), __ast_channel_alloc_ap(), __ast_channel_internal_alloc(), __ast_manager_event_multichan(), __ast_module_ref(), __ast_module_unref(), __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), __container_unlink_node_debug(), _ast_odbc_request_obj2(), _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_cli_command_full(), ast_create_callid(), ast_dial_append(), 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(), container_destruct_debug(), create_new_sip_etag(), dahdi_destroy(), dahdi_request(), dahdi_translate(), destroy_session(), 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_ao2_link(), internal_ao2_ref(), 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(), temp_peer(), try_merge_optimize_out(), try_swap_optimize_out(), update_stats(), and worker_thread_alloc().

00733 {

int ast_atomic_fetchadd_int_slow ( volatile int *  p,
int  v 
)

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

References ast_mutex_lock, ast_mutex_unlock, and fetchadd_m.

02260 {
02261    int ret;
02262    ast_mutex_lock(&fetchadd_m);
02263    ret = *p;
02264    *p += v;
02265    ast_mutex_unlock(&fetchadd_m);
02266    return ret;
02267 }


Generated on Thu Apr 16 06:31:49 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6