Mon Mar 12 2012 21:40:49

Asterisk developer's documentation


lock.h File Reference

Asterisk locking-related definitions: More...

#include <pthread.h>
#include <time.h>
#include <sys/param.h>
#include <execinfo.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
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   PTHREAD_RWLOCK_INITIALIZER
#define ast_cond_broadcast(cond)   __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define ast_cond_destroy(cond)   __ast_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define ast_cond_init(cond, attr)   __ast_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr)
#define ast_cond_signal(cond)   __ast_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define ast_cond_timedwait(cond, mutex, time)   __ast_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time)
#define ast_cond_wait(cond, mutex)   __ast_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex)
#define AST_LOCK_TRACK_INIT_VALUE   { { NULL }, { 0 }, 0, { NULL }, { 0 }, {{{ 0 }}}, PTHREAD_MUTEX_INIT_VALUE }
#define AST_MAX_REENTRANCY   10
#define AST_MUTEX_DEFINE_STATIC(mutex)   __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE, 1)
#define AST_MUTEX_DEFINE_STATIC_NOTRACKING(mutex)   __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE_NOTRACKING, 0)
#define ast_mutex_destroy(a)   __ast_pthread_mutex_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
#define ast_mutex_init(pmutex)   __ast_pthread_mutex_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex)
#define ast_mutex_init_notracking(pmutex)   __ast_pthread_mutex_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex)
#define AST_MUTEX_INIT_VALUE   { PTHREAD_MUTEX_INIT_VALUE, NULL, 1 }
#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_NP
#define ast_mutex_lock(a)   __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
#define ast_mutex_trylock(a)   __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
#define ast_mutex_unlock(a)   __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
#define AST_PTHREADT_NULL   (pthread_t) -1
#define AST_PTHREADT_STOP   (pthread_t) -2
#define AST_RWLOCK_DEFINE_STATIC(rwlock)   __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE, 1)
#define AST_RWLOCK_DEFINE_STATIC_NOTRACKING(rwlock)   __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE_NOTRACKING, 0)
#define ast_rwlock_destroy(rwlock)   __ast_rwlock_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
#define ast_rwlock_init(rwlock)   __ast_rwlock_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
 wrapper for rwlock with tracking enabled
#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_RECURSIVE_MUTEX_INITIALIZER_NP
#define pthread_mutex_lock   use_ast_mutex_lock_instead_of_pthread_mutex_lock
#define pthread_mutex_t   use_ast_mutex_t_instead_of_pthread_mutex_t
#define pthread_mutex_trylock   use_ast_mutex_trylock_instead_of_pthread_mutex_trylock
#define pthread_mutex_unlock   use_ast_mutex_unlock_instead_of_pthread_mutex_unlock
#define ROFFSET   ((lt->reentrancy > 0) ? (lt->reentrancy-1) : 0)

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:

  • ast_mutext_t, ast_rwlock_t and related functions;
  • atomic arithmetic instructions;
  • wrappers for channel locking.

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

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

Definition at line 546 of file lock.h.

#define ast_cond_broadcast (   cond)    __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define AST_LOCK_TRACK_INIT_VALUE   { { NULL }, { 0 }, 0, { NULL }, { 0 }, {{{ 0 }}}, PTHREAD_MUTEX_INIT_VALUE }

Definition at line 89 of file lock.h.

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

Definition at line 526 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 527 of file lock.h.

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

Definition at line 153 of file lock.h.

#define AST_MUTEX_INIT_VALUE   { PTHREAD_MUTEX_INIT_VALUE, NULL, 1 }

Definition at line 94 of file lock.h.

#define AST_MUTEX_INIT_VALUE_NOTRACKING   { PTHREAD_MUTEX_INIT_VALUE, NULL, 0 }

Definition at line 95 of file lock.h.

#define AST_MUTEX_INITIALIZER   __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__

Definition at line 568 of file lock.h.

#define AST_MUTEX_KIND   PTHREAD_MUTEX_RECURSIVE_NP

Definition at line 76 of file lock.h.

Referenced by __ast_pthread_mutex_init(), and dummy_start().

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

Definition at line 155 of file lock.h.

Referenced by __attempt_transmit(), __auth_reject(), __auto_congest(), __auto_hangup(), __find_callno(), __get_from_jb(), __iax2_poke_noanswer(), __oh323_new(), __reload(), __send_lagrq(), __send_ping(), __unload_module(), _sip_tcp_helper_thread(), _unload_module(), acf_channel_read(), acf_jabberreceive_read(), action_agents(), action_dahdishowchannels(), add_notify(), agent_ack_sleep(), agent_call(), agent_cleanup(), agent_cont_sleep(), agent_devicestate(), agent_digit_begin(), agent_digit_end(), agent_fixup(), agent_hangup(), agent_indicate(), agent_lock_owner(), agent_logoff(), agent_read(), agent_request(), agent_sendhtml(), agent_sendtext(), agent_write(), agents_data_provider_get(), agents_show(), agents_show_online(), aji_handle_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(), aoro2_obj_cb(), app_exec(), append_mailbox_mapping(), ast_atomic_fetchadd_int_slow(), ast_bridge_change_state(), ast_bridge_merge(), ast_cdr_detach(), ast_cdr_engine_init(), ast_cdr_submit_batch(), ast_cel_report_event(), ast_cli_netstats(), ast_config_engine_deregister(), ast_config_engine_register(), ast_context_lockmacro(), ast_db_del(), ast_db_get(), ast_db_put(), ast_dial_join(), ast_dnsmgr_changed(), ast_features_reload(), ast_get_enum(), ast_iax2_new(), ast_merge_contexts_and_delete(), ast_monitor_start(), ast_random(), ast_rdlock_contexts(), ast_replace_sigchld(), ast_sched_add_variable(), ast_sched_del(), ast_sched_dump(), ast_sched_report(), ast_sched_runq(), ast_sched_thread_add(), ast_sched_thread_add_variable(), ast_sched_thread_destroy(), ast_sched_thread_poke(), ast_sched_wait(), ast_sched_when(), ast_search_dns(), ast_smdi_md_message_push(), ast_smdi_md_message_putback(), ast_smdi_mwi_message_push(), ast_smdi_mwi_message_putback(), ast_taskprocessor_push(), ast_unreplace_sigchld(), ast_wrlock_contexts(), auth_reject(), authenticate_reply(), auto_hangup(), blr_ebl(), blr_txt(), bridge_channel_join_multithreaded(), bridge_channel_join_singlethreaded(), bridge_hangup(), bridge_write(), build_device(), build_profile(), build_reply_digest(), caldav_load_calendar(), cb_events(), cdr_handler(), check_availability(), check_beep(), cl_dequeue_chan(), cl_queue_chan(), clear_config_maps(), cli_tps_ping(), close_client(), conf_free(), conf_run(), config_device(), config_handler(), config_line(), config_load(), config_pgsql(), console_answer(), console_autoanswer(), console_dial(), console_hangup(), console_sendtext(), create_channel_name(), create_client(), csv_log(), custom_log(), dahdi_accept_r2_call_exec(), dahdi_answer(), dahdi_bridge(), dahdi_call(), dahdi_cc_callback(), dahdi_channels_data_provider_get(), dahdi_destroy_channel_bynum(), dahdi_digit_begin(), dahdi_digit_end(), dahdi_exception(), dahdi_fixup(), dahdi_func_read(), dahdi_func_write(), dahdi_handle_dtmf(), dahdi_hangup(), dahdi_indicate(), dahdi_pri_error(), dahdi_pri_message(), dahdi_r2_disconnect_call(), dahdi_r2_on_call_disconnect(), dahdi_r2_on_call_end(), dahdi_r2_on_call_init(), dahdi_r2_on_call_offered(), dahdi_r2_on_hardware_alarm(), dahdi_r2_on_line_blocked(), dahdi_r2_on_line_idle(), dahdi_r2_on_protocol_error(), dahdi_request(), dahdi_restart(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dahdi_softhangup_all(), dahdi_unlink(), dahdi_unlink_pri_pvt(), dahdi_unlink_ss7_pvt(), data_odbc_provider_handler(), db_sync_thread(), decrease_call_count(), defer_full_frame(), delete_users(), destroy_all_channels(), destroy_all_mailbox_mappings(), destroy_endpoint(), destroy_monitor_audiohook(), destroy_pgsql(), devstate_change_collector_cb(), dial_trunk(), dnsmgr_refresh(), do_cdr(), do_monitor(), do_refresh(), do_reload(), do_timing(), donodelog(), dp_lookup(), dump_cmd_queues(), dump_queue(), ewscal_load_calendar(), exchangecal_load_calendar(), find_call_locked(), find_chan_by_bc(), find_channel(), find_command(), find_engine(), find_hold_active_call(), find_hold_call(), find_hold_call_l3(), find_idle_thread(), find_subchannel_and_lock(), find_subchannel_by_name(), find_table(), find_tpeer(), function_remote(), get_chan_by_ast(), get_chan_by_ast_name(), get_input(), get_lock(), gtalk_alloc(), gtalk_answer(), gtalk_digit_begin(), gtalk_digit_end(), gtalk_fixup(), gtalk_get_rtp_peer(), gtalk_hangup(), gtalk_newcall(), gtalk_read(), gtalk_ringing_ack(), gtalk_set_rtp_peer(), gtalk_show_channels(), gtalk_write(), h323_reload(), handle_capabilities_res_message(), handle_cli_core_show_config_mappings(), 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_odbc_show(), handle_cli_osp_show(), handle_deferred_full_frames(), handle_init_event(), handle_mfcr2_call_files(), handle_mfcr2_set_blocked(), handle_mfcr2_set_debug(), handle_mfcr2_set_idle(), handle_mfcr2_show_channels(), handle_mgcp_audit_endpoint(), handle_mgcp_show_endpoints(), handle_modlist(), handle_pri_debug(), handle_pri_service_generic(), handle_pri_set_debug_file(), handle_pri_show_debug(), handle_register_message(), handle_request(), handle_request_do(), handle_speechrecognize(), handle_ss7_block_cic(), handle_ss7_block_linkset(), handle_ss7_unblock_cic(), handle_ss7_unblock_linkset(), handle_statechange(), hidthread(), iax2_answer(), iax2_bridge(), 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(), inotify_daemon(), jingle_alloc(), jingle_answer(), jingle_digit(), jingle_fixup(), jingle_get_rtp_peer(), jingle_hangup(), jingle_newcall(), jingle_read(), jingle_set_rtp_peer(), jingle_show_channels(), jingle_write(), key_main_page(), key_select_extension(), leave_voicemail(), load_config(), load_module(), load_rpt_vars(), lock_both(), lock_broker(), lock_msg_q(), log_jitterstats(), login_exec(), lua_free_extensions(), lua_load_extensions(), lua_reload_extensions(), make_trunk(), mansession_lock(), mb_poll_thread(), 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(), 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(), node_lookup(), odbc_obj_connect(), odbc_obj_disconnect(), oh323_alloc(), oh323_answer(), oh323_call(), oh323_destroy(), oh323_digit_begin(), oh323_digit_end(), oh323_fixup(), oh323_get_rtp_peer(), oh323_hangup(), oh323_indicate(), oh323_read(), oh323_request(), oh323_simulate_dtmf_end(), oh323_update_info(), oh323_write(), osp_create_provider(), osp_create_transaction(), osp_get_provider(), osp_unload(), parse_config(), parsing(), peer_destructor(), pgsql_log(), phone_request(), play_sound_file(), pri_dchannel(), pri_ss_thread(), private_enum_init(), process_db_keys(), prune_gateways(), pthread_timer_open(), pvt_destructor(), queue_ringing_trunk(), radio_tune(), 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(), register_verify(), registry_authrequest(), release_chan(), release_chan_early(), reload(), reload_config(), reload_followme(), require_pgsql(), restart_monitor(), restart_pktc_thread(), retrans_pkt(), rpt_master(), rpt_tele_thread(), run_devstate_collector(), run_station(), save_to_folder(), sched_context_destroy(), sched_run(), schedule_calendar_event(), scheduled_destroy(), send_client(), send_command_locked(), send_lagrq(), send_ping(), send_request(), send_retransmit(), set_config(), set_pvt_defaults(), setup_dahdi_int(), sig_pri_attempt_transfer(), sig_pri_available(), sig_pri_cc_agent_callee_available(), sig_pri_cc_agent_destructor(), sig_pri_cc_agent_init(), sig_pri_cc_agent_party_b_free(), sig_pri_cc_agent_req_rsp(), sig_pri_cc_agent_status_req(), sig_pri_cc_agent_stop_ringing(), sig_pri_cc_monitor_instance_destroy(), sig_pri_cc_monitor_req_cc(), sig_pri_cc_monitor_status_rsp(), sig_pri_cc_monitor_suspend(), sig_pri_cc_monitor_unsuspend(), sig_pri_cli_show_channels(), sig_pri_cli_show_span(), sig_pri_lock_owner(), sig_pri_new_ast_channel(), sig_pri_send_mwi_indication(), sig_ss7_available(), sig_ss7_cli_show_channels(), sig_ss7_lock_owner(), sig_ss7_request(), signal_condition(), sip_reload(), sip_show_settings(), sip_tcptls_write(), skinny_get_rtp_peer(), skinny_hangup(), skinny_read(), skinny_req_parse(), skinny_write(), sla_check_reload(), 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(), smart_bridge_operation(), socket_process(), softmix_bridge_poke(), softmix_bridge_thread(), softmix_bridge_write(), spandsp_fax_cli_show_stats(), speech_background(), sqlite_log(), ss7_linkset(), ss7_start_call(), ssl_lock(), start_rtp(), statpost(), stop_mixmonitor_exec(), stop_poll_thread(), store_config(), store_pgsql(), stun_monitor_request(), stun_stop_monitor(), submit_unscheduled_batch(), syslog_log(), tds_load_module(), tds_log(), tds_unload_module(), timing_read(), tps_ping_handler(), tps_processing_function(), tps_taskprocessor_destroy(), tps_taskprocessor_pop(), transmit_frame(), transmit_response(), tune_write(), unistim_fixup(), unistim_hangup(), unistim_info(), unistim_new(), unistim_read(), unistim_register(), unistim_reload(), unistim_write(), unistimsock_read(), unload_module(), update2_ldap(), update2_pgsql(), update_ldap(), update_pgsql(), update_registry(), vm_execmain(), write_cdr(), and writefile().

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

Referenced by __attempt_transmit(), __auth_reject(), __auto_congest(), __auto_hangup(), __find_callno(), __get_from_jb(), __iax2_poke_noanswer(), __oh323_destroy(), __oh323_new(), __oh323_rtp_create(), __reload(), __send_lagrq(), __send_ping(), __unload_module(), _sip_tcp_helper_thread(), _unload_module(), acf_channel_read(), acf_jabberreceive_read(), action_agents(), action_dahdishowchannels(), add_notify(), agent_ack_sleep(), agent_call(), agent_cleanup(), agent_cont_sleep(), agent_devicestate(), agent_digit_begin(), agent_digit_end(), agent_fixup(), agent_hangup(), agent_indicate(), agent_lock_owner(), agent_logoff(), agent_read(), agent_request(), agent_sendhtml(), agent_sendtext(), agent_write(), agents_data_provider_get(), agents_show(), agents_show_online(), aji_handle_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_call(), answer_exec_run(), aoro2_obj_cb(), app_exec(), append_mailbox_mapping(), ast_atomic_fetchadd_int_slow(), ast_bridge_change_state(), ast_bridge_merge(), ast_cdr_detach(), ast_cdr_engine_init(), ast_cdr_submit_batch(), ast_cel_report_event(), ast_cli_netstats(), ast_cli_perms_init(), ast_config_engine_deregister(), ast_config_engine_register(), ast_context_unlockmacro(), ast_db_del(), ast_db_get(), ast_db_put(), ast_dial_join(), ast_dnsmgr_changed(), ast_features_reload(), ast_get_enum(), ast_iax2_new(), ast_merge_contexts_and_delete(), ast_module_reload(), ast_monitor_start(), ast_random(), ast_replace_sigchld(), ast_sched_add_variable(), ast_sched_del(), ast_sched_dump(), ast_sched_report(), ast_sched_runq(), ast_sched_thread_add(), ast_sched_thread_add_variable(), ast_sched_thread_destroy(), ast_sched_thread_poke(), ast_sched_wait(), ast_sched_when(), ast_search_dns(), ast_smdi_md_message_push(), ast_smdi_md_message_putback(), ast_smdi_mwi_message_push(), ast_smdi_mwi_message_putback(), ast_taskprocessor_push(), ast_unlock_contexts(), ast_unreplace_sigchld(), auth_reject(), authenticate_reply(), auto_hangup(), blr_ebl(), blr_txt(), bridge_channel_join_multithreaded(), bridge_channel_join_singlethreaded(), bridge_hangup(), bridge_queue_hangup(), bridge_write(), build_device(), build_profile(), build_reply_digest(), cache_get_callno_locked(), caldav_load_calendar(), cb_events(), cdr_handler(), chan_ringing(), check_availability(), check_beep(), cl_dequeue_chan(), cl_queue_chan(), cleanup_connection(), clear_config_maps(), cli_tps_ping(), close_client(), conf_free(), conf_run(), config_device(), config_handler(), config_line(), config_load(), config_pgsql(), connection_made(), console_answer(), console_autoanswer(), console_dial(), console_hangup(), console_sendtext(), create_channel_name(), create_client(), csv_log(), custom_log(), dahdi_accept_r2_call_exec(), dahdi_answer(), dahdi_bridge(), dahdi_call(), dahdi_cc_callback(), dahdi_channels_data_provider_get(), dahdi_destroy_channel_bynum(), dahdi_digit_begin(), dahdi_digit_end(), dahdi_exception(), dahdi_fixup(), dahdi_func_read(), dahdi_func_write(), dahdi_handle_dtmf(), dahdi_hangup(), dahdi_indicate(), dahdi_pri_error(), dahdi_pri_message(), dahdi_r2_disconnect_call(), dahdi_r2_on_call_disconnect(), dahdi_r2_on_call_end(), dahdi_r2_on_call_init(), dahdi_r2_on_call_offered(), dahdi_r2_on_hardware_alarm(), dahdi_r2_on_line_blocked(), dahdi_r2_on_line_idle(), dahdi_r2_on_protocol_error(), dahdi_read(), dahdi_request(), dahdi_restart(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dahdi_softhangup_all(), dahdi_unlink(), dahdi_unlink_pri_pvt(), dahdi_unlink_ss7_pvt(), data_odbc_provider_handler(), db_sync_thread(), decrease_call_count(), defer_full_frame(), delete_users(), destroy_all_channels(), destroy_all_mailbox_mappings(), destroy_endpoint(), destroy_monitor_audiohook(), destroy_pgsql(), devstate_change_collector_cb(), dial_trunk(), dnsmgr_refresh(), do_cdr(), do_monitor(), do_refresh(), do_reload(), do_timing(), donodelog(), dp_lookup(), dump_cmd_queues(), dump_queue(), ewscal_load_calendar(), exchangecal_load_calendar(), external_rtp_create(), find_cache(), find_call_locked(), find_chan_by_bc(), find_channel(), find_command(), find_engine(), find_hold_active_call(), find_hold_call(), find_hold_call_l3(), find_idle_thread(), find_subchannel_and_lock(), find_subchannel_by_name(), find_table(), function_remote(), get_chan_by_ast(), get_chan_by_ast_name(), get_input(), get_lock(), gtalk_alloc(), gtalk_answer(), gtalk_digit_begin(), gtalk_digit_end(), gtalk_fixup(), gtalk_get_rtp_peer(), gtalk_hangup(), gtalk_newcall(), gtalk_read(), gtalk_ringing_ack(), gtalk_set_rtp_peer(), gtalk_show_channels(), gtalk_write(), h323_reload(), handle_capabilities_res_message(), handle_cli_core_show_config_mappings(), 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_odbc_show(), handle_cli_osp_show(), handle_deferred_full_frames(), handle_init_event(), handle_mfcr2_call_files(), handle_mfcr2_set_blocked(), handle_mfcr2_set_debug(), handle_mfcr2_set_idle(), handle_mfcr2_show_channels(), handle_mgcp_audit_endpoint(), handle_mgcp_show_endpoints(), handle_modlist(), handle_pri_debug(), handle_pri_service_generic(), handle_pri_set_debug_file(), handle_pri_show_debug(), handle_register_message(), handle_request(), handle_request_do(), handle_speechrecognize(), handle_ss7_block_cic(), handle_ss7_block_linkset(), handle_ss7_unblock_cic(), handle_ss7_unblock_linkset(), handle_statechange(), hangup_connection(), hidthread(), iax2_answer(), iax2_bridge(), 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(), inotify_daemon(), jingle_alloc(), jingle_answer(), jingle_digit(), jingle_fixup(), jingle_get_rtp_peer(), jingle_hangup(), jingle_newcall(), jingle_read(), jingle_set_rtp_peer(), jingle_show_channels(), jingle_write(), key_main_page(), key_select_extension(), ldap_loadentry(), leave_voicemail(), load_config(), load_module(), load_rpt_vars(), lock_broker(), log_jitterstats(), login_exec(), lua_free_extensions(), lua_load_extensions(), lua_reload_extensions(), make_trunk(), mansession_unlock(), mb_poll_thread(), 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(), 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(), node_lookup(), odbc_obj_connect(), odbc_obj_disconnect(), oh323_alloc(), oh323_answer(), oh323_call(), oh323_destroy(), oh323_digit_begin(), oh323_digit_end(), oh323_fixup(), oh323_get_rtp_peer(), oh323_hangup(), oh323_indicate(), oh323_read(), oh323_request(), oh323_simulate_dtmf_end(), oh323_update_info(), oh323_write(), osp_create_provider(), osp_create_transaction(), osp_get_provider(), osp_unload(), parse_config(), parsing(), peer_destructor(), pgsql_log(), phone_request(), play_sound_file(), pri_dchannel(), pri_rel(), pri_ss_thread(), private_enum_init(), process_db_keys(), progress(), prune_gateways(), pthread_timer_open(), pvt_destructor(), queue_ringing_trunk(), radio_tune(), 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(), receive_digit(), recordthread(), refresh_list(), register_verify(), registry_authrequest(), release_chan(), release_chan_early(), reload(), reload_config(), reload_followme(), remote_hold(), require_pgsql(), restart_monitor(), restart_pktc_thread(), retrans_pkt(), rpt_master(), rpt_tele_thread(), run_devstate_collector(), run_station(), save_to_folder(), sched_context_destroy(), sched_run(), schedule_calendar_event(), scheduled_destroy(), send_client(), send_command_locked(), send_lagrq(), send_ping(), send_request(), send_retransmit(), set_config(), set_dtmf_payload(), set_local_capabilities(), set_peer_capabilities(), set_pvt_defaults(), setup_dahdi_int(), setup_rtp_connection(), sig_pri_attempt_transfer(), sig_pri_available(), sig_pri_cc_agent_callee_available(), sig_pri_cc_agent_destructor(), sig_pri_cc_agent_init(), sig_pri_cc_agent_party_b_free(), sig_pri_cc_agent_req_rsp(), sig_pri_cc_agent_status_req(), sig_pri_cc_agent_stop_ringing(), sig_pri_cc_monitor_instance_destroy(), sig_pri_cc_monitor_req_cc(), sig_pri_cc_monitor_status_rsp(), sig_pri_cc_monitor_suspend(), sig_pri_cc_monitor_unsuspend(), sig_pri_cli_show_channels(), sig_pri_cli_show_span(), sig_pri_lock_owner(), sig_pri_new_ast_channel(), sig_pri_send_mwi_indication(), sig_ss7_available(), sig_ss7_cli_show_channels(), sig_ss7_lock_owner(), sig_ss7_request(), signal_condition(), sip_reload(), sip_show_settings(), sip_tcptls_write(), skinny_get_rtp_peer(), skinny_hangup(), skinny_read(), skinny_req_parse(), skinny_write(), sla_check_reload(), 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(), smart_bridge_operation(), socket_process(), socket_process_meta(), softmix_bridge_poke(), softmix_bridge_thread(), softmix_bridge_write(), spandsp_fax_cli_show_stats(), speech_background(), sqlite_log(), ss7_linkset(), ss7_rel(), ss7_start_call(), ssl_lock(), start_rtp(), statpost(), stop_mixmonitor_exec(), stop_poll_thread(), store_config(), store_pgsql(), stun_monitor_request(), stun_stop_monitor(), submit_unscheduled_batch(), syslog_log(), tds_load_module(), tds_log(), tds_unload_module(), timing_read(), tps_ping_handler(), tps_processing_function(), tps_taskprocessor_destroy(), tps_taskprocessor_pop(), transmit_frame(), transmit_response(), tune_write(), unistim_fixup(), unistim_hangup(), unistim_info(), unistim_new(), unistim_read(), unistim_register(), unistim_reload(), unistim_write(), unistimsock_read(), unload_module(), unlock_both(), unlock_msg_q(), update2_ldap(), update2_pgsql(), update_ldap(), update_pgsql(), update_registry(), vm_execmain(), write_cdr(), and writefile().

#define AST_PTHREADT_NULL   (pthread_t) -1
#define AST_RWLOCK_DEFINE_STATIC (   rwlock)    __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE, 1)

Definition at line 549 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 550 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)

wrapper for rwlock with tracking enabled

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

Definition at line 190 of file lock.h.

Referenced by ast_context_find_or_create(), ast_data_init(), ast_hashtab_create(), ast_hashtab_dup(), ast_hashtab_initlock(), ast_heap_create(), and find_table().

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

#define AST_RWLOCK_INIT_VALUE   { __AST_RWLOCK_INIT_VALUE, NULL, 1 }

Definition at line 97 of file lock.h.

#define AST_RWLOCK_INIT_VALUE_NOTRACKING   { __AST_RWLOCK_INIT_VALUE, NULL, 0 }

Definition at line 98 of file lock.h.

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

Definition at line 205 of file lock.h.

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

Definition at line 206 of file lock.h.

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

Definition at line 203 of file lock.h.

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

Definition at line 204 of file lock.h.

#define CHANNEL_DEADLOCK_AVOIDANCE (   chan)
#define DLA_LOCK (   lock)    ast_mutex_lock(lock)

Definition at line 498 of file lock.h.

Referenced by dahdi_handle_event().

#define DLA_UNLOCK (   lock)    ast_mutex_unlock(lock)

Definition at line 496 of file lock.h.

Referenced by dahdi_handle_event().

#define gethostbyname   __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__

Definition at line 570 of file lock.h.

Referenced by connect_sphinx().

#define pthread_cond_broadcast   use_ast_cond_broadcast_instead_of_pthread_cond_broadcast

Definition at line 564 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 562 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 561 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 563 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 554 of file lock.h.

#define pthread_cond_timedwait   use_ast_cond_timedwait_instead_of_pthread_cond_timedwait

Definition at line 566 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 565 of file lock.h.

Referenced by __ast_cond_wait().

#define pthread_create   __use_ast_pthread_create_instead__

Definition at line 573 of file lock.h.

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

#define pthread_mutex_destroy   use_ast_mutex_destroy_instead_of_pthread_mutex_destroy

Definition at line 560 of file lock.h.

Referenced by __ast_pthread_mutex_destroy(), and stack_destroy().

#define pthread_mutex_init   use_ast_mutex_init_instead_of_pthread_mutex_init

Definition at line 559 of file lock.h.

Referenced by __ast_pthread_mutex_init(), dummy_start(), init_bc(), and stack_init().

#define PTHREAD_MUTEX_INIT_VALUE   PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP

Definition at line 75 of file lock.h.

#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 ROFFSET   ((lt->reentrancy > 0) ? (lt->reentrancy-1) : 0)

Typedef Documentation

typedef pthread_cond_t ast_cond_t

Definition at line 144 of file lock.h.

typedef struct ast_mutex_info ast_mutex_t

Definition at line 140 of file lock.h.

typedef struct ast_rwlock_info ast_rwlock_t

Definition at line 142 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 459 of file lock.c.

References pthread_cond_broadcast.

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

Definition at line 465 of file lock.c.

References pthread_cond_destroy.

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

References pthread_cond_init.

{
   return pthread_cond_init(cond, cond_attr);
}
int __ast_cond_signal ( const char *  filename,
int  lineno,
const char *  func,
const char *  cond_name,
ast_cond_t cond 
)

Definition at line 453 of file lock.c.

References pthread_cond_signal.

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

References __ast_pthread_mutex_init(), ast_bt_get_addresses(), AST_MAX_REENTRANCY, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, pthread_cond_timedwait, pthread_mutex_t, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
      __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
               filename, lineno, func, mutex_name);
      res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
      if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
         __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
                filename, lineno, func, mutex_name);
      }
      return res;
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
         __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
                  filename, lineno, func, mutex_name);
         __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
                  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
#ifdef HAVE_BKTR
         __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
#endif
         DO_THREAD_CRASH;
      }

      if (--lt->reentrancy < 0) {
         __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
                  filename, lineno, func, mutex_name);
         lt->reentrancy = 0;
      }

      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = NULL;
         lt->lineno[lt->reentrancy] = 0;
         lt->func[lt->reentrancy] = NULL;
         lt->thread[lt->reentrancy] = 0;
      }
#ifdef HAVE_BKTR
      if (lt->reentrancy) {
         bt = &lt->backtrace[lt->reentrancy - 1];
      }
#endif
      ast_reentrancy_unlock(lt);

#ifdef HAVE_BKTR
      ast_remove_lock_info(t, bt);
#else
      ast_remove_lock_info(t);
#endif
   }
#endif /* DEBUG_THREADS */

   res = pthread_cond_timedwait(cond, &t->mutex, abstime);

#ifdef DEBUG_THREADS
   if (res && (res != ETIMEDOUT)) {
      __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
               filename, lineno, func, strerror(res));
      DO_THREAD_CRASH;
   } else if (t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = lineno;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
#ifdef HAVE_BKTR
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
#endif
         lt->reentrancy++;
      } else {
         __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
                        filename, lineno, func, mutex_name);
      }
      ast_reentrancy_unlock(lt);

#ifdef HAVE_BKTR
      ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
#else
      ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
#endif
   }
#endif /* DEBUG_THREADS */

   return res;
}
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 471 of file lock.c.

References __ast_pthread_mutex_init(), ast_bt_get_addresses(), AST_MAX_REENTRANCY, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, pthread_cond_wait, pthread_mutex_t, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
      __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
               filename, lineno, func, mutex_name);
      res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
      if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
         __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
                filename, lineno, func, mutex_name);
      }
      return res;
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
         __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
                  filename, lineno, func, mutex_name);
         __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
                  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
#ifdef HAVE_BKTR
         __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
#endif
         DO_THREAD_CRASH;
      }

      if (--lt->reentrancy < 0) {
         __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
               filename, lineno, func, mutex_name);
         lt->reentrancy = 0;
      }

      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = NULL;
         lt->lineno[lt->reentrancy] = 0;
         lt->func[lt->reentrancy] = NULL;
         lt->thread[lt->reentrancy] = 0;
      }

#ifdef HAVE_BKTR
      if (lt->reentrancy) {
         bt = &lt->backtrace[lt->reentrancy - 1];
      }
#endif
      ast_reentrancy_unlock(lt);

#ifdef HAVE_BKTR
      ast_remove_lock_info(t, bt);
#else
      ast_remove_lock_info(t);
#endif
   }
#endif /* DEBUG_THREADS */

   res = pthread_cond_wait(cond, &t->mutex);

#ifdef DEBUG_THREADS
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
               filename, lineno, func, strerror(res));
      DO_THREAD_CRASH;
   } else if (t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = lineno;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
#ifdef HAVE_BKTR
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
#endif
         lt->reentrancy++;
      } else {
         __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
                        filename, lineno, func, mutex_name);
      }
      ast_reentrancy_unlock(lt);

#ifdef HAVE_BKTR
      ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
#else
      ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
#endif
   }
#endif /* DEBUG_THREADS */

   return res;
}
int __ast_pthread_mutex_destroy ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 78 of file lock.c.

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

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
      /* Don't try to uninitialize non initialized mutex
       * This may no effect on linux
       * And always ganerate core on *BSD with
       * linked libpthread
       * This not error condition if the mutex created on the fly.
       */
      __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n",
               filename, lineno, func, mutex_name);
      return 0;
   }
#endif

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   res = pthread_mutex_trylock(&t->mutex);
   switch (res) {
   case 0:
      pthread_mutex_unlock(&t->mutex);
      break;
   case EINVAL:
      __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",
              filename, lineno, func, mutex_name);
      break;
   case EBUSY:
      __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",
               filename, lineno, func, mutex_name);
      if (t->tracking) {
         ast_reentrancy_lock(lt);
         __ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",
                lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
#ifdef HAVE_BKTR
         __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
#endif
         ast_reentrancy_unlock(lt);
      }
      break;
   }
#endif /* DEBUG_THREADS */

   res = pthread_mutex_destroy(&t->mutex);

#ifdef DEBUG_THREADS
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error destroying mutex %s: %s\n",
               filename, lineno, func, mutex_name, strerror(res));
   }
   if (t->tracking) {
      ast_reentrancy_lock(lt);
      lt->file[0] = filename;
      lt->lineno[0] = lineno;
      lt->func[0] = func;
      lt->reentrancy = 0;
      lt->thread[0] = 0;
#ifdef HAVE_BKTR
      memset(&lt->backtrace[0], 0, sizeof(lt->backtrace[0]));
#endif
      ast_reentrancy_unlock(lt);
      delete_reentrancy_cs(&t->track);
   }
#endif /* DEBUG_THREADS */

   return res;
}
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 44 of file lock.c.

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

Referenced by __ast_cond_timedwait(), __ast_cond_wait(), __ast_pthread_mutex_lock(), __ast_pthread_mutex_trylock(), and __ast_pthread_mutex_unlock().

{
   int res;
   pthread_mutexattr_t  attr;

   t->track = NULL;
#ifdef DEBUG_THREADS
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
/*
      int canlog = strcmp(filename, "logger.c") & track;
      __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is already initialized.\n",
               filename, lineno, func, mutex_name);
      DO_THREAD_CRASH;
*/
      return 0;
   }

#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if ((t->tracking = tracking)) {
      ast_reentrancy_init(&t->track);
   }
#endif /* DEBUG_THREADS */

   pthread_mutexattr_init(&attr);
   pthread_mutexattr_settype(&attr, AST_MUTEX_KIND);

   res = pthread_mutex_init(&t->mutex, &attr);
   pthread_mutexattr_destroy(&attr);
   return res;
}
int __ast_pthread_mutex_lock ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 156 of file lock.c.

References __ast_pthread_mutex_init(), ast_bt_get_addresses(), ast_mark(), AST_MAX_REENTRANCY, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, pthread_mutex_lock, pthread_mutex_t, 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().

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
      /* Don't warn abount uninitialized mutex.
       * Simple try to initialize it.
       * May be not needed in linux system.
       */
      res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
      if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
         __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
                filename, lineno, func, mutex_name);
         return res;
      }
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
#ifdef HAVE_BKTR
      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);
      ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
#else
      ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
#endif
   }
#endif /* DEBUG_THREADS */

#if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
   {
      time_t seconds = time(NULL);
      time_t wait_time, reported_wait = 0;
      do {
#ifdef   HAVE_MTX_PROFILE
         ast_mark(mtx_prof, 1);
#endif
         res = pthread_mutex_trylock(&t->mutex);
#ifdef   HAVE_MTX_PROFILE
         ast_mark(mtx_prof, 0);
#endif
         if (res == EBUSY) {
            wait_time = time(NULL) - seconds;
            if (wait_time > reported_wait && (wait_time % 5) == 0) {
               __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
                        filename, lineno, func, (int) wait_time, mutex_name);
               ast_reentrancy_lock(lt);
#ifdef HAVE_BKTR
               __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
#endif
               __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
                        lt->file[ROFFSET], lt->lineno[ROFFSET],
                        lt->func[ROFFSET], mutex_name);
#ifdef HAVE_BKTR
               __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
#endif
               ast_reentrancy_unlock(lt);
               reported_wait = wait_time;
            }
            usleep(200);
         }
      } while (res == EBUSY);
   }
#else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
#ifdef   HAVE_MTX_PROFILE
   ast_mark(mtx_prof, 1);
   res = pthread_mutex_trylock(&t->mutex);
   ast_mark(mtx_prof, 0);
   if (res)
#endif
   res = pthread_mutex_lock(&t->mutex);
#endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */

#ifdef DEBUG_THREADS
   if (t->tracking && !res) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = lineno;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
         lt->reentrancy++;
      } else {
         __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
                        filename, lineno, func, mutex_name);
      }
      ast_reentrancy_unlock(lt);
      if (t->tracking) {
         ast_mark_lock_acquired(t);
      }
   } else if (t->tracking) {
#ifdef HAVE_BKTR
      if (lt->reentrancy) {
         ast_reentrancy_lock(lt);
         bt = &lt->backtrace[lt->reentrancy-1];
         ast_reentrancy_unlock(lt);
      } else {
         bt = NULL;
      }
      ast_remove_lock_info(t, bt);
#else
      ast_remove_lock_info(t);
#endif
   }
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",
               filename, lineno, func, strerror(res));
      DO_THREAD_CRASH;
   }
#endif /* DEBUG_THREADS */

   return res;
}
int __ast_pthread_mutex_trylock ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 288 of file lock.c.

References __ast_pthread_mutex_init(), ast_bt_get_addresses(), AST_MAX_REENTRANCY, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, pthread_mutex_t, pthread_mutex_trylock, ast_lock_track::reentrancy, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

Referenced by __ao2_trylock().

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
      /* Don't warn abount uninitialized mutex.
       * Simple try to initialize it.
       * May be not needed in linux system.
       */
      res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
      if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
         __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
                filename, lineno, func, mutex_name);
         return res;
      }
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
#ifdef HAVE_BKTR
      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);
      ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
#else
      ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
#endif
   }
#endif /* DEBUG_THREADS */

   res = pthread_mutex_trylock(&t->mutex);

#ifdef DEBUG_THREADS
   if (t->tracking && !res) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = lineno;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
         lt->reentrancy++;
      } else {
         __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
                  filename, lineno, func, mutex_name);
      }
      ast_reentrancy_unlock(lt);
      if (t->tracking) {
         ast_mark_lock_acquired(t);
      }
   } else if (t->tracking) {
      ast_mark_lock_failed(t);
   }
#endif /* DEBUG_THREADS */

   return res;
}
int __ast_pthread_mutex_unlock ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 362 of file lock.c.

References __ast_pthread_mutex_init(), AST_MAX_REENTRANCY, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_mutex_info::mutex, 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().

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
      __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
               filename, lineno, func, mutex_name);
      res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
      if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
         __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
                filename, lineno, func, mutex_name);
      }
      return res;
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
         __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
                  filename, lineno, func, mutex_name);
         __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
                  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
#ifdef HAVE_BKTR
         __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
#endif
         DO_THREAD_CRASH;
      }

      if (--lt->reentrancy < 0) {
         __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
                  filename, lineno, func, mutex_name);
         lt->reentrancy = 0;
      }

      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = NULL;
         lt->lineno[lt->reentrancy] = 0;
         lt->func[lt->reentrancy] = NULL;
         lt->thread[lt->reentrancy] = 0;
      }

#ifdef HAVE_BKTR
      if (lt->reentrancy) {
         bt = &lt->backtrace[lt->reentrancy - 1];
      }
#endif
      ast_reentrancy_unlock(lt);

#ifdef HAVE_BKTR
      ast_remove_lock_info(t, bt);
#else
      ast_remove_lock_info(t);
#endif
   }
#endif /* DEBUG_THREADS */

   res = pthread_mutex_unlock(&t->mutex);

#ifdef DEBUG_THREADS
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n",
               filename, lineno, func, strerror(res));
      DO_THREAD_CRASH;
   }
#endif /* DEBUG_THREADS */

   return res;
}
int __ast_rwlock_destroy ( const char *  filename,
int  lineno,
const char *  func,
const char *  rwlock_name,
ast_rwlock_t t 
)

Definition at line 719 of file lock.c.

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

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt = t->track;
   int canlog = strcmp(filename, "logger.c") & t->tracking;

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if (t->lock == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
      __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
               filename, lineno, func, rwlock_name);
      return 0;
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

#endif /* DEBUG_THREADS */

   res = pthread_rwlock_destroy(&t->lock);

#ifdef DEBUG_THREADS
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error destroying rwlock %s: %s\n",
            filename, lineno, func, rwlock_name, strerror(res));
   }
   if (t->tracking) {
      ast_reentrancy_lock(lt);
      lt->file[0] = filename;
      lt->lineno[0] = lineno;
      lt->func[0] = func;
      lt->reentrancy = 0;
      lt->thread[0] = 0;
#ifdef HAVE_BKTR
      memset(&lt->backtrace[0], 0, sizeof(lt->backtrace[0]));
#endif
      ast_reentrancy_unlock(lt);
      delete_reentrancy_cs(&t->track);
   }
#endif /* DEBUG_THREADS */

   return res;
}
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 686 of file lock.c.

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

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

{
   int res;
   pthread_rwlockattr_t attr;

#ifdef DEBUG_THREADS

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   int canlog = strcmp(filename, "logger.c") & t->tracking;

   if (t->lock != ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
      __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is already initialized.\n",
            filename, lineno, func, rwlock_name);
      return 0;
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if ((t->tracking = tracking)) {
      ast_reentrancy_init(&t->track);
   }
#endif /* DEBUG_THREADS */

   pthread_rwlockattr_init(&attr);

#ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
   pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP);
#endif

   res = pthread_rwlock_init(&t->lock, &attr);
   pthread_rwlockattr_destroy(&attr);
   return res;
}
int __ast_rwlock_rdlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 848 of file lock.c.

References __ast_rwlock_init(), __AST_RWLOCK_INIT_VALUE, ast_bt_get_addresses(), AST_MAX_REENTRANCY, ast_lock_track::backtrace, 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.

Referenced by __ast_heap_rdlock().

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
       /* Don't warn abount uninitialized lock.
        * Simple try to initialize it.
        * May be not needed in linux system.
        */
      res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
      if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
         __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
               filename, line, func, name);
         return res;
      }
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
#ifdef HAVE_BKTR
      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);
      ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

#if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
   {
      time_t seconds = time(NULL);
      time_t wait_time, reported_wait = 0;
      do {
         res = pthread_rwlock_tryrdlock(&t->lock);
         if (res == EBUSY) {
            wait_time = time(NULL) - seconds;
            if (wait_time > reported_wait && (wait_time % 5) == 0) {
               __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for readlock '%s'?\n",
                  filename, line, func, (int)wait_time, name);
               if (t->tracking) {
                  ast_reentrancy_lock(lt);
#ifdef HAVE_BKTR
                  __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
#endif
                  __ast_mutex_logger("%s line %d (%s): '%s' was locked  here.\n",
                        lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
                        lt->func[lt->reentrancy-1], name);
#ifdef HAVE_BKTR
                  __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
#endif
                  ast_reentrancy_unlock(lt);
               }
               reported_wait = wait_time;
            }
            usleep(200);
         }
      } while (res == EBUSY);
   }
#else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
   res = pthread_rwlock_rdlock(&t->lock);
#endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */

#ifdef DEBUG_THREADS
   if (!res && t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = line;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
         lt->reentrancy++;
      }
      ast_reentrancy_unlock(lt);
      if (t->tracking) {
         ast_mark_lock_acquired(t);
      }
   } else if (t->tracking) {
#ifdef HAVE_BKTR
      if (lt->reentrancy) {
         ast_reentrancy_lock(lt);
         bt = &lt->backtrace[lt->reentrancy-1];
         ast_reentrancy_unlock(lt);
      } else {
         bt = NULL;
      }
      ast_remove_lock_info(t, bt);
#else
      ast_remove_lock_info(t);
#endif
   }

   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
            filename, line, func, strerror(res));
      DO_THREAD_CRASH;
   }
#endif /* DEBUG_THREADS */

   return res;
}
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 1089 of file lock.c.

References __ast_rwlock_init(), __AST_RWLOCK_INIT_VALUE, ast_bt_get_addresses(), AST_MAX_REENTRANCY, ast_tvnow(), ast_tvsub(), ast_lock_track::backtrace, 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.

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
       /* Don't warn abount uninitialized lock.
        * Simple try to initialize it.
        * May be not needed in linux system.
        */
      res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
      if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
         __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
               filename, line, func, name);
         return res;
      }
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
#ifdef HAVE_BKTR
      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
   res = pthread_rwlock_timedrdlock(&t->lock, abs_timeout);
#else
   do {
      struct timeval _start = ast_tvnow(), _diff;
      for (;;) {
         if (!(res = pthread_rwlock_tryrdlock(&t->lock))) {
            break;
         }
         _diff = ast_tvsub(ast_tvnow(), _start);
         if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
            break;
         }
         usleep(1);
      }
   } while (0);
#endif

#ifdef DEBUG_THREADS
   if (!res && t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = line;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
         lt->reentrancy++;
      }
      ast_reentrancy_unlock(lt);
      if (t->tracking) {
         ast_mark_lock_acquired(t);
      }
   } else if (t->tracking) {
#ifdef HAVE_BKTR
      if (lt->reentrancy) {
         ast_reentrancy_lock(lt);
         bt = &lt->backtrace[lt->reentrancy-1];
         ast_reentrancy_unlock(lt);
      } else {
         bt = NULL;
      }
      ast_remove_lock_info(t, bt);
#else
      ast_remove_lock_info(t);
#endif
   }
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
            filename, line, func, strerror(res));
      DO_THREAD_CRASH;
   }
#endif /* DEBUG_THREADS */

   return res;
}
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 1192 of file lock.c.

References __ast_rwlock_init(), __AST_RWLOCK_INIT_VALUE, ast_bt_get_addresses(), AST_MAX_REENTRANCY, ast_tvnow(), ast_tvsub(), ast_lock_track::backtrace, 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.

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
       /* Don't warn abount uninitialized lock.
        * Simple try to initialize it.
        * May be not needed in linux system.
        */
      res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
      if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
         __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
               filename, line, func, name);
         return res;
      }
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
#ifdef HAVE_BKTR
      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
   res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout);
#else
   do {
      struct timeval _start = ast_tvnow(), _diff;
      for (;;) {
         if (!(res = pthread_rwlock_trywrlock(&t->lock))) {
            break;
         }
         _diff = ast_tvsub(ast_tvnow(), _start);
         if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
            break;
         }
         usleep(1);
      }
   } while (0);
#endif

#ifdef DEBUG_THREADS
   if (!res && t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = line;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
         lt->reentrancy++;
      }
      ast_reentrancy_unlock(lt);
      if (t->tracking) {
         ast_mark_lock_acquired(t);
      }
   } else if (t->tracking) {
#ifdef HAVE_BKTR
      if (lt->reentrancy) {
         ast_reentrancy_lock(lt);
         bt = &lt->backtrace[lt->reentrancy-1];
         ast_reentrancy_unlock(lt);
      } else {
         bt = NULL;
      }
      if (t->tracking) {
         ast_remove_lock_info(t, bt);
      }
#else
      if (t->tracking) {
         ast_remove_lock_info(t);
      }
#endif
   }
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
            filename, line, func, strerror(res));
      DO_THREAD_CRASH;
   }
#endif /* DEBUG_THREADS */

   return res;
}
int __ast_rwlock_tryrdlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 1299 of file lock.c.

References __ast_rwlock_init(), __AST_RWLOCK_INIT_VALUE, ast_bt_get_addresses(), AST_MAX_REENTRANCY, ast_lock_track::backtrace, 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.

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   int canlog = strcmp(filename, "logger.c") & t->tracking;

   if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
       /* Don't warn abount uninitialized lock.
        * Simple try to initialize it.
        * May be not needed in linux system.
        */
      res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
      if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
         __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
               filename, line, func, name);
         return res;
      }
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
#ifdef HAVE_BKTR
      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);
      ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

   res = pthread_rwlock_tryrdlock(&t->lock);

#ifdef DEBUG_THREADS
   if (!res && t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = line;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
         lt->reentrancy++;
      }
      ast_reentrancy_unlock(lt);
      if (t->tracking) {
         ast_mark_lock_acquired(t);
      }
   } else if (t->tracking) {
      ast_mark_lock_failed(t);
   }
#endif /* DEBUG_THREADS */

   return res;
}
int __ast_rwlock_trywrlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 1369 of file lock.c.

References __ast_rwlock_init(), __AST_RWLOCK_INIT_VALUE, ast_bt_get_addresses(), AST_MAX_REENTRANCY, ast_lock_track::backtrace, 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.

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   int canlog = strcmp(filename, "logger.c") & t->tracking;

   if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
       /* Don't warn abount uninitialized lock.
        * Simple try to initialize it.
        * May be not needed in linux system.
        */
      res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
      if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
         __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
               filename, line, func, name);
         return res;
      }
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
#ifdef HAVE_BKTR
      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

   res = pthread_rwlock_trywrlock(&t->lock);

#ifdef DEBUG_THREADS
   if (!res && t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = line;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
         lt->reentrancy++;
      }
      ast_reentrancy_unlock(lt);
      ast_mark_lock_acquired(t);
   } else if (t->tracking) {
      ast_mark_lock_failed(t);
   }
#endif /* DEBUG_THREADS */

   return res;
}
int __ast_rwlock_unlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 762 of file lock.c.

References __ast_rwlock_init(), __AST_RWLOCK_INIT_VALUE, AST_PTHREADT_NULL, ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::func, ast_lock_track::lineno, ast_rwlock_info::lock, ast_lock_track::reentrancy, ast_lock_track::thread, ast_rwlock_info::track, and ast_rwlock_info::tracking.

Referenced by __ast_heap_unlock().

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif
   int lock_found = 0;


#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
      __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
               filename, line, func, name);
      res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
      if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
         __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
               filename, line, func, name);
      }
      return res;
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy) {
         int i;
         pthread_t self = pthread_self();
         for (i = lt->reentrancy - 1; i >= 0; --i) {
            if (lt->thread[i] == self) {
               lock_found = 1;
               if (i != lt->reentrancy - 1) {
                  lt->file[i] = lt->file[lt->reentrancy - 1];
                  lt->lineno[i] = lt->lineno[lt->reentrancy - 1];
                  lt->func[i] = lt->func[lt->reentrancy - 1];
                  lt->thread[i] = lt->thread[lt->reentrancy - 1];
               }
#ifdef HAVE_BKTR
               bt = &lt->backtrace[i];
#endif
               lt->file[lt->reentrancy - 1] = NULL;
               lt->lineno[lt->reentrancy - 1] = 0;
               lt->func[lt->reentrancy - 1] = NULL;
               lt->thread[lt->reentrancy - 1] = AST_PTHREADT_NULL;
               break;
            }
         }
      }

      if (lock_found && --lt->reentrancy < 0) {
         __ast_mutex_logger("%s line %d (%s): rwlock '%s' freed more times than we've locked!\n",
               filename, line, func, name);
         lt->reentrancy = 0;
      }

      ast_reentrancy_unlock(lt);

#ifdef HAVE_BKTR
      ast_remove_lock_info(t, bt);
#else
      ast_remove_lock_info(t);
#endif
   }
#endif /* DEBUG_THREADS */

   res = pthread_rwlock_unlock(&t->lock);

#ifdef DEBUG_THREADS
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error releasing rwlock: %s\n",
            filename, line, func, strerror(res));
      DO_THREAD_CRASH;
   }
#endif /* DEBUG_THREADS */

   return res;
}
int __ast_rwlock_wrlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 967 of file lock.c.

References __ast_rwlock_init(), __AST_RWLOCK_INIT_VALUE, ast_bt_get_addresses(), AST_MAX_REENTRANCY, ast_lock_track::backtrace, 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.

Referenced by __ast_heap_wrlock().

{
   int res;

#ifdef DEBUG_THREADS
   struct ast_lock_track *lt;
   int canlog = strcmp(filename, "logger.c") & t->tracking;
#ifdef HAVE_BKTR
   struct ast_bt *bt = NULL;
#endif

#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
   if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
       /* Don't warn abount uninitialized lock.
        * Simple try to initialize it.
        * May be not needed in linux system.
        */
      res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
      if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
         __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
               filename, line, func, name);
         return res;
      }
   }
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

   if (t->tracking && !t->track) {
      ast_reentrancy_init(&t->track);
   }
   lt = t->track;

   if (t->tracking) {
#ifdef HAVE_BKTR
      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

#if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
   {
      time_t seconds = time(NULL);
      time_t wait_time, reported_wait = 0;
      do {
         res = pthread_rwlock_trywrlock(&t->lock);
         if (res == EBUSY) {
            wait_time = time(NULL) - seconds;
            if (wait_time > reported_wait && (wait_time % 5) == 0) {
               __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for writelock '%s'?\n",
                  filename, line, func, (int)wait_time, name);
               if (t->tracking) {
                  ast_reentrancy_lock(lt);
#ifdef HAVE_BKTR
                  __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
#endif
                  __ast_mutex_logger("%s line %d (%s): '%s' was locked  here.\n",
                        lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
                        lt->func[lt->reentrancy-1], name);
#ifdef HAVE_BKTR
                  __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
#endif
                  ast_reentrancy_unlock(lt);
               }
               reported_wait = wait_time;
            }
            usleep(200);
         }
      } while (res == EBUSY);
   }
#else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
   res = pthread_rwlock_wrlock(&t->lock);
#endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */

#ifdef DEBUG_THREADS
   if (!res && t->tracking) {
      ast_reentrancy_lock(lt);
      if (lt->reentrancy < AST_MAX_REENTRANCY) {
         lt->file[lt->reentrancy] = filename;
         lt->lineno[lt->reentrancy] = line;
         lt->func[lt->reentrancy] = func;
         lt->thread[lt->reentrancy] = pthread_self();
         lt->reentrancy++;
      }
      ast_reentrancy_unlock(lt);
      if (t->tracking) {
         ast_mark_lock_acquired(t);
      }
   } else if (t->tracking) {
#ifdef HAVE_BKTR
      if (lt->reentrancy) {
         ast_reentrancy_lock(lt);
         bt = &lt->backtrace[lt->reentrancy-1];
         ast_reentrancy_unlock(lt);
      } else {
         bt = NULL;
      }
      if (t->tracking) {
         ast_remove_lock_info(t, bt);
      }
#else
      if (t->tracking) {
         ast_remove_lock_info(t);
      }
#endif
   }
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error obtaining write lock: %s\n",
            filename, line, func, strerror(res));
      DO_THREAD_CRASH;
   }
#endif /* DEBUG_THREADS */

   return res;
}
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 649 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 603 of file lock.h.

Referenced by __ao2_lock(), __ao2_trylock(), __ao2_unlock(), __ast_channel_alloc_ap(), __ast_manager_event_multichan(), __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), _ast_odbc_request_obj2(), _sip_tcp_helper_thread(), accept_thread(), acf_odbc_read(), action_login(), add_subscribe_event(), admin_exec(), advance_event(), append_event(), ast_cli_command_full(), ast_dial_append(), ast_event_subscribe_new(), ast_module_ref(), ast_module_unref(), authenticate_verify(), build_conf(), build_peer(), cc_device_monitor_init(), cc_extension_monitor_init(), cc_interfaces_datastore_init(), cdr_seq_inc(), 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_session(), find_transcoders(), generic_fax_exec(), grab_last(), handle_register_message(), httpd_helper_thread(), iax2_destroy_helper(), iax2_process_thread(), iax_frame_free(), iax_frame_new(), inprocess_count(), internal_ao2_alloc(), internal_ao2_callback(), internal_ao2_container_alloc(), internal_ao2_iterator_next(), internal_ao2_link(), internal_ao2_ref(), load_realtime_queue(), pri_dchannel(), receivefax_exec(), reload_single_queue(), run_station(), sendfax_exec(), session_destructor(), session_do(), sig_pri_cw_available(), sig_pri_hangup(), sip_destroy_peer(), sip_new(), sip_peer_hold(), sip_register(), sip_registry_destroy(), sla_add_trunk_to_station(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), smdi_msg_retrieve_read(), spandsp_fax_switch_to_t38(), temp_peer(), and update_stats().

{
int ast_atomic_fetchadd_int_slow ( volatile int *  p,
int  v 
)

Definition at line 1857 of file utils.c.

References ast_mutex_lock, ast_mutex_unlock, and fetchadd_m.

{
   int ret;
   ast_mutex_lock(&fetchadd_m);
   ret = *p;
   *p += v;
   ast_mutex_unlock(&fetchadd_m);
   return ret;
}