Wed Jan 8 2020 09:50:14

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"

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

Macros

#define __AST_MUTEX_DEFINE(scope, mutex, init_val, track)   scope ast_mutex_t mutex = init_val
 
#define __AST_RWLOCK_DEFINE(scope, rwlock, init_val, track)   scope ast_rwlock_t rwlock = init_val
 
#define __AST_RWLOCK_INIT_VALUE   PTHREAD_RWLOCK_INITIALIZER
 
#define 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 More...
 
#define ast_rwlock_init_notracking(rwlock)   __ast_rwlock_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
 wrapper for ast_rwlock_init with tracking disabled More...
 
#define AST_RWLOCK_INIT_VALUE   { __AST_RWLOCK_INIT_VALUE, NULL, 1 }
 
#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. More...
 
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. More...
 
int ast_atomic_fetchadd_int_slow (volatile int *p, int v)
 

Detailed Description

Asterisk locking-related definitions:

Definition in file lock.h.

Macro Definition 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_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(), __dahdi_exception(), __find_callno(), __get_from_jb(), __iax2_poke_noanswer(), __oh323_new(), __reload(), __send_lagrq(), __send_ping(), __unload_module(), _ast_odbc_request_obj2(), _sip_tcp_helper_thread(), _unload_module(), acf_channel_read(), acf_jabberreceive_read(), action_agents(), action_dahdishowchannels(), add_notify(), adsi_delete(), adsi_message(), 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_submit_batch(), ast_cel_check_retire_linkedid(), ast_cel_engine_term(), ast_cel_linkedid_ref(), ast_cel_report_event(), ast_cli_netstats(), ast_config_engine_deregister(), ast_config_engine_register(), ast_context_lockmacro(), ast_db_del(), 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_odbc_direct_execute(), ast_odbc_find_table(), ast_odbc_prepare_and_execute(), ast_odbc_smart_execute(), 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(), astdb_init(), astdb_shutdown(), 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_reply_digest(), caldav_load_calendar(), can_safely_quit(), cb_events(), cdr_handler(), check_availability(), check_beep(), cl_dequeue_chan(), cl_queue_chan(), clear_config_maps(), cli_tps_ping(), close_client(), close_mailbox(), conf_free(), conf_run(), config_device(), config_handler(), config_line(), config_load(), config_module(), config_pgsql(), console_answer(), console_autoanswer(), console_dial(), console_hangup(), console_sendtext(), create_channel_name(), create_client(), csv_log(), custom_log(), dahdi_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_handle_event(), 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(), data_odbc_provider_handler(), db_get_common(), 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(), dnsmgr_shutdown(), do_cdr(), do_monitor(), do_refresh(), do_reload(), do_timing(), 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(), 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_abort_shutdown(), 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_cli_status(), 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_statechange(), 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(), 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(), meetme_menu_admin_extended(), mgcp_answer(), mgcp_call(), mgcp_devicestate(), mgcp_fixup(), mgcp_hangup(), mgcp_indicate(), mgcp_pktcgate_open(), mgcp_pktcgate_remove(), mgcp_postrequest(), mgcp_prune_realtime_gateway(), mgcp_read(), mgcp_reload(), mgcp_senddigit_begin(), mgcp_senddigit_end(), mgcp_write(), mgcpsock_read(), 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(), 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(), pbx_load_module(), peer_destructor(), pgsql_log(), phone_request(), play_message(), play_sound_file(), pri_dchannel(), pri_ss_thread(), private_enum_init(), process_db_keys(), prune_gateways(), pthread_timer_open(), pvt_destructor(), queue_ringing_trunk(), rcv_mac_addr(), realtime_destroy_handler(), realtime_handler(), realtime_ldap_base_ap(), realtime_multi_handler(), realtime_multi_pgsql(), realtime_pgsql(), realtime_store_handler(), realtime_update2_handler(), realtime_update_handler(), recordthread(), register_verify(), registry_authrequest(), release_chan(), release_chan_early(), reload(), reload_config(), reload_followme(), reqprep(), require_pgsql(), restart_monitor(), restart_pktc_thread(), retrans_pkt(), 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_hangup_source_and_cause(), 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_new_ast_channel(), sig_pri_send_mwi_indication(), signal_condition(), sip_reload(), sip_show_settings(), sip_tcptls_write(), skinny_get_rtp_peer(), skinny_hangup(), skinny_read(), skinny_req_parse(), skinny_write(), 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(), ssl_lock(), start_network_thread(), start_rtp(), stop_mixmonitor_exec(), stop_poll_thread(), store_pgsql(), stun_monitor_request(), stun_stop_monitor(), submit_scheduled_batch(), 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(), 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(), vm_instructions_en(), and writefile().

#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(), __dahdi_exception(), __find_callno(), __get_from_jb(), __iax2_poke_noanswer(), __oh323_destroy(), __oh323_new(), __oh323_rtp_create(), __reload(), __send_lagrq(), __send_ping(), __unload_module(), _ast_odbc_request_obj2(), _sip_tcp_helper_thread(), _unload_module(), acf_channel_read(), acf_jabberreceive_read(), action_agents(), action_dahdishowchannels(), add_notify(), adsi_delete(), adsi_message(), 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_submit_batch(), ast_cel_check_retire_linkedid(), ast_cel_engine_term(), ast_cel_linkedid_ref(), 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_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_odbc_direct_execute(), ast_odbc_find_table(), ast_odbc_prepare_and_execute(), ast_odbc_smart_execute(), 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(), astdb_init(), astdb_shutdown(), 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_reply_digest(), cache_get_callno_locked(), caldav_load_calendar(), can_safely_quit(), 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(), close_mailbox(), conf_free(), conf_run(), config_device(), config_handler(), config_line(), config_load(), config_module(), 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_handle_event(), 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(), data_odbc_provider_handler(), db_get_common(), 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(), dnsmgr_shutdown(), do_cdr(), do_monitor(), do_refresh(), do_reload(), do_timing(), 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(), 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_abort_shutdown(), 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_cli_status(), 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_statechange(), hangup_connection(), 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(), lock_broker(), log_jitterstats(), login_exec(), lua_free_extensions(), lua_load_extensions(), lua_reload_extensions(), make_trunk(), mansession_unlock(), mb_poll_thread(), meetme_menu_admin_extended(), mgcp_answer(), mgcp_call(), mgcp_devicestate(), mgcp_fixup(), mgcp_hangup(), mgcp_indicate(), mgcp_pktcgate_open(), mgcp_pktcgate_remove(), mgcp_postrequest(), mgcp_prune_realtime_gateway(), mgcp_read(), mgcp_reload(), mgcp_request(), mgcp_senddigit_begin(), mgcp_senddigit_end(), mgcp_write(), mgcpsock_read(), 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(), 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(), pbx_load_module(), peer_destructor(), pgsql_log(), phone_request(), play_message(), 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(), 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(), reqprep(), require_pgsql(), restart_monitor(), restart_pktc_thread(), retrans_pkt(), 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_dtmf_payload(), set_hangup_source_and_cause(), 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_new_ast_channel(), sig_pri_send_mwi_indication(), signal_condition(), sip_reload(), sip_show_settings(), sip_tcptls_write(), skinny_get_rtp_peer(), skinny_hangup(), skinny_read(), skinny_req_parse(), skinny_write(), 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(), ssl_lock(), start_network_thread(), start_rtp(), stop_mixmonitor_exec(), stop_poll_thread(), store_pgsql(), stun_monitor_request(), stun_stop_monitor(), submit_scheduled_batch(), 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(), 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(), vm_instructions_en(), and writefile().

#define AST_PTHREADT_NULL   (pthread_t) -1

Definition at line 65 of file lock.h.

Referenced by __ast_manager_event_multichan(), __ast_rwlock_unlock(), __sip_reliable_xmit(), __unload_module(), _unload_module(), action_waitevent(), actual_load_config(), add_notify(), ast_autoservice_start(), ast_autoservice_stop(), ast_bridge_destroy(), ast_bridge_new(), ast_cdr_submit_batch(), ast_dial_create(), ast_dial_join(), ast_localtime_wakeup_monitor(), ast_log(), ast_safe_fork(), ast_sched_thread_create(), ast_sched_thread_destroy(), ast_smdi_interface_destroy(), ast_taskprocessor_get(), ast_tcptls_server_start(), ast_tcptls_server_stop(), autoservice_run(), autoservice_shutdown(), bridge_channel_join(), bridge_poke(), bridge_thread(), build_calendar(), build_conf(), build_mansession(), calendar_event_notify(), cdr_engine_shutdown(), close_logger(), conf_free(), conf_run(), console_verboser(), dahdi_r2_destroy_links(), dahdi_r2_get_link(), dahdi_restart(), dnsmgr_shutdown(), do_reload(), generic_http_callback(), get_input(), init_pvt(), inotify_daemon(), load_module(), meetme_menu_admin_extended(), moh_class_destructor(), monitor_sig_flags(), multiplexed_add_or_remove(), multiplexed_bridge_create(), multiplexed_nudge(), multiplexed_thread_function(), network_thread(), pri_destroy_dchan(), pri_grab(), process_clearcache(), process_precache(), really_quit(), restart_monitor(), restart_pktc_thread(), sig_pri_init_pri(), sla_destroy(), sla_load_config(), sla_queue_event_full(), smart_bridge_operation(), smdi_load(), stop_poll_thread(), stop_stream(), tps_taskprocessor_destroy(), and unload_module().

#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 ast_rwlock_unlock (   a)    __ast_rwlock_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)

Definition at line 200 of file lock.h.

Referenced by ast_adsi_available(), ast_adsi_begin_download(), ast_adsi_channel_restore(), ast_adsi_clear_screen(), ast_adsi_clear_soft_keys(), ast_adsi_connect_session(), ast_adsi_data_mode(), ast_adsi_disconnect_session(), ast_adsi_display(), ast_adsi_download_connect(), ast_adsi_download_disconnect(), ast_adsi_end_download(), ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_input_control(), ast_adsi_input_format(), ast_adsi_install_funcs(), ast_adsi_load_session(), ast_adsi_load_soft_key(), ast_adsi_print(), ast_adsi_query_cpeid(), ast_adsi_query_cpeinfo(), ast_adsi_read_encoded_dtmf(), ast_adsi_set_keys(), ast_adsi_set_line(), ast_adsi_transmit_message(), ast_adsi_transmit_message_full(), ast_adsi_unload_session(), ast_adsi_voice_mode(), ast_calendar_config_acquire(), ast_calendar_config_release(), ast_hashtab_destroy(), ast_hashtab_end_traversal(), ast_hashtab_get_stats(), ast_hashtab_insert_immediate(), ast_hashtab_insert_safe(), ast_hashtab_lookup(), ast_hashtab_lookup_with_hash(), ast_hashtab_remove_object_via_lookup(), ast_hashtab_remove_this_object(), ast_hashtab_unlock(), ast_str_retrieve_variable(), ast_unlock_call_features(), ast_unlock_context(), destroy_pvts(), destroy_table(), feature_interpret_helper(), feature_request_and_dial(), get_active_pvt(), get_general_options(), handle_feature_show(), handle_show_globals(), load_config(), load_tech_calendars(), manager_log(), pbx_builtin_clear_globals(), pbx_builtin_getvar_helper(), pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), remap_feature(), set_active(), set_config_flags(), set_general_options(), and unmap_features().

#define CHANNEL_DEADLOCK_AVOIDANCE (   chan)
Value:
usleep(1); \
#define ast_channel_lock(chan)
Definition: channel.h:2466
#define ast_channel_unlock(chan)
Definition: channel.h:2467

Definition at line 480 of file lock.h.

Referenced by awesome_locking(), bridge_queue_hangup(), bridge_write(), dahdi_bridge(), dahdi_handle_event(), dahdi_read(), dial_exec_full(), misdn_attempt_transfer(), and sip_hangup().

#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

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

References pthread_cond_broadcast.

498 {
500 }
#define pthread_cond_broadcast
Definition: lock.h:564
ast_cond_t cond
Definition: app_meetme.c:963
int __ast_cond_destroy ( const char *  filename,
int  lineno,
const char *  func,
const char *  cond_name,
ast_cond_t cond 
)

Definition at line 502 of file lock.c.

References pthread_cond_destroy.

504 {
505  return pthread_cond_destroy(cond);
506 }
ast_cond_t cond
Definition: app_meetme.c:963
#define pthread_cond_destroy
Definition: lock.h:562
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 484 of file lock.c.

References pthread_cond_init.

486 {
487  return pthread_cond_init(cond, cond_attr);
488 }
#define pthread_cond_init
Definition: lock.h:561
ast_cond_t cond
Definition: app_meetme.c:963
int __ast_cond_signal ( const char *  filename,
int  lineno,
const char *  func,
const char *  cond_name,
ast_cond_t cond 
)

Definition at line 490 of file lock.c.

References pthread_cond_signal.

492 {
493  return pthread_cond_signal(cond);
494 }
ast_cond_t cond
Definition: app_meetme.c:963
#define pthread_cond_signal
Definition: lock.h:563
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 589 of file lock.c.

References __ast_pthread_mutex_init(), 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::reentr_mutex, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

592 {
593  int res;
594 
595 #ifdef DEBUG_THREADS
596  struct ast_lock_track *lt;
597  struct ast_lock_track lt_orig;
598  int canlog = strcmp(filename, "logger.c") & t->tracking;
599 
600 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
601  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
602  __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
603  filename, lineno, func, mutex_name);
604  res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
605  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
606  __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
607  filename, lineno, func, mutex_name);
608  }
609  return res;
610  }
611 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
612 
613  if (t->tracking && !t->track) {
614  ast_reentrancy_init(&t->track);
615  }
616  lt = t->track;
617 
618  if (t->tracking) {
619  ast_reentrancy_lock(lt);
620  if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
621  __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
622  filename, lineno, func, mutex_name);
623  __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
624  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
625 #ifdef HAVE_BKTR
626  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
627 #endif
628  DO_THREAD_CRASH;
629  } else if (lt->reentrancy <= 0) {
630  __ast_mutex_logger("%s line %d (%s): attempted to wait on an unlocked mutex '%s'\n",
631  filename, lineno, func, mutex_name);
632  DO_THREAD_CRASH;
633  }
634 
635  /* Waiting on a condition completely suspends a recursive mutex,
636  * even if it's been recursively locked multiple times. Make a
637  * copy of the lock tracking, and reset reentrancy to zero */
638  lt_orig = *lt;
639  lt->reentrancy = 0;
640  ast_reentrancy_unlock(lt);
641 
642  ast_suspend_lock_info(t);
643  }
644 #endif /* DEBUG_THREADS */
645 
646  res = pthread_cond_timedwait(cond, &t->mutex, abstime);
647 
648 #ifdef DEBUG_THREADS
649  if (res && (res != ETIMEDOUT)) {
650  __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
651  filename, lineno, func, strerror(res));
652  DO_THREAD_CRASH;
653  } else if (t->tracking) {
654  pthread_mutex_t reentr_mutex_orig;
655  ast_reentrancy_lock(lt);
656  /* Restore lock tracking to what it was prior to the wait */
657  reentr_mutex_orig = lt->reentr_mutex;
658  *lt = lt_orig;
659  /* un-trash the mutex we just copied over */
660  lt->reentr_mutex = reentr_mutex_orig;
661  ast_reentrancy_unlock(lt);
662 
663  ast_suspend_lock_info(t);
664  }
665 #endif /* DEBUG_THREADS */
666 
667  return res;
668 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
unsigned int tracking
Definition: lock.h:125
int reentrancy
Definition: lock.h:107
int __ast_pthread_mutex_init(int tracking, const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
Definition: lock.c:65
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
#define pthread_mutex_t
Definition: lock.h:553
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
struct ast_lock_track * track
Definition: lock.h:124
ast_cond_t cond
Definition: app_meetme.c:963
#define ROFFSET
Definition: lock.h:208
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
pthread_mutex_t mutex
Definition: lock.h:122
pthread_mutex_t reentr_mutex
Definition: lock.h:113
#define pthread_cond_timedwait
Definition: lock.h:566
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 508 of file lock.c.

References __ast_pthread_mutex_init(), 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::reentr_mutex, ast_lock_track::reentrancy, ROFFSET, ast_lock_track::thread, ast_mutex_info::track, and ast_mutex_info::tracking.

511 {
512  int res;
513 
514 #ifdef DEBUG_THREADS
515  struct ast_lock_track *lt;
516  struct ast_lock_track lt_orig;
517  int canlog = strcmp(filename, "logger.c") & t->tracking;
518 
519 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
520  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
521  __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
522  filename, lineno, func, mutex_name);
523  res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
524  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
525  __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
526  filename, lineno, func, mutex_name);
527  }
528  return res;
529  }
530 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
531 
532  if (t->tracking && !t->track) {
533  ast_reentrancy_init(&t->track);
534  }
535  lt = t->track;
536 
537  if (t->tracking) {
538  ast_reentrancy_lock(lt);
539  if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
540  __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
541  filename, lineno, func, mutex_name);
542  __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
543  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
544 #ifdef HAVE_BKTR
545  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
546 #endif
547  DO_THREAD_CRASH;
548  } else if (lt->reentrancy <= 0) {
549  __ast_mutex_logger("%s line %d (%s): attempted to wait on an unlocked mutex '%s'\n",
550  filename, lineno, func, mutex_name);
551  DO_THREAD_CRASH;
552  }
553 
554  /* Waiting on a condition completely suspends a recursive mutex,
555  * even if it's been recursively locked multiple times. Make a
556  * copy of the lock tracking, and reset reentrancy to zero */
557  lt_orig = *lt;
558  lt->reentrancy = 0;
559  ast_reentrancy_unlock(lt);
560 
561  ast_suspend_lock_info(t);
562  }
563 #endif /* DEBUG_THREADS */
564 
565  res = pthread_cond_wait(cond, &t->mutex);
566 
567 #ifdef DEBUG_THREADS
568  if (res) {
569  __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
570  filename, lineno, func, strerror(res));
571  DO_THREAD_CRASH;
572  } else if (t->tracking) {
573  pthread_mutex_t reentr_mutex_orig;
574  ast_reentrancy_lock(lt);
575  /* Restore lock tracking to what it was prior to the wait */
576  reentr_mutex_orig = lt->reentr_mutex;
577  *lt = lt_orig;
578  /* un-trash the mutex we just copied over */
579  lt->reentr_mutex = reentr_mutex_orig;
580  ast_reentrancy_unlock(lt);
581 
582  ast_restore_lock_info(t);
583  }
584 #endif /* DEBUG_THREADS */
585 
586  return res;
587 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
unsigned int tracking
Definition: lock.h:125
int reentrancy
Definition: lock.h:107
int __ast_pthread_mutex_init(int tracking, const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
Definition: lock.c:65
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
#define pthread_mutex_t
Definition: lock.h:553
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
struct ast_lock_track * track
Definition: lock.h:124
#define pthread_cond_wait
Definition: lock.h:565
ast_cond_t cond
Definition: app_meetme.c:963
#define ROFFSET
Definition: lock.h:208
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
pthread_mutex_t mutex
Definition: lock.h:122
pthread_mutex_t reentr_mutex
Definition: lock.h:113
int __ast_pthread_mutex_destroy ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 99 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.

101 {
102  int res;
103 
104 #ifdef DEBUG_THREADS
105  struct ast_lock_track *lt;
106  int canlog = strcmp(filename, "logger.c") & t->tracking;
107 
108 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
109  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
110  /* Don't try to uninitialize non initialized mutex
111  * This may no effect on linux
112  * And always ganerate core on *BSD with
113  * linked libpthread
114  * This not error condition if the mutex created on the fly.
115  */
116  __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n",
117  filename, lineno, func, mutex_name);
118  return 0;
119  }
120 #endif
121 
122  if (t->tracking && !t->track) {
123  ast_reentrancy_init(&t->track);
124  }
125  lt = t->track;
126 
127  res = pthread_mutex_trylock(&t->mutex);
128  switch (res) {
129  case 0:
131  break;
132  case EINVAL:
133  __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",
134  filename, lineno, func, mutex_name);
135  break;
136  case EBUSY:
137  __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",
138  filename, lineno, func, mutex_name);
139  if (t->tracking) {
140  ast_reentrancy_lock(lt);
141  __ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",
142  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
143 #ifdef HAVE_BKTR
144  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
145 #endif
146  ast_reentrancy_unlock(lt);
147  }
148  break;
149  }
150 #endif /* DEBUG_THREADS */
151 
152  res = pthread_mutex_destroy(&t->mutex);
153 
154 #ifdef DEBUG_THREADS
155  if (res) {
156  __ast_mutex_logger("%s line %d (%s): Error destroying mutex %s: %s\n",
157  filename, lineno, func, mutex_name, strerror(res));
158  }
159  if (t->tracking) {
160  ast_reentrancy_lock(lt);
161  lt->file[0] = filename;
162  lt->lineno[0] = lineno;
163  lt->func[0] = func;
164  lt->reentrancy = 0;
165  lt->thread[0] = 0;
166 #ifdef HAVE_BKTR
167  memset(&lt->backtrace[0], 0, sizeof(lt->backtrace[0]));
168 #endif
169  ast_reentrancy_unlock(lt);
170  delete_reentrancy_cs(&t->track);
171  }
172 #endif /* DEBUG_THREADS */
173 
174  return res;
175 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
unsigned int tracking
Definition: lock.h:125
int reentrancy
Definition: lock.h:107
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
#define pthread_mutex_t
Definition: lock.h:553
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
struct ast_lock_track * track
Definition: lock.h:124
#define pthread_mutex_destroy
Definition: lock.h:560
#define ROFFSET
Definition: lock.h:208
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
pthread_mutex_t mutex
Definition: lock.h:122
#define pthread_mutex_unlock
Definition: lock.h:557
#define pthread_mutex_trylock
Definition: lock.h:558
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 65 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().

67 {
68  int res;
69  pthread_mutexattr_t attr;
70 
71 #ifdef DEBUG_THREADS
72  t->track = NULL;
73 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
74  if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
75 /*
76  int canlog = strcmp(filename, "logger.c") & track;
77  __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is already initialized.\n",
78  filename, lineno, func, mutex_name);
79  DO_THREAD_CRASH;
80 */
81  return 0;
82  }
83 
84 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
85 
86  if ((t->tracking = tracking)) {
87  ast_reentrancy_init(&t->track);
88  }
89 #endif /* DEBUG_THREADS */
90 
91  pthread_mutexattr_init(&attr);
92  pthread_mutexattr_settype(&attr, AST_MUTEX_KIND);
93 
94  res = pthread_mutex_init(&t->mutex, &attr);
95  pthread_mutexattr_destroy(&attr);
96  return res;
97 }
#define pthread_mutex_init
Definition: lock.h:559
unsigned int tracking
Definition: lock.h:125
#define pthread_mutex_t
Definition: lock.h:553
struct ast_lock_track * track
Definition: lock.h:124
pthread_mutex_t mutex
Definition: lock.h:122
#define AST_MUTEX_KIND
Definition: lock.h:76
int __ast_pthread_mutex_lock ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 177 of file lock.c.

References __ast_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().

179 {
180  int res;
181 
182 #ifdef DEBUG_THREADS
183  struct ast_lock_track *lt;
184  int canlog = strcmp(filename, "logger.c") & t->tracking;
185 #ifdef HAVE_BKTR
186  struct ast_bt *bt = NULL;
187 #endif
188 
189 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
190  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
191  /* Don't warn abount uninitialized mutex.
192  * Simple try to initialize it.
193  * May be not needed in linux system.
194  */
195  res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
196  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
197  __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
198  filename, lineno, func, mutex_name);
199  return res;
200  }
201  }
202 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
203 
204  if (t->tracking && !t->track) {
205  ast_reentrancy_init(&t->track);
206  }
207  lt = t->track;
208 
209  if (t->tracking) {
210 #ifdef HAVE_BKTR
211  struct ast_bt tmp;
212 
213  /* The implementation of backtrace() may have its own locks.
214  * Capture the backtrace outside of the reentrancy lock to
215  * avoid deadlocks. See ASTERISK-22455. */
216  ast_bt_get_addresses(&tmp);
217 
218  ast_reentrancy_lock(lt);
219  if (lt->reentrancy != AST_MAX_REENTRANCY) {
220  lt->backtrace[lt->reentrancy] = tmp;
221  bt = &lt->backtrace[lt->reentrancy];
222  }
223  ast_reentrancy_unlock(lt);
224 
225  ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
226 #else
227  ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
228 #endif
229  }
230 #endif /* DEBUG_THREADS */
231 
232 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
233  {
234  time_t seconds = time(NULL);
235  time_t wait_time, reported_wait = 0;
236  do {
237 #ifdef HAVE_MTX_PROFILE
238  ast_mark(mtx_prof, 1);
239 #endif
240  res = pthread_mutex_trylock(&t->mutex);
241 #ifdef HAVE_MTX_PROFILE
242  ast_mark(mtx_prof, 0);
243 #endif
244  if (res == EBUSY) {
245  wait_time = time(NULL) - seconds;
246  if (wait_time > reported_wait && (wait_time % 5) == 0) {
247  __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
248  filename, lineno, func, (int) wait_time, mutex_name);
249  ast_reentrancy_lock(lt);
250 #ifdef HAVE_BKTR
251  __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
252 #endif
253  __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
254  lt->file[ROFFSET], lt->lineno[ROFFSET],
255  lt->func[ROFFSET], mutex_name);
256 #ifdef HAVE_BKTR
257  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
258 #endif
259  ast_reentrancy_unlock(lt);
260  reported_wait = wait_time;
261  }
262  usleep(200);
263  }
264  } while (res == EBUSY);
265  }
266 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
267 #ifdef HAVE_MTX_PROFILE
268  ast_mark(mtx_prof, 1);
269  res = pthread_mutex_trylock(&t->mutex);
270  ast_mark(mtx_prof, 0);
271  if (res)
272 #endif
273  res = pthread_mutex_lock(&t->mutex);
274 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
275 
276 #ifdef DEBUG_THREADS
277  if (t->tracking && !res) {
278  ast_reentrancy_lock(lt);
279  if (lt->reentrancy < AST_MAX_REENTRANCY) {
280  lt->file[lt->reentrancy] = filename;
281  lt->lineno[lt->reentrancy] = lineno;
282  lt->func[lt->reentrancy] = func;
283  lt->thread[lt->reentrancy] = pthread_self();
284  lt->reentrancy++;
285  } else {
286  __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
287  filename, lineno, func, mutex_name);
288  }
289  ast_reentrancy_unlock(lt);
290  if (t->tracking) {
291  ast_mark_lock_acquired(t);
292  }
293  } else if (t->tracking) {
294 #ifdef HAVE_BKTR
295  if (lt->reentrancy) {
296  ast_reentrancy_lock(lt);
297  bt = &lt->backtrace[lt->reentrancy-1];
298  ast_reentrancy_unlock(lt);
299  } else {
300  bt = NULL;
301  }
302  ast_remove_lock_info(t, bt);
303 #else
304  ast_remove_lock_info(t);
305 #endif
306  }
307  if (res) {
308  __ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",
309  filename, lineno, func, strerror(res));
310  DO_THREAD_CRASH;
311  }
312 #endif /* DEBUG_THREADS */
313 
314  return res;
315 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
int64_t ast_mark(int, int start1_stop0)
Definition: asterisk.c:775
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
unsigned int tracking
Definition: lock.h:125
int reentrancy
Definition: lock.h:107
int __ast_pthread_mutex_init(int tracking, const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
Definition: lock.c:65
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
#define pthread_mutex_t
Definition: lock.h:553
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
struct ast_lock_track * track
Definition: lock.h:124
Definition: logger.h:267
#define pthread_mutex_lock
Definition: lock.h:556
#define ROFFSET
Definition: lock.h:208
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
#define AST_MAX_REENTRANCY
Definition: lock.h:100
int ast_bt_get_addresses(struct ast_bt *bt)
Definition: logger.c:1319
pthread_mutex_t mutex
Definition: lock.h:122
#define pthread_mutex_trylock
Definition: lock.h:558
int __ast_pthread_mutex_trylock ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 317 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().

319 {
320  int res;
321 
322 #ifdef DEBUG_THREADS
323  struct ast_lock_track *lt;
324  int canlog = strcmp(filename, "logger.c") & t->tracking;
325 #ifdef HAVE_BKTR
326  struct ast_bt *bt = NULL;
327 #endif
328 
329 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
330  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
331  /* Don't warn abount uninitialized mutex.
332  * Simple try to initialize it.
333  * May be not needed in linux system.
334  */
335  res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
336  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
337  __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
338  filename, lineno, func, mutex_name);
339  return res;
340  }
341  }
342 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
343 
344  if (t->tracking && !t->track) {
345  ast_reentrancy_init(&t->track);
346  }
347  lt = t->track;
348 
349  if (t->tracking) {
350 #ifdef HAVE_BKTR
351  struct ast_bt tmp;
352 
353  /* The implementation of backtrace() may have its own locks.
354  * Capture the backtrace outside of the reentrancy lock to
355  * avoid deadlocks. See ASTERISK-22455. */
356  ast_bt_get_addresses(&tmp);
357 
358  ast_reentrancy_lock(lt);
359  if (lt->reentrancy != AST_MAX_REENTRANCY) {
360  lt->backtrace[lt->reentrancy] = tmp;
361  bt = &lt->backtrace[lt->reentrancy];
362  }
363  ast_reentrancy_unlock(lt);
364 
365  ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
366 #else
367  ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
368 #endif
369  }
370 #endif /* DEBUG_THREADS */
371 
372  res = pthread_mutex_trylock(&t->mutex);
373 
374 #ifdef DEBUG_THREADS
375  if (t->tracking && !res) {
376  ast_reentrancy_lock(lt);
377  if (lt->reentrancy < AST_MAX_REENTRANCY) {
378  lt->file[lt->reentrancy] = filename;
379  lt->lineno[lt->reentrancy] = lineno;
380  lt->func[lt->reentrancy] = func;
381  lt->thread[lt->reentrancy] = pthread_self();
382  lt->reentrancy++;
383  } else {
384  __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
385  filename, lineno, func, mutex_name);
386  }
387  ast_reentrancy_unlock(lt);
388  if (t->tracking) {
389  ast_mark_lock_acquired(t);
390  }
391  } else if (t->tracking) {
392  ast_mark_lock_failed(t);
393  }
394 #endif /* DEBUG_THREADS */
395 
396  return res;
397 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
unsigned int tracking
Definition: lock.h:125
int reentrancy
Definition: lock.h:107
int __ast_pthread_mutex_init(int tracking, const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
Definition: lock.c:65
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
#define pthread_mutex_t
Definition: lock.h:553
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
struct ast_lock_track * track
Definition: lock.h:124
Definition: logger.h:267
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
#define AST_MAX_REENTRANCY
Definition: lock.h:100
int ast_bt_get_addresses(struct ast_bt *bt)
Definition: logger.c:1319
pthread_mutex_t mutex
Definition: lock.h:122
#define pthread_mutex_trylock
Definition: lock.h:558
int __ast_pthread_mutex_unlock ( const char *  filename,
int  lineno,
const char *  func,
const char *  mutex_name,
ast_mutex_t t 
)

Definition at line 399 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().

401 {
402  int res;
403 
404 #ifdef DEBUG_THREADS
405  struct ast_lock_track *lt;
406  int canlog = strcmp(filename, "logger.c") & t->tracking;
407 #ifdef HAVE_BKTR
408  struct ast_bt *bt = NULL;
409 #endif
410 
411 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
412  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
413  __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
414  filename, lineno, func, mutex_name);
415  res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
416  if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
417  __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
418  filename, lineno, func, mutex_name);
419  }
420  return res;
421  }
422 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
423 
424  if (t->tracking && !t->track) {
425  ast_reentrancy_init(&t->track);
426  }
427  lt = t->track;
428 
429  if (t->tracking) {
430  ast_reentrancy_lock(lt);
431  if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
432  __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
433  filename, lineno, func, mutex_name);
434  __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
435  lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
436 #ifdef HAVE_BKTR
437  __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
438 #endif
439  DO_THREAD_CRASH;
440  }
441 
442  if (--lt->reentrancy < 0) {
443  __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
444  filename, lineno, func, mutex_name);
445  lt->reentrancy = 0;
446  }
447 
448  if (lt->reentrancy < AST_MAX_REENTRANCY) {
449  lt->file[lt->reentrancy] = NULL;
450  lt->lineno[lt->reentrancy] = 0;
451  lt->func[lt->reentrancy] = NULL;
452  lt->thread[lt->reentrancy] = 0;
453  }
454 
455 #ifdef HAVE_BKTR
456  if (lt->reentrancy) {
457  bt = &lt->backtrace[lt->reentrancy - 1];
458  }
459 #endif
460  ast_reentrancy_unlock(lt);
461 
462 #ifdef HAVE_BKTR
463  ast_remove_lock_info(t, bt);
464 #else
465  ast_remove_lock_info(t);
466 #endif
467  }
468 #endif /* DEBUG_THREADS */
469 
470  res = pthread_mutex_unlock(&t->mutex);
471 
472 #ifdef DEBUG_THREADS
473  if (res) {
474  __ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n",
475  filename, lineno, func, strerror(res));
476  DO_THREAD_CRASH;
477  }
478 #endif /* DEBUG_THREADS */
479 
480  return res;
481 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
unsigned int tracking
Definition: lock.h:125
int reentrancy
Definition: lock.h:107
int __ast_pthread_mutex_init(int tracking, const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
Definition: lock.c:65
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
#define pthread_mutex_t
Definition: lock.h:553
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
struct ast_lock_track * track
Definition: lock.h:124
Definition: logger.h:267
#define ROFFSET
Definition: lock.h:208
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
#define AST_MAX_REENTRANCY
Definition: lock.h:100
pthread_mutex_t mutex
Definition: lock.h:122
#define pthread_mutex_unlock
Definition: lock.h:557
int __ast_rwlock_destroy ( const char *  filename,
int  lineno,
const char *  func,
const char *  rwlock_name,
ast_rwlock_t t 
)

Definition at line 703 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.

704 {
705  int res;
706 
707 #ifdef DEBUG_THREADS
708  struct ast_lock_track *lt = t->track;
709  int canlog = strcmp(filename, "logger.c") & t->tracking;
710 
711 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
712  if (t->lock == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
713  __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
714  filename, lineno, func, rwlock_name);
715  return 0;
716  }
717 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
718 
719 #endif /* DEBUG_THREADS */
720 
721  res = pthread_rwlock_destroy(&t->lock);
722 
723 #ifdef DEBUG_THREADS
724  if (res) {
725  __ast_mutex_logger("%s line %d (%s): Error destroying rwlock %s: %s\n",
726  filename, lineno, func, rwlock_name, strerror(res));
727  }
728  if (t->tracking && lt) {
729  ast_reentrancy_lock(lt);
730  lt->file[0] = filename;
731  lt->lineno[0] = lineno;
732  lt->func[0] = func;
733  lt->reentrancy = 0;
734  lt->thread[0] = 0;
735 #ifdef HAVE_BKTR
736  memset(&lt->backtrace[0], 0, sizeof(lt->backtrace[0]));
737 #endif
738  ast_reentrancy_unlock(lt);
739  delete_reentrancy_cs(&t->track);
740  }
741 #endif /* DEBUG_THREADS */
742 
743  return res;
744 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:83
int reentrancy
Definition: lock.h:107
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
unsigned int tracking
Definition: lock.h:137
pthread_rwlock_t lock
Definition: lock.h:134
struct ast_lock_track * track
Definition: lock.h:136
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 670 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().

671 {
672  int res;
673  pthread_rwlockattr_t attr;
674 
675 #ifdef DEBUG_THREADS
676 
677 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
678  int canlog = strcmp(filename, "logger.c") & t->tracking;
679 
680  if (t->lock != ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
681  __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is already initialized.\n",
682  filename, lineno, func, rwlock_name);
683  return 0;
684  }
685 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
686 
687  if ((t->tracking = tracking)) {
688  ast_reentrancy_init(&t->track);
689  }
690 #endif /* DEBUG_THREADS */
691 
692  pthread_rwlockattr_init(&attr);
693 
694 #ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
695  pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP);
696 #endif
697 
698  res = pthread_rwlock_init(&t->lock, &attr);
699  pthread_rwlockattr_destroy(&attr);
700  return res;
701 }
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:83
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
unsigned int tracking
Definition: lock.h:137
pthread_rwlock_t lock
Definition: lock.h:134
struct ast_lock_track * track
Definition: lock.h:136
int __ast_rwlock_rdlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 832 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().

833 {
834  int res;
835 
836 #ifdef DEBUG_THREADS
837  struct ast_lock_track *lt;
838  int canlog = strcmp(filename, "logger.c") & t->tracking;
839 #ifdef HAVE_BKTR
840  struct ast_bt *bt = NULL;
841 #endif
842 
843 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
844  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
845  /* Don't warn abount uninitialized lock.
846  * Simple try to initialize it.
847  * May be not needed in linux system.
848  */
849  res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
850  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
851  __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
852  filename, line, func, name);
853  return res;
854  }
855  }
856 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
857 
858  if (t->tracking && !t->track) {
859  ast_reentrancy_init(&t->track);
860  }
861  lt = t->track;
862 
863  if (t->tracking) {
864 #ifdef HAVE_BKTR
865  struct ast_bt tmp;
866 
867  /* The implementation of backtrace() may have its own locks.
868  * Capture the backtrace outside of the reentrancy lock to
869  * avoid deadlocks. See ASTERISK-22455. */
870  ast_bt_get_addresses(&tmp);
871 
872  ast_reentrancy_lock(lt);
873  if (lt->reentrancy != AST_MAX_REENTRANCY) {
874  lt->backtrace[lt->reentrancy] = tmp;
875  bt = &lt->backtrace[lt->reentrancy];
876  }
877  ast_reentrancy_unlock(lt);
878 
879  ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
880 #else
881  ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
882 #endif
883  }
884 #endif /* DEBUG_THREADS */
885 
886 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
887  {
888  time_t seconds = time(NULL);
889  time_t wait_time, reported_wait = 0;
890  do {
891  res = pthread_rwlock_tryrdlock(&t->lock);
892  if (res == EBUSY) {
893  wait_time = time(NULL) - seconds;
894  if (wait_time > reported_wait && (wait_time % 5) == 0) {
895  __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for readlock '%s'?\n",
896  filename, line, func, (int)wait_time, name);
897  if (t->tracking) {
898  ast_reentrancy_lock(lt);
899 #ifdef HAVE_BKTR
900  __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
901 #endif
902  __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
903  lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
904  lt->func[lt->reentrancy-1], name);
905 #ifdef HAVE_BKTR
906  __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
907 #endif
908  ast_reentrancy_unlock(lt);
909  }
910  reported_wait = wait_time;
911  }
912  usleep(200);
913  }
914  } while (res == EBUSY);
915  }
916 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
917  res = pthread_rwlock_rdlock(&t->lock);
918 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
919 
920 #ifdef DEBUG_THREADS
921  if (!res && t->tracking) {
922  ast_reentrancy_lock(lt);
923  if (lt->reentrancy < AST_MAX_REENTRANCY) {
924  lt->file[lt->reentrancy] = filename;
925  lt->lineno[lt->reentrancy] = line;
926  lt->func[lt->reentrancy] = func;
927  lt->thread[lt->reentrancy] = pthread_self();
928  lt->reentrancy++;
929  }
930  ast_reentrancy_unlock(lt);
931  if (t->tracking) {
932  ast_mark_lock_acquired(t);
933  }
934  } else if (t->tracking) {
935 #ifdef HAVE_BKTR
936  if (lt->reentrancy) {
937  ast_reentrancy_lock(lt);
938  bt = &lt->backtrace[lt->reentrancy-1];
939  ast_reentrancy_unlock(lt);
940  } else {
941  bt = NULL;
942  }
943  ast_remove_lock_info(t, bt);
944 #else
945  ast_remove_lock_info(t);
946 #endif
947  }
948 
949  if (res) {
950  __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
951  filename, line, func, strerror(res));
952  DO_THREAD_CRASH;
953  }
954 #endif /* DEBUG_THREADS */
955 
956  return res;
957 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:83
int reentrancy
Definition: lock.h:107
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
Definition: logger.h:267
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
static const char name[]
unsigned int tracking
Definition: lock.h:137
#define AST_MAX_REENTRANCY
Definition: lock.h:100
int __ast_rwlock_init(int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
Definition: lock.c:670
int ast_bt_get_addresses(struct ast_bt *bt)
Definition: logger.c:1319
pthread_rwlock_t lock
Definition: lock.h:134
struct ast_lock_track * track
Definition: lock.h:136
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_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.

1091 {
1092  int res;
1093 
1094 #ifdef DEBUG_THREADS
1095  struct ast_lock_track *lt;
1096  int canlog = strcmp(filename, "logger.c") & t->tracking;
1097 #ifdef HAVE_BKTR
1098  struct ast_bt *bt = NULL;
1099 #endif
1100 
1101 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
1102  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
1103  /* Don't warn abount uninitialized lock.
1104  * Simple try to initialize it.
1105  * May be not needed in linux system.
1106  */
1107  res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
1108  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
1109  __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
1110  filename, line, func, name);
1111  return res;
1112  }
1113  }
1114 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
1115 
1116  if (t->tracking && !t->track) {
1117  ast_reentrancy_init(&t->track);
1118  }
1119  lt = t->track;
1120 
1121  if (t->tracking) {
1122 #ifdef HAVE_BKTR
1123  struct ast_bt tmp;
1124 
1125  /* The implementation of backtrace() may have its own locks.
1126  * Capture the backtrace outside of the reentrancy lock to
1127  * avoid deadlocks. See ASTERISK-22455. */
1128  ast_bt_get_addresses(&tmp);
1129 
1130  ast_reentrancy_lock(lt);
1131  if (lt->reentrancy != AST_MAX_REENTRANCY) {
1132  lt->backtrace[lt->reentrancy] = tmp;
1133  bt = &lt->backtrace[lt->reentrancy];
1134  }
1135  ast_reentrancy_unlock(lt);
1136 
1137  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
1138 #else
1139  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
1140 #endif
1141  }
1142 #endif /* DEBUG_THREADS */
1143 
1144 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
1145  res = pthread_rwlock_timedrdlock(&t->lock, abs_timeout);
1146 #else
1147  do {
1148  struct timeval _now;
1149  for (;;) {
1150  if (!(res = pthread_rwlock_tryrdlock(&t->lock))) {
1151  break;
1152  }
1153  _now = ast_tvnow();
1154  if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
1155  break;
1156  }
1157  usleep(1);
1158  }
1159  } while (0);
1160 #endif
1161 
1162 #ifdef DEBUG_THREADS
1163  if (!res && t->tracking) {
1164  ast_reentrancy_lock(lt);
1165  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1166  lt->file[lt->reentrancy] = filename;
1167  lt->lineno[lt->reentrancy] = line;
1168  lt->func[lt->reentrancy] = func;
1169  lt->thread[lt->reentrancy] = pthread_self();
1170  lt->reentrancy++;
1171  }
1172  ast_reentrancy_unlock(lt);
1173  if (t->tracking) {
1174  ast_mark_lock_acquired(t);
1175  }
1176  } else if (t->tracking) {
1177 #ifdef HAVE_BKTR
1178  if (lt->reentrancy) {
1179  ast_reentrancy_lock(lt);
1180  bt = &lt->backtrace[lt->reentrancy-1];
1181  ast_reentrancy_unlock(lt);
1182  } else {
1183  bt = NULL;
1184  }
1185  ast_remove_lock_info(t, bt);
1186 #else
1187  ast_remove_lock_info(t);
1188 #endif
1189  }
1190  if (res) {
1191  __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
1192  filename, line, func, strerror(res));
1193  DO_THREAD_CRASH;
1194  }
1195 #endif /* DEBUG_THREADS */
1196 
1197  return res;
1198 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:83
int reentrancy
Definition: lock.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
Definition: logger.h:267
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
static const char name[]
unsigned int tracking
Definition: lock.h:137
#define AST_MAX_REENTRANCY
Definition: lock.h:100
int __ast_rwlock_init(int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
Definition: lock.c:670
int ast_bt_get_addresses(struct ast_bt *bt)
Definition: logger.c:1319
pthread_rwlock_t lock
Definition: lock.h:134
struct ast_lock_track * track
Definition: lock.h:136
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 1200 of file lock.c.

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

1202 {
1203  int res;
1204 
1205 #ifdef DEBUG_THREADS
1206  struct ast_lock_track *lt;
1207  int canlog = strcmp(filename, "logger.c") & t->tracking;
1208 #ifdef HAVE_BKTR
1209  struct ast_bt *bt = NULL;
1210 #endif
1211 
1212 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
1213  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
1214  /* Don't warn abount uninitialized lock.
1215  * Simple try to initialize it.
1216  * May be not needed in linux system.
1217  */
1218  res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
1219  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
1220  __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
1221  filename, line, func, name);
1222  return res;
1223  }
1224  }
1225 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
1226 
1227  if (t->tracking && !t->track) {
1228  ast_reentrancy_init(&t->track);
1229  }
1230  lt = t->track;
1231 
1232  if (t->tracking) {
1233 #ifdef HAVE_BKTR
1234  struct ast_bt tmp;
1235 
1236  /* The implementation of backtrace() may have its own locks.
1237  * Capture the backtrace outside of the reentrancy lock to
1238  * avoid deadlocks. See ASTERISK-22455. */
1239  ast_bt_get_addresses(&tmp);
1240 
1241  ast_reentrancy_lock(lt);
1242  if (lt->reentrancy != AST_MAX_REENTRANCY) {
1243  lt->backtrace[lt->reentrancy] = tmp;
1244  bt = &lt->backtrace[lt->reentrancy];
1245  }
1246  ast_reentrancy_unlock(lt);
1247 
1248  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
1249 #else
1250  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
1251 #endif
1252  }
1253 #endif /* DEBUG_THREADS */
1254 
1255 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
1256  res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout);
1257 #else
1258  do {
1259  struct timeval _now;
1260  for (;;) {
1261  if (!(res = pthread_rwlock_trywrlock(&t->lock))) {
1262  break;
1263  }
1264  _now = ast_tvnow();
1265  if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
1266  break;
1267  }
1268  usleep(1);
1269  }
1270  } while (0);
1271 #endif
1272 
1273 #ifdef DEBUG_THREADS
1274  if (!res && t->tracking) {
1275  ast_reentrancy_lock(lt);
1276  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1277  lt->file[lt->reentrancy] = filename;
1278  lt->lineno[lt->reentrancy] = line;
1279  lt->func[lt->reentrancy] = func;
1280  lt->thread[lt->reentrancy] = pthread_self();
1281  lt->reentrancy++;
1282  }
1283  ast_reentrancy_unlock(lt);
1284  if (t->tracking) {
1285  ast_mark_lock_acquired(t);
1286  }
1287  } else if (t->tracking) {
1288 #ifdef HAVE_BKTR
1289  if (lt->reentrancy) {
1290  ast_reentrancy_lock(lt);
1291  bt = &lt->backtrace[lt->reentrancy-1];
1292  ast_reentrancy_unlock(lt);
1293  } else {
1294  bt = NULL;
1295  }
1296  if (t->tracking) {
1297  ast_remove_lock_info(t, bt);
1298  }
1299 #else
1300  if (t->tracking) {
1301  ast_remove_lock_info(t);
1302  }
1303 #endif
1304  }
1305  if (res) {
1306  __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
1307  filename, line, func, strerror(res));
1308  DO_THREAD_CRASH;
1309  }
1310 #endif /* DEBUG_THREADS */
1311 
1312  return res;
1313 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:83
int reentrancy
Definition: lock.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
Definition: logger.h:267
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
static const char name[]
unsigned int tracking
Definition: lock.h:137
#define AST_MAX_REENTRANCY
Definition: lock.h:100
int __ast_rwlock_init(int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
Definition: lock.c:670
int ast_bt_get_addresses(struct ast_bt *bt)
Definition: logger.c:1319
pthread_rwlock_t lock
Definition: lock.h:134
struct ast_lock_track * track
Definition: lock.h:136
int __ast_rwlock_tryrdlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 1315 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.

1316 {
1317  int res;
1318 
1319 #ifdef DEBUG_THREADS
1320  struct ast_lock_track *lt;
1321 #ifdef HAVE_BKTR
1322  struct ast_bt *bt = NULL;
1323 #endif
1324 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
1325  int canlog = strcmp(filename, "logger.c") & t->tracking;
1326 
1327  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
1328  /* Don't warn abount uninitialized lock.
1329  * Simple try to initialize it.
1330  * May be not needed in linux system.
1331  */
1332  res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
1333  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
1334  __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
1335  filename, line, func, name);
1336  return res;
1337  }
1338  }
1339 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
1340 
1341  if (t->tracking && !t->track) {
1342  ast_reentrancy_init(&t->track);
1343  }
1344  lt = t->track;
1345 
1346  if (t->tracking) {
1347 #ifdef HAVE_BKTR
1348  struct ast_bt tmp;
1349 
1350  /* The implementation of backtrace() may have its own locks.
1351  * Capture the backtrace outside of the reentrancy lock to
1352  * avoid deadlocks. See ASTERISK-22455. */
1353  ast_bt_get_addresses(&tmp);
1354 
1355  ast_reentrancy_lock(lt);
1356  if (lt->reentrancy != AST_MAX_REENTRANCY) {
1357  lt->backtrace[lt->reentrancy] = tmp;
1358  bt = &lt->backtrace[lt->reentrancy];
1359  }
1360  ast_reentrancy_unlock(lt);
1361 
1362  ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
1363 #else
1364  ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
1365 #endif
1366  }
1367 #endif /* DEBUG_THREADS */
1368 
1369  res = pthread_rwlock_tryrdlock(&t->lock);
1370 
1371 #ifdef DEBUG_THREADS
1372  if (!res && t->tracking) {
1373  ast_reentrancy_lock(lt);
1374  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1375  lt->file[lt->reentrancy] = filename;
1376  lt->lineno[lt->reentrancy] = line;
1377  lt->func[lt->reentrancy] = func;
1378  lt->thread[lt->reentrancy] = pthread_self();
1379  lt->reentrancy++;
1380  }
1381  ast_reentrancy_unlock(lt);
1382  if (t->tracking) {
1383  ast_mark_lock_acquired(t);
1384  }
1385  } else if (t->tracking) {
1386  ast_mark_lock_failed(t);
1387  }
1388 #endif /* DEBUG_THREADS */
1389 
1390  return res;
1391 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:83
int reentrancy
Definition: lock.h:107
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
Definition: logger.h:267
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
static const char name[]
unsigned int tracking
Definition: lock.h:137
#define AST_MAX_REENTRANCY
Definition: lock.h:100
int __ast_rwlock_init(int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
Definition: lock.c:670
int ast_bt_get_addresses(struct ast_bt *bt)
Definition: logger.c:1319
pthread_rwlock_t lock
Definition: lock.h:134
struct ast_lock_track * track
Definition: lock.h:136
int __ast_rwlock_trywrlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 1393 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.

1394 {
1395  int res;
1396 
1397 #ifdef DEBUG_THREADS
1398  struct ast_lock_track *lt;
1399 #ifdef HAVE_BKTR
1400  struct ast_bt *bt = NULL;
1401 #endif
1402 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
1403  int canlog = strcmp(filename, "logger.c") & t->tracking;
1404 
1405  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
1406  /* Don't warn abount uninitialized lock.
1407  * Simple try to initialize it.
1408  * May be not needed in linux system.
1409  */
1410  res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
1411  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
1412  __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
1413  filename, line, func, name);
1414  return res;
1415  }
1416  }
1417 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
1418 
1419  if (t->tracking && !t->track) {
1420  ast_reentrancy_init(&t->track);
1421  }
1422  lt = t->track;
1423 
1424  if (t->tracking) {
1425 #ifdef HAVE_BKTR
1426  struct ast_bt tmp;
1427 
1428  /* The implementation of backtrace() may have its own locks.
1429  * Capture the backtrace outside of the reentrancy lock to
1430  * avoid deadlocks. See ASTERISK-22455. */
1431  ast_bt_get_addresses(&tmp);
1432 
1433  ast_reentrancy_lock(lt);
1434  if (lt->reentrancy != AST_MAX_REENTRANCY) {
1435  lt->backtrace[lt->reentrancy] = tmp;
1436  bt = &lt->backtrace[lt->reentrancy];
1437  }
1438  ast_reentrancy_unlock(lt);
1439 
1440  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
1441 #else
1442  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
1443 #endif
1444  }
1445 #endif /* DEBUG_THREADS */
1446 
1447  res = pthread_rwlock_trywrlock(&t->lock);
1448 
1449 #ifdef DEBUG_THREADS
1450  if (!res && t->tracking) {
1451  ast_reentrancy_lock(lt);
1452  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1453  lt->file[lt->reentrancy] = filename;
1454  lt->lineno[lt->reentrancy] = line;
1455  lt->func[lt->reentrancy] = func;
1456  lt->thread[lt->reentrancy] = pthread_self();
1457  lt->reentrancy++;
1458  }
1459  ast_reentrancy_unlock(lt);
1460  ast_mark_lock_acquired(t);
1461  } else if (t->tracking) {
1462  ast_mark_lock_failed(t);
1463  }
1464 #endif /* DEBUG_THREADS */
1465 
1466  return res;
1467 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:83
int reentrancy
Definition: lock.h:107
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
Definition: logger.h:267
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
static const char name[]
unsigned int tracking
Definition: lock.h:137
#define AST_MAX_REENTRANCY
Definition: lock.h:100
int __ast_rwlock_init(int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
Definition: lock.c:670
int ast_bt_get_addresses(struct ast_bt *bt)
Definition: logger.c:1319
pthread_rwlock_t lock
Definition: lock.h:134
struct ast_lock_track * track
Definition: lock.h:136
int __ast_rwlock_unlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 746 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().

747 {
748  int res;
749 
750 #ifdef DEBUG_THREADS
751  struct ast_lock_track *lt;
752  int canlog = strcmp(filename, "logger.c") & t->tracking;
753 #ifdef HAVE_BKTR
754  struct ast_bt *bt = NULL;
755 #endif
756  int lock_found = 0;
757 
758 
759 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
760  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
761  __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",
762  filename, line, func, name);
763  res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
764  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
765  __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
766  filename, line, func, name);
767  }
768  return res;
769  }
770 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
771 
772  if (t->tracking && !t->track) {
773  ast_reentrancy_init(&t->track);
774  }
775  lt = t->track;
776 
777  if (t->tracking) {
778  ast_reentrancy_lock(lt);
779  if (lt->reentrancy) {
780  int i;
781  pthread_t self = pthread_self();
782  for (i = lt->reentrancy - 1; i >= 0; --i) {
783  if (lt->thread[i] == self) {
784  lock_found = 1;
785  if (i != lt->reentrancy - 1) {
786  lt->file[i] = lt->file[lt->reentrancy - 1];
787  lt->lineno[i] = lt->lineno[lt->reentrancy - 1];
788  lt->func[i] = lt->func[lt->reentrancy - 1];
789  lt->thread[i] = lt->thread[lt->reentrancy - 1];
790  }
791 #ifdef HAVE_BKTR
792  bt = &lt->backtrace[i];
793 #endif
794  lt->file[lt->reentrancy - 1] = NULL;
795  lt->lineno[lt->reentrancy - 1] = 0;
796  lt->func[lt->reentrancy - 1] = NULL;
797  lt->thread[lt->reentrancy - 1] = AST_PTHREADT_NULL;
798  break;
799  }
800  }
801  }
802 
803  if (lock_found && --lt->reentrancy < 0) {
804  __ast_mutex_logger("%s line %d (%s): rwlock '%s' freed more times than we've locked!\n",
805  filename, line, func, name);
806  lt->reentrancy = 0;
807  }
808 
809  ast_reentrancy_unlock(lt);
810 
811 #ifdef HAVE_BKTR
812  ast_remove_lock_info(t, bt);
813 #else
814  ast_remove_lock_info(t);
815 #endif
816  }
817 #endif /* DEBUG_THREADS */
818 
819  res = pthread_rwlock_unlock(&t->lock);
820 
821 #ifdef DEBUG_THREADS
822  if (res) {
823  __ast_mutex_logger("%s line %d (%s): Error releasing rwlock: %s\n",
824  filename, line, func, strerror(res));
825  DO_THREAD_CRASH;
826  }
827 #endif /* DEBUG_THREADS */
828 
829  return res;
830 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:83
int reentrancy
Definition: lock.h:107
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
Definition: logger.h:267
#define AST_PTHREADT_NULL
Definition: lock.h:65
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
static const char name[]
unsigned int tracking
Definition: lock.h:137
int __ast_rwlock_init(int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
Definition: lock.c:670
pthread_rwlock_t lock
Definition: lock.h:134
struct ast_lock_track * track
Definition: lock.h:136
int __ast_rwlock_wrlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name 
)

Definition at line 959 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().

960 {
961  int res;
962 
963 #ifdef DEBUG_THREADS
964  struct ast_lock_track *lt;
965  int canlog = strcmp(filename, "logger.c") & t->tracking;
966 #ifdef HAVE_BKTR
967  struct ast_bt *bt = NULL;
968 #endif
969 
970 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
971  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
972  /* Don't warn abount uninitialized lock.
973  * Simple try to initialize it.
974  * May be not needed in linux system.
975  */
976  res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
977  if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
978  __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
979  filename, line, func, name);
980  return res;
981  }
982  }
983 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
984 
985  if (t->tracking && !t->track) {
986  ast_reentrancy_init(&t->track);
987  }
988  lt = t->track;
989 
990  if (t->tracking) {
991 #ifdef HAVE_BKTR
992  struct ast_bt tmp;
993 
994  /* The implementation of backtrace() may have its own locks.
995  * Capture the backtrace outside of the reentrancy lock to
996  * avoid deadlocks. See ASTERISK-22455. */
997  ast_bt_get_addresses(&tmp);
998 
999  ast_reentrancy_lock(lt);
1000  if (lt->reentrancy != AST_MAX_REENTRANCY) {
1001  lt->backtrace[lt->reentrancy] = tmp;
1002  bt = &lt->backtrace[lt->reentrancy];
1003  }
1004  ast_reentrancy_unlock(lt);
1005 
1006  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
1007 #else
1008  ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
1009 #endif
1010  }
1011 #endif /* DEBUG_THREADS */
1012 
1013 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
1014  {
1015  time_t seconds = time(NULL);
1016  time_t wait_time, reported_wait = 0;
1017  do {
1018  res = pthread_rwlock_trywrlock(&t->lock);
1019  if (res == EBUSY) {
1020  wait_time = time(NULL) - seconds;
1021  if (wait_time > reported_wait && (wait_time % 5) == 0) {
1022  __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for writelock '%s'?\n",
1023  filename, line, func, (int)wait_time, name);
1024  if (t->tracking) {
1025  ast_reentrancy_lock(lt);
1026 #ifdef HAVE_BKTR
1027  __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
1028 #endif
1029  __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
1030  lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
1031  lt->func[lt->reentrancy-1], name);
1032 #ifdef HAVE_BKTR
1033  __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
1034 #endif
1035  ast_reentrancy_unlock(lt);
1036  }
1037  reported_wait = wait_time;
1038  }
1039  usleep(200);
1040  }
1041  } while (res == EBUSY);
1042  }
1043 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
1044  res = pthread_rwlock_wrlock(&t->lock);
1045 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
1046 
1047 #ifdef DEBUG_THREADS
1048  if (!res && t->tracking) {
1049  ast_reentrancy_lock(lt);
1050  if (lt->reentrancy < AST_MAX_REENTRANCY) {
1051  lt->file[lt->reentrancy] = filename;
1052  lt->lineno[lt->reentrancy] = line;
1053  lt->func[lt->reentrancy] = func;
1054  lt->thread[lt->reentrancy] = pthread_self();
1055  lt->reentrancy++;
1056  }
1057  ast_reentrancy_unlock(lt);
1058  if (t->tracking) {
1059  ast_mark_lock_acquired(t);
1060  }
1061  } else if (t->tracking) {
1062 #ifdef HAVE_BKTR
1063  if (lt->reentrancy) {
1064  ast_reentrancy_lock(lt);
1065  bt = &lt->backtrace[lt->reentrancy-1];
1066  ast_reentrancy_unlock(lt);
1067  } else {
1068  bt = NULL;
1069  }
1070  if (t->tracking) {
1071  ast_remove_lock_info(t, bt);
1072  }
1073 #else
1074  if (t->tracking) {
1075  ast_remove_lock_info(t);
1076  }
1077 #endif
1078  }
1079  if (res) {
1080  __ast_mutex_logger("%s line %d (%s): Error obtaining write lock: %s\n",
1081  filename, line, func, strerror(res));
1082  DO_THREAD_CRASH;
1083  }
1084 #endif /* DEBUG_THREADS */
1085 
1086  return res;
1087 }
pthread_t thread[AST_MAX_REENTRANCY]
Definition: lock.h:109
const char * file[AST_MAX_REENTRANCY]
Definition: lock.h:105
#define __AST_RWLOCK_INIT_VALUE
Definition: lock.h:83
int reentrancy
Definition: lock.h:107
int lineno[AST_MAX_REENTRANCY]
Definition: lock.h:106
struct ast_bt backtrace[AST_MAX_REENTRANCY]
Definition: lock.h:111
Definition: logger.h:267
const char * func[AST_MAX_REENTRANCY]
Definition: lock.h:108
static const char name[]
unsigned int tracking
Definition: lock.h:137
#define AST_MAX_REENTRANCY
Definition: lock.h:100
int __ast_rwlock_init(int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
Definition: lock.c:670
int ast_bt_get_addresses(struct ast_bt *bt)
Definition: logger.c:1319
pthread_rwlock_t lock
Definition: lock.h:134
struct ast_lock_track * track
Definition: lock.h:136
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().

652 {
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_channel_destructor(), ast_cli_command_full(), ast_dial_append(), ast_event_subscribe_new(), ast_module_ref(), ast_module_unref(), ast_undestroyed_channels(), 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(), local_new(), 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(), smdi_msg_retrieve_read(), spandsp_fax_switch_to_t38(), temp_peer(), and update_stats().

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

Definition at line 2078 of file utils.c.

References ast_mutex_lock, ast_mutex_unlock, and fetchadd_m.

2079 {
2080  int ret;
2082  ret = *p;
2083  *p += v;
2085  return ret;
2086 }
#define ast_mutex_lock(a)
Definition: lock.h:155
static ast_mutex_t fetchadd_m
Definition: utils.c:2076
#define ast_mutex_unlock(a)
Definition: lock.h:156