Sun Oct 16 2011 08:42:53

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 play_sound_file(), reload_followme(), app_exec(), conf_free(), sla_queue_event_full(), announce_thread(), conf_run(), recordthread(), run_station(), sla_handle_dial_state_event(), sla_hangup_stations(), sla_handle_ringing_trunk_event(), sla_check_reload(), sla_thread(), dial_trunk(), sla_station_exec(), queue_ringing_trunk(), sla_trunk_exec(), sla_destroy(), leave_voicemail(), load_config(), mixmonitor_ds_destroy(), destroy_monitor_audiohook(), mixmonitor_thread(), stop_mixmonitor_exec(), osp_create_provider(), osp_get_provider(), osp_create_transaction(), osp_unload(), handle_cli_osp_show(), donodelog(), statpost(), node_lookup(), load_rpt_vars(), rpt_tele_thread(), function_remote(), rpt_master(), speech_background(), save_to_folder(), vm_execmain(), mb_poll_thread(), stop_poll_thread(), ast_replace_sigchld(), ast_unreplace_sigchld(), softmix_bridge_write(), softmix_bridge_poke(), softmix_bridge_thread(), ast_bridge_change_state(), smart_bridge_operation(), bridge_channel_join_multithreaded(), bridge_channel_join_singlethreaded(), ast_bridge_merge(), ast_cdr_submit_batch(), submit_unscheduled_batch(), ast_cdr_detach(), do_cdr(), do_reload(), ast_cdr_engine_init(), writefile(), csv_log(), custom_log(), pgsql_log(), sqlite_log(), write_cdr(), reload(), syslog_log(), tds_log(), tds_unload_module(), tds_load_module(), ast_cel_report_event(), agent_cleanup(), agent_read(), agent_sendhtml(), agent_sendtext(), agent_write(), agent_fixup(), agent_indicate(), agent_digit_begin(), agent_digit_end(), agent_call(), agent_hangup(), agent_cont_sleep(), agent_ack_sleep(), check_availability(), check_beep(), agent_request(), action_agents(), agent_logoff(), agents_show(), agents_show_online(), login_exec(), agent_devicestate(), agents_data_provider_get(), alsa_digit(), alsa_text(), alsa_call(), alsa_answer(), alsa_hangup(), alsa_write(), alsa_read(), alsa_fixup(), alsa_indicate(), alsa_request(), console_autoanswer(), console_answer(), console_sendtext(), console_hangup(), console_dial(), bridge_write(), bridge_hangup(), set_pvt_defaults(), my_handle_dtmf(), my_lock_private(), my_increase_ss_count(), my_decrease_ss_count(), dahdi_digit_begin(), dahdi_digit_end(), dahdi_call(), dahdi_unlink_pri_pvt(), dahdi_unlink_ss7_pvt(), destroy_all_channels(), dahdi_hangup(), dahdi_answer(), dahdi_func_read(), dahdi_func_write(), dahdi_unlink(), dahdi_bridge(), dahdi_fixup(), dahdi_handle_dtmf(), dahdi_exception(), dahdi_indicate(), create_channel_name(), analog_ss_thread(), dahdi_destroy_channel_bynum(), handle_init_event(), do_monitor(), restart_monitor(), dahdi_request(), dahdi_cc_callback(), dahdi_pri_message(), dahdi_pri_error(), handle_pri_set_debug_file(), handle_pri_debug(), handle_pri_show_debug(), dahdi_softhangup_all(), dahdi_restart(), dahdi_show_channels(), dahdi_show_channel(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_set_dnd(), find_channel(), action_dahdishowchannels(), handle_ss7_block_cic(), handle_ss7_block_linkset(), handle_ss7_unblock_cic(), handle_ss7_unblock_linkset(), __unload_module(), setup_dahdi_int(), dahdi_channels_data_provider_get(), gtalk_ringing_ack(), gtalk_answer(), gtalk_get_rtp_peer(), gtalk_set_rtp_peer(), gtalk_alloc(), gtalk_newcall(), gtalk_read(), gtalk_write(), gtalk_fixup(), gtalk_digit_begin(), gtalk_digit_end(), gtalk_hangup(), gtalk_show_channels(), unload_module(), oh323_simulate_dtmf_end(), oh323_update_info(), oh323_destroy(), oh323_digit_begin(), oh323_digit_end(), oh323_call(), oh323_answer(), oh323_hangup(), oh323_read(), oh323_write(), oh323_indicate(), oh323_fixup(), __oh323_new(), oh323_alloc(), find_call_locked(), oh323_request(), h323_reload(), oh323_get_rtp_peer(), signal_condition(), find_idle_thread(), __send_ping(), send_ping(), __send_lagrq(), send_lagrq(), scheduled_destroy(), pvt_destructor(), make_trunk(), __find_callno(), __attempt_transmit(), handle_cli_iax2_show_stats(), __get_from_jb(), transmit_frame(), iax2_fixup(), __auto_congest(), iax2_call(), iax2_hangup(), iax2_setoption(), iax2_queryoption(), iax2_key_rotate(), lock_both(), iax2_bridge(), iax2_answer(), iax2_indicate(), ast_iax2_new(), find_tpeer(), handle_cli_iax2_show_channels(), ast_cli_netstats(), iax2_write(), send_command_locked(), register_verify(), authenticate_reply(), update_registry(), registry_authrequest(), __auth_reject(), auth_reject(), __auto_hangup(), auto_hangup(), timing_read(), dp_lookup(), log_jitterstats(), handle_deferred_full_frames(), defer_full_frame(), socket_process(), iax2_process_thread(), iax2_do_register(), __iax2_poke_noanswer(), iax2_poke_peer(), peer_destructor(), delete_users(), acf_channel_read(), jingle_answer(), jingle_get_rtp_peer(), jingle_set_rtp_peer(), jingle_alloc(), jingle_newcall(), jingle_read(), jingle_write(), jingle_fixup(), jingle_digit(), jingle_hangup(), jingle_show_channels(), dump_queue(), retrans_pkt(), mgcp_postrequest(), send_request(), mgcp_call(), mgcp_hangup(), handle_mgcp_show_endpoints(), handle_mgcp_audit_endpoint(), mgcp_answer(), mgcp_read(), mgcp_write(), mgcp_fixup(), mgcp_senddigit_begin(), mgcp_senddigit_end(), mgcp_devicestate(), mgcp_indicate(), find_subchannel_and_lock(), mgcp_pktcgate_remove(), mgcp_pktcgate_open(), dump_cmd_queues(), find_command(), start_rtp(), handle_request(), mgcpsock_read(), mgcp_prune_realtime_gateway(), destroy_endpoint(), prune_gateways(), reload_config(), mgcp_reload(), misdn_chan_is_valid(), get_chan_by_ast(), get_chan_by_ast_name(), misdn_overlap_dial_task(), handle_cli_misdn_show_channels(), handle_cli_misdn_show_channel(), misdn_hangup(), find_chan_by_bc(), find_hold_call(), find_hold_call_l3(), find_hold_active_call(), cl_queue_chan(), cl_dequeue_chan(), release_chan(), release_chan_early(), cb_events(), misdn_jb_fill(), misdn_jb_empty(), phone_request(), load_module(), sip_tcptls_write(), _sip_tcp_helper_thread(), sip_show_settings(), build_reply_digest(), handle_request_do(), sip_reload(), transmit_response(), skinny_get_rtp_peer(), skinny_hangup(), skinny_read(), skinny_write(), handle_register_message(), handle_capabilities_res_message(), get_input(), skinny_req_parse(), config_line(), config_device(), config_load(), send_client(), create_client(), close_client(), send_retransmit(), unistim_register(), rcv_mac_addr(), key_select_extension(), key_main_page(), parsing(), unistim_hangup(), unistimsock_read(), unistim_read(), unistim_write(), unistim_fixup(), find_subchannel_by_name(), unistim_new(), unistim_info(), unistim_reload(), build_device(), hidthread(), radio_tune(), tune_write(), store_config(), handle_modlist(), clear_config_maps(), ast_config_engine_register(), ast_config_engine_deregister(), find_engine(), handle_cli_core_show_config_mappings(), process_db_keys(), ast_db_put(), ast_db_get(), ast_db_del(), db_sync_thread(), run_devstate_collector(), devstate_change_collector_cb(), answer_exec_run(), ast_dial_join(), ast_search_dns(), dnsmgr_refresh(), ast_dnsmgr_changed(), blr_txt(), blr_ebl(), ast_get_enum(), private_enum_init(), ast_features_reload(), lock_broker(), get_lock(), iax_prov_complete_template(), iax_provision_build(), iax_provision_version(), iax_template_parse(), iax_process_template(), iax_show_provisioning(), iax_provision_free_templates(), inotify_daemon(), add_notify(), mansession_lock(), misdn_cfg_lock(), handle_statechange(), increase_call_count(), decrease_call_count(), ast_context_lockmacro(), ast_merge_contexts_and_delete(), ast_wrlock_contexts(), ast_rdlock_contexts(), handle_cli_dialplan_save(), lua_load_extensions(), lua_reload_extensions(), lua_free_extensions(), handle_speechrecognize(), schedule_calendar_event(), do_refresh(), caldav_load_calendar(), ewscal_load_calendar(), exchangecal_load_calendar(), ical_load_calendar(), realtime_ldap_base_ap(), update_ldap(), update2_ldap(), find_table(), realtime_pgsql(), realtime_multi_pgsql(), update_pgsql(), update2_pgsql(), store_pgsql(), destroy_pgsql(), config_pgsql(), require_pgsql(), parse_config(), cdr_handler(), config_handler(), realtime_handler(), realtime_multi_handler(), realtime_update_handler(), realtime_update2_handler(), realtime_store_handler(), realtime_destroy_handler(), spandsp_fax_cli_show_stats(), acf_jabberreceive_read(), aji_handle_message(), ast_monitor_start(), handle_cli_odbc_show(), aoro2_obj_cb(), odbc_obj_disconnect(), odbc_obj_connect(), data_odbc_provider_handler(), build_profile(), set_config(), restart_pktc_thread(), ast_smdi_md_message_push(), ast_smdi_mwi_message_push(), ast_smdi_md_message_putback(), ast_smdi_mwi_message_putback(), lock_msg_q(), destroy_all_mailbox_mappings(), append_mailbox_mapping(), mwi_monitor_handler(), _unload_module(), stun_monitor_request(), __reload(), pthread_timer_open(), do_timing(), sched_run(), ast_sched_thread_poke(), ast_sched_thread_destroy(), ast_sched_thread_add_variable(), ast_sched_thread_add(), sched_context_destroy(), ast_sched_wait(), ast_sched_add_variable(), ast_sched_del(), ast_sched_report(), ast_sched_dump(), ast_sched_runq(), ast_sched_when(), sig_pri_new_ast_channel(), sig_pri_lock_owner(), pri_ss_thread(), pri_dchannel(), sig_pri_available(), sig_pri_cli_show_channels(), sig_pri_cli_show_span(), sig_ss7_lock_owner(), ss7_start_call(), ss7_linkset(), ssl_lock(), tps_ping_handler(), cli_tps_ping(), tps_processing_function(), tps_taskprocessor_destroy(), tps_taskprocessor_pop(), ast_taskprocessor_push(), ast_random(), and ast_atomic_fetchadd_int_slow().

#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 play_sound_file(), reload_followme(), app_exec(), conf_free(), sla_queue_event_full(), announce_thread(), conf_run(), recordthread(), run_station(), sla_handle_dial_state_event(), sla_hangup_stations(), sla_handle_ringing_trunk_event(), sla_check_reload(), sla_thread(), dial_trunk(), sla_station_exec(), queue_ringing_trunk(), sla_trunk_exec(), sla_destroy(), leave_voicemail(), load_config(), mixmonitor_ds_destroy(), destroy_monitor_audiohook(), mixmonitor_thread(), stop_mixmonitor_exec(), osp_create_provider(), osp_get_provider(), osp_create_transaction(), osp_unload(), handle_cli_osp_show(), donodelog(), statpost(), node_lookup(), load_rpt_vars(), rpt_tele_thread(), function_remote(), rpt_master(), speech_background(), save_to_folder(), vm_execmain(), mb_poll_thread(), stop_poll_thread(), ast_replace_sigchld(), ast_unreplace_sigchld(), softmix_bridge_write(), softmix_bridge_poke(), softmix_bridge_thread(), ast_bridge_change_state(), smart_bridge_operation(), bridge_channel_join_multithreaded(), bridge_channel_join_singlethreaded(), ast_bridge_merge(), ast_cdr_submit_batch(), submit_unscheduled_batch(), ast_cdr_detach(), do_cdr(), do_reload(), ast_cdr_engine_init(), writefile(), csv_log(), custom_log(), pgsql_log(), sqlite_log(), write_cdr(), reload(), syslog_log(), tds_log(), tds_unload_module(), tds_load_module(), ast_cel_report_event(), agent_cleanup(), agent_read(), agent_sendhtml(), agent_sendtext(), agent_write(), agent_fixup(), agent_indicate(), agent_digit_begin(), agent_digit_end(), agent_call(), agent_hangup(), agent_cont_sleep(), agent_ack_sleep(), check_availability(), check_beep(), agent_request(), action_agents(), agent_logoff(), agents_show(), agents_show_online(), login_exec(), agent_devicestate(), agents_data_provider_get(), alsa_digit(), alsa_text(), alsa_call(), alsa_answer(), alsa_hangup(), alsa_write(), alsa_read(), alsa_fixup(), alsa_indicate(), alsa_request(), console_autoanswer(), console_answer(), console_sendtext(), console_hangup(), console_dial(), bridge_write(), bridge_queue_hangup(), bridge_hangup(), set_pvt_defaults(), my_handle_dtmf(), my_unlock_private(), my_increase_ss_count(), my_decrease_ss_count(), dahdi_digit_begin(), dahdi_digit_end(), dahdi_call(), dahdi_unlink_pri_pvt(), dahdi_unlink_ss7_pvt(), destroy_all_channels(), dahdi_hangup(), dahdi_answer(), dahdi_func_read(), dahdi_func_write(), dahdi_unlink(), dahdi_bridge(), dahdi_fixup(), dahdi_handle_dtmf(), dahdi_exception(), dahdi_read(), dahdi_indicate(), create_channel_name(), analog_ss_thread(), dahdi_destroy_channel_bynum(), handle_init_event(), do_monitor(), restart_monitor(), dahdi_request(), dahdi_cc_callback(), dahdi_pri_message(), dahdi_pri_error(), handle_pri_set_debug_file(), handle_pri_debug(), handle_pri_show_debug(), dahdi_softhangup_all(), dahdi_restart(), dahdi_show_channels(), dahdi_show_channel(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_set_dnd(), find_channel(), action_dahdishowchannels(), handle_ss7_block_cic(), handle_ss7_block_linkset(), handle_ss7_unblock_cic(), handle_ss7_unblock_linkset(), __unload_module(), setup_dahdi_int(), dahdi_channels_data_provider_get(), gtalk_ringing_ack(), gtalk_answer(), gtalk_get_rtp_peer(), gtalk_set_rtp_peer(), gtalk_alloc(), gtalk_newcall(), gtalk_read(), gtalk_write(), gtalk_fixup(), gtalk_digit_begin(), gtalk_digit_end(), gtalk_hangup(), gtalk_show_channels(), unload_module(), oh323_simulate_dtmf_end(), oh323_update_info(), __oh323_destroy(), oh323_destroy(), oh323_digit_begin(), oh323_digit_end(), oh323_call(), oh323_answer(), oh323_hangup(), oh323_read(), oh323_write(), oh323_indicate(), oh323_fixup(), __oh323_rtp_create(), __oh323_new(), oh323_alloc(), find_call_locked(), oh323_request(), receive_digit(), external_rtp_create(), setup_rtp_connection(), connection_made(), progress(), answer_call(), chan_ringing(), cleanup_connection(), hangup_connection(), set_dtmf_payload(), set_peer_capabilities(), set_local_capabilities(), remote_hold(), h323_reload(), oh323_get_rtp_peer(), signal_condition(), find_idle_thread(), __send_ping(), send_ping(), __send_lagrq(), send_lagrq(), scheduled_destroy(), pvt_destructor(), make_trunk(), __find_callno(), __attempt_transmit(), handle_cli_iax2_show_stats(), __get_from_jb(), transmit_frame(), iax2_fixup(), __auto_congest(), iax2_call(), iax2_hangup(), iax2_setoption(), iax2_queryoption(), iax2_key_rotate(), unlock_both(), iax2_bridge(), iax2_answer(), iax2_indicate(), ast_iax2_new(), iax2_trunk_queue(), handle_cli_iax2_show_channels(), ast_cli_netstats(), iax2_write(), send_command_locked(), register_verify(), authenticate_reply(), update_registry(), registry_authrequest(), __auth_reject(), auth_reject(), __auto_hangup(), auto_hangup(), timing_read(), dp_lookup(), log_jitterstats(), handle_deferred_full_frames(), defer_full_frame(), socket_process_meta(), socket_process(), iax2_process_thread(), iax2_do_register(), iax2_provision(), __iax2_poke_noanswer(), iax2_poke_peer(), iax2_request(), peer_destructor(), delete_users(), cache_get_callno_locked(), find_cache(), acf_channel_read(), jingle_answer(), jingle_get_rtp_peer(), jingle_set_rtp_peer(), jingle_alloc(), jingle_newcall(), jingle_read(), jingle_write(), jingle_fixup(), jingle_digit(), jingle_hangup(), jingle_show_channels(), dump_queue(), retrans_pkt(), mgcp_postrequest(), send_request(), mgcp_call(), mgcp_hangup(), handle_mgcp_show_endpoints(), handle_mgcp_audit_endpoint(), mgcp_answer(), mgcp_read(), mgcp_write(), mgcp_fixup(), mgcp_senddigit_begin(), mgcp_senddigit_end(), mgcp_devicestate(), mgcp_indicate(), find_subchannel_and_lock(), mgcp_pktcgate_remove(), mgcp_pktcgate_open(), dump_cmd_queues(), find_command(), start_rtp(), handle_request(), mgcpsock_read(), mgcp_prune_realtime_gateway(), mgcp_request(), destroy_endpoint(), prune_gateways(), reload_config(), mgcp_reload(), misdn_chan_is_valid(), get_chan_by_ast(), get_chan_by_ast_name(), misdn_overlap_dial_task(), handle_cli_misdn_show_channels(), handle_cli_misdn_show_channel(), misdn_hangup(), find_chan_by_bc(), find_hold_call(), find_hold_call_l3(), find_hold_active_call(), cl_queue_chan(), cl_dequeue_chan(), release_chan(), release_chan_early(), cb_events(), misdn_jb_fill(), misdn_jb_empty(), phone_request(), load_module(), sip_tcptls_write(), _sip_tcp_helper_thread(), sip_show_settings(), build_reply_digest(), handle_request_do(), sip_reload(), transmit_response(), skinny_get_rtp_peer(), skinny_hangup(), skinny_read(), skinny_write(), handle_register_message(), handle_capabilities_res_message(), get_input(), skinny_req_parse(), config_line(), config_device(), config_load(), send_client(), create_client(), close_client(), send_retransmit(), unistim_register(), rcv_mac_addr(), key_select_extension(), key_main_page(), parsing(), unistim_hangup(), unistimsock_read(), unistim_read(), unistim_write(), unistim_fixup(), find_subchannel_by_name(), unistim_new(), unistim_info(), unistim_reload(), build_device(), hidthread(), radio_tune(), tune_write(), store_config(), handle_modlist(), ast_cli_perms_init(), clear_config_maps(), ast_config_engine_register(), ast_config_engine_deregister(), find_engine(), handle_cli_core_show_config_mappings(), process_db_keys(), ast_db_put(), ast_db_get(), ast_db_del(), db_sync_thread(), run_devstate_collector(), devstate_change_collector_cb(), answer_exec_run(), ast_dial_join(), ast_search_dns(), dnsmgr_refresh(), ast_dnsmgr_changed(), refresh_list(), blr_txt(), blr_ebl(), ast_get_enum(), private_enum_init(), ast_features_reload(), lock_broker(), get_lock(), iax_prov_complete_template(), iax_provision_build(), iax_provision_version(), iax_template_parse(), iax_process_template(), iax_show_provisioning(), iax_provision_free_templates(), ast_module_reload(), inotify_daemon(), add_notify(), mansession_unlock(), misdn_cfg_unlock(), handle_statechange(), increase_call_count(), decrease_call_count(), ast_context_unlockmacro(), ast_merge_contexts_and_delete(), ast_unlock_contexts(), handle_cli_dialplan_save(), lua_load_extensions(), lua_reload_extensions(), lua_free_extensions(), handle_speechrecognize(), schedule_calendar_event(), do_refresh(), caldav_load_calendar(), ewscal_load_calendar(), exchangecal_load_calendar(), ical_load_calendar(), ldap_loadentry(), realtime_ldap_base_ap(), update_ldap(), update2_ldap(), find_table(), realtime_pgsql(), realtime_multi_pgsql(), update_pgsql(), update2_pgsql(), store_pgsql(), destroy_pgsql(), config_pgsql(), require_pgsql(), parse_config(), cdr_handler(), config_handler(), realtime_handler(), realtime_multi_handler(), realtime_update_handler(), realtime_update2_handler(), realtime_store_handler(), realtime_destroy_handler(), spandsp_fax_cli_show_stats(), acf_jabberreceive_read(), aji_handle_message(), ast_monitor_start(), handle_cli_odbc_show(), aoro2_obj_cb(), odbc_obj_disconnect(), odbc_obj_connect(), data_odbc_provider_handler(), build_profile(), set_config(), restart_pktc_thread(), ast_smdi_md_message_push(), ast_smdi_mwi_message_push(), ast_smdi_md_message_putback(), ast_smdi_mwi_message_putback(), unlock_msg_q(), destroy_all_mailbox_mappings(), append_mailbox_mapping(), mwi_monitor_handler(), _unload_module(), stun_monitor_request(), __reload(), pthread_timer_open(), do_timing(), sched_run(), ast_sched_thread_poke(), ast_sched_thread_destroy(), ast_sched_thread_add_variable(), ast_sched_thread_add(), sched_context_destroy(), ast_sched_wait(), ast_sched_add_variable(), ast_sched_del(), ast_sched_report(), ast_sched_dump(), ast_sched_runq(), ast_sched_when(), pri_rel(), sig_pri_new_ast_channel(), sig_pri_lock_owner(), pri_ss_thread(), pri_dchannel(), sig_pri_available(), sig_pri_cli_show_channels(), sig_pri_cli_show_span(), sig_ss7_lock_owner(), ss7_start_call(), ss7_linkset(), ss7_rel(), ssl_lock(), tps_ping_handler(), cli_tps_ping(), tps_processing_function(), tps_taskprocessor_destroy(), tps_taskprocessor_pop(), ast_taskprocessor_push(), ast_random(), and ast_atomic_fetchadd_int_slow().

#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_data_init(), ast_hashtab_create(), ast_hashtab_dup(), ast_hashtab_initlock(), ast_heap_create(), ast_context_find_or_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 misdn_tasks_init(), misdn_lib_init(), and ast_pthread_create_stack().

#define pthread_mutex_destroy   use_ast_mutex_destroy_instead_of_pthread_mutex_destroy

Definition at line 560 of file lock.h.

Referenced by stack_destroy(), and __ast_pthread_mutex_destroy().

#define pthread_mutex_init   use_ast_mutex_init_instead_of_pthread_mutex_init

Definition at line 559 of file lock.h.

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

#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_mutex_info::tracking, ast_mutex_info::mutex, pthread_mutex_t, __ast_pthread_mutex_init(), ast_mutex_info::track, ast_lock_track::reentrancy, ast_lock_track::thread, ROFFSET, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, ast_lock_track::backtrace, AST_MAX_REENTRANCY, pthread_cond_timedwait, and ast_bt_get_addresses().

{
   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_mutex_info::tracking, ast_mutex_info::mutex, pthread_mutex_t, __ast_pthread_mutex_init(), ast_mutex_info::track, ast_lock_track::reentrancy, ast_lock_track::thread, ROFFSET, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, ast_lock_track::backtrace, AST_MAX_REENTRANCY, pthread_cond_wait, and ast_bt_get_addresses().

{
   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_mutex_info::tracking, ast_mutex_info::mutex, pthread_mutex_t, ast_mutex_info::track, pthread_mutex_trylock, pthread_mutex_unlock, ast_lock_track::file, ROFFSET, ast_lock_track::lineno, ast_lock_track::func, ast_lock_track::backtrace, pthread_mutex_destroy, ast_lock_track::reentrancy, and ast_lock_track::thread.

{
   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_info::track, ast_mutex_info::mutex, pthread_mutex_t, ast_mutex_info::tracking, AST_MUTEX_KIND, and pthread_mutex_init.

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

{
   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_mutex_info::tracking, ast_mutex_info::mutex, pthread_mutex_t, __ast_pthread_mutex_init(), ast_mutex_info::track, ast_lock_track::reentrancy, AST_MAX_REENTRANCY, ast_bt_get_addresses(), ast_lock_track::backtrace, ast_mark(), pthread_mutex_trylock, ast_lock_track::file, ROFFSET, ast_lock_track::lineno, ast_lock_track::func, pthread_mutex_lock, and ast_lock_track::thread.

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_mutex_info::tracking, ast_mutex_info::mutex, pthread_mutex_t, __ast_pthread_mutex_init(), ast_mutex_info::track, ast_lock_track::reentrancy, AST_MAX_REENTRANCY, ast_bt_get_addresses(), ast_lock_track::backtrace, pthread_mutex_trylock, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, and ast_lock_track::thread.

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_mutex_info::tracking, ast_mutex_info::mutex, pthread_mutex_t, __ast_pthread_mutex_init(), ast_mutex_info::track, ast_lock_track::reentrancy, ast_lock_track::thread, ROFFSET, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, ast_lock_track::backtrace, AST_MAX_REENTRANCY, and pthread_mutex_unlock.

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_info::track, ast_rwlock_info::tracking, ast_rwlock_info::lock, __AST_RWLOCK_INIT_VALUE, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, ast_lock_track::reentrancy, ast_lock_track::thread, and ast_lock_track::backtrace.

{
   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_info::tracking, ast_rwlock_info::lock, __AST_RWLOCK_INIT_VALUE, and ast_rwlock_info::track.

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

{
   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_info::tracking, ast_rwlock_info::lock, __AST_RWLOCK_INIT_VALUE, __ast_rwlock_init(), ast_rwlock_info::track, ast_lock_track::reentrancy, AST_MAX_REENTRANCY, ast_bt_get_addresses(), ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, and ast_lock_track::thread.

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_info::tracking, ast_rwlock_info::lock, __AST_RWLOCK_INIT_VALUE, __ast_rwlock_init(), ast_rwlock_info::track, ast_lock_track::reentrancy, AST_MAX_REENTRANCY, ast_bt_get_addresses(), ast_lock_track::backtrace, ast_tvnow(), ast_tvsub(), ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, and ast_lock_track::thread.

{
   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_info::tracking, ast_rwlock_info::lock, __AST_RWLOCK_INIT_VALUE, __ast_rwlock_init(), ast_rwlock_info::track, ast_lock_track::reentrancy, AST_MAX_REENTRANCY, ast_bt_get_addresses(), ast_lock_track::backtrace, ast_tvnow(), ast_tvsub(), ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, and ast_lock_track::thread.

{
   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_info::tracking, ast_rwlock_info::lock, __AST_RWLOCK_INIT_VALUE, __ast_rwlock_init(), ast_rwlock_info::track, ast_lock_track::reentrancy, AST_MAX_REENTRANCY, ast_bt_get_addresses(), ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, and ast_lock_track::thread.

{
   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_info::tracking, ast_rwlock_info::lock, __AST_RWLOCK_INIT_VALUE, __ast_rwlock_init(), ast_rwlock_info::track, ast_lock_track::reentrancy, AST_MAX_REENTRANCY, ast_bt_get_addresses(), ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, and ast_lock_track::thread.

{
   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_info::tracking, ast_rwlock_info::lock, __AST_RWLOCK_INIT_VALUE, __ast_rwlock_init(), ast_rwlock_info::track, ast_lock_track::reentrancy, ast_lock_track::thread, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, ast_lock_track::backtrace, and AST_PTHREADT_NULL.

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_info::tracking, ast_rwlock_info::lock, __AST_RWLOCK_INIT_VALUE, __ast_rwlock_init(), ast_rwlock_info::track, ast_lock_track::reentrancy, AST_MAX_REENTRANCY, ast_bt_get_addresses(), ast_lock_track::backtrace, ast_lock_track::file, ast_lock_track::lineno, ast_lock_track::func, and ast_lock_track::thread.

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(), run_station(), sla_station_exec(), and iax2_process_thread_cleanup().

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

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

Definition at line 1860 of file utils.c.

References ast_mutex_lock, fetchadd_m, and ast_mutex_unlock.

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