Sat Apr 26 2014 22:02:55

Asterisk developer's documentation


lock.h File Reference

Asterisk locking-related definitions: More...

#include <pthread.h>
#include <time.h>
#include <sys/param.h>
#include <execinfo.h>
#include "asterisk/logger.h"
#include "asterisk/compiler.h"
#include "asterisk/inline_api.h"
Include dependency graph for lock.h:

Go to the source code of this file.

Data Structures

struct  ast_lock_track
struct  ast_mutex_info
 Structure for mutex and tracking information. More...
struct  ast_rwlock_info
 Structure for rwlock and tracking information. More...

Defines

#define __AST_MUTEX_DEFINE(scope, mutex, init_val, track)   scope ast_mutex_t mutex = init_val
#define __AST_RWLOCK_DEFINE(scope, rwlock, init_val, track)   scope ast_rwlock_t rwlock = init_val
#define __AST_RWLOCK_INIT_VALUE   PTHREAD_RWLOCK_INITIALIZER
#define ast_cond_broadcast(cond)   __ast_cond_broadcast(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define ast_cond_destroy(cond)   __ast_cond_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define ast_cond_init(cond, attr)   __ast_cond_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond, attr)
#define ast_cond_signal(cond)   __ast_cond_signal(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, cond)
#define ast_cond_timedwait(cond, mutex, time)   __ast_cond_timedwait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex, time)
#define ast_cond_wait(cond, mutex)   __ast_cond_wait(__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #mutex, cond, mutex)
#define AST_LOCK_TRACK_INIT_VALUE   { { NULL }, { 0 }, 0, { NULL }, { 0 }, {{{ 0 }}}, PTHREAD_MUTEX_INIT_VALUE }
#define AST_MAX_REENTRANCY   10
#define AST_MUTEX_DEFINE_STATIC(mutex)   __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE, 1)
#define AST_MUTEX_DEFINE_STATIC_NOTRACKING(mutex)   __AST_MUTEX_DEFINE(static, mutex, AST_MUTEX_INIT_VALUE_NOTRACKING, 0)
#define ast_mutex_destroy(a)   __ast_pthread_mutex_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
#define ast_mutex_init(pmutex)   __ast_pthread_mutex_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex)
#define ast_mutex_init_notracking(pmutex)   __ast_pthread_mutex_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #pmutex, pmutex)
#define AST_MUTEX_INIT_VALUE   { PTHREAD_MUTEX_INIT_VALUE, NULL, 1 }
#define AST_MUTEX_INIT_VALUE_NOTRACKING   { PTHREAD_MUTEX_INIT_VALUE, NULL, 0 }
#define AST_MUTEX_INITIALIZER   __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__
#define AST_MUTEX_KIND   PTHREAD_MUTEX_RECURSIVE_NP
#define ast_mutex_lock(a)   __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
#define ast_mutex_trylock(a)   __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
#define ast_mutex_unlock(a)   __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
#define AST_PTHREADT_NULL   (pthread_t) -1
#define AST_PTHREADT_STOP   (pthread_t) -2
#define AST_RWLOCK_DEFINE_STATIC(rwlock)   __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE, 1)
#define AST_RWLOCK_DEFINE_STATIC_NOTRACKING(rwlock)   __AST_RWLOCK_DEFINE(static, rwlock, AST_RWLOCK_INIT_VALUE_NOTRACKING, 0)
#define ast_rwlock_destroy(rwlock)   __ast_rwlock_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
#define ast_rwlock_init(rwlock)   __ast_rwlock_init(1, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
 wrapper for rwlock with tracking enabled
#define ast_rwlock_init_notracking(rwlock)   __ast_rwlock_init(0, __FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
 wrapper for ast_rwlock_init with tracking disabled
#define AST_RWLOCK_INIT_VALUE   { __AST_RWLOCK_INIT_VALUE, NULL, 1 }
#define AST_RWLOCK_INIT_VALUE_NOTRACKING   { __AST_RWLOCK_INIT_VALUE, NULL, 0 }
#define ast_rwlock_rdlock(a)   __ast_rwlock_rdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define ast_rwlock_timedrdlock(a, b)   __ast_rwlock_timedrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a, b)
#define ast_rwlock_timedwrlock(a, b)   __ast_rwlock_timedwrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a, b)
#define ast_rwlock_tryrdlock(a)   __ast_rwlock_tryrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define ast_rwlock_trywrlock(a)   __ast_rwlock_trywrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define ast_rwlock_unlock(a)   __ast_rwlock_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define ast_rwlock_wrlock(a)   __ast_rwlock_wrlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#define CHANNEL_DEADLOCK_AVOIDANCE(chan)
#define DEADLOCK_AVOIDANCE(lock)
#define DLA_LOCK(lock)   ast_mutex_lock(lock)
#define DLA_UNLOCK(lock)   ast_mutex_unlock(lock)
#define gethostbyname   __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__
#define pthread_cond_broadcast   use_ast_cond_broadcast_instead_of_pthread_cond_broadcast
#define pthread_cond_destroy   use_ast_cond_destroy_instead_of_pthread_cond_destroy
#define pthread_cond_init   use_ast_cond_init_instead_of_pthread_cond_init
#define pthread_cond_signal   use_ast_cond_signal_instead_of_pthread_cond_signal
#define pthread_cond_t   use_ast_cond_t_instead_of_pthread_cond_t
#define pthread_cond_timedwait   use_ast_cond_timedwait_instead_of_pthread_cond_timedwait
#define pthread_cond_wait   use_ast_cond_wait_instead_of_pthread_cond_wait
#define pthread_create   __use_ast_pthread_create_instead__
#define pthread_mutex_destroy   use_ast_mutex_destroy_instead_of_pthread_mutex_destroy
#define pthread_mutex_init   use_ast_mutex_init_instead_of_pthread_mutex_init
#define PTHREAD_MUTEX_INIT_VALUE   PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
#define pthread_mutex_lock   use_ast_mutex_lock_instead_of_pthread_mutex_lock
#define pthread_mutex_t   use_ast_mutex_t_instead_of_pthread_mutex_t
#define pthread_mutex_trylock   use_ast_mutex_trylock_instead_of_pthread_mutex_trylock
#define pthread_mutex_unlock   use_ast_mutex_unlock_instead_of_pthread_mutex_unlock
#define ROFFSET   ((lt->reentrancy > 0) ? (lt->reentrancy-1) : 0)

Typedefs

typedef pthread_cond_t ast_cond_t
typedef struct ast_mutex_info ast_mutex_t
typedef struct ast_rwlock_info ast_rwlock_t

Functions

int __ast_cond_broadcast (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond)
int __ast_cond_destroy (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond)
int __ast_cond_init (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond, pthread_condattr_t *cond_attr)
int __ast_cond_signal (const char *filename, int lineno, const char *func, const char *cond_name, ast_cond_t *cond)
int __ast_cond_timedwait (const char *filename, int lineno, const char *func, const char *cond_name, const char *mutex_name, ast_cond_t *cond, ast_mutex_t *t, const struct timespec *abstime)
int __ast_cond_wait (const char *filename, int lineno, const char *func, const char *cond_name, const char *mutex_name, ast_cond_t *cond, ast_mutex_t *t)
int __ast_pthread_mutex_destroy (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_pthread_mutex_init (int tracking, const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_pthread_mutex_lock (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_pthread_mutex_trylock (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_pthread_mutex_unlock (const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t)
int __ast_rwlock_destroy (const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
int __ast_rwlock_init (int tracking, const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t)
int __ast_rwlock_rdlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int __ast_rwlock_timedrdlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name, const struct timespec *abs_timeout)
int __ast_rwlock_timedwrlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name, const struct timespec *abs_timeout)
int __ast_rwlock_tryrdlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int __ast_rwlock_trywrlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int __ast_rwlock_unlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int __ast_rwlock_wrlock (const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
int ast_atomic_dec_and_test (volatile int *p)
 decrement *p by 1 and return true if the variable has reached 0. Useful e.g. to check if a refcount has reached 0.
int ast_atomic_fetchadd_int (volatile int *p, int v)
 Atomically add v to *p and return * the previous value of *p. This can be used to handle reference counts, and the return value can be used to generate unique identifiers.
int ast_atomic_fetchadd_int_slow (volatile int *p, int v)

Detailed Description

Asterisk locking-related definitions:

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

Definition in file lock.h.


Define Documentation

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

Definition at line 523 of file lock.h.

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

Definition at line 546 of file lock.h.

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

Definition at line 89 of file lock.h.

Definition at line 526 of file lock.h.

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.

Definition at line 94 of file lock.h.

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(), _unload_module(), acf_channel_read(), acf_jabberreceive_read(), acl_change_event_cb(), 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(), app_exec(), append_mailbox_mapping(), ast_atomic_fetchadd_int_slow(), 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_deltree(), ast_db_gettree(), ast_db_put(), ast_dial_join(), ast_dnsmgr_changed(), ast_features_reload(), ast_get_enum(), ast_iax2_new(), ast_merge_contexts_and_delete(), ast_monitor_start(), ast_random(), ast_rdlock_contexts(), ast_realtime_is_mapping_defined(), ast_replace_sigchld(), ast_sched_add_variable(), ast_sched_context_destroy(), ast_sched_del(), ast_sched_dump(), ast_sched_report(), ast_sched_runq(), 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_verb_update(), ast_wrlock_contexts(), astdb_atexit(), auth_reject(), authenticate_reply(), auto_hangup(), blr_ebl(), blr_txt(), build_device(), build_profile(), build_reply_digest(), caldav_load_calendar(), can_safely_quit(), cb_events(), cdr_handler(), channel_to_session(), check_availability(), check_beep(), cl_dequeue_chan(), cl_queue_chan(), clear_config_maps(), cli_tps_ping(), close_client(), close_mailbox(), conf_free(), conf_run(), conf_start_record(), conf_stop_record_thread(), 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_sendtext(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dahdi_softhangup_all(), dahdi_unlink(), dahdi_unlink_pri_pvt(), dahdi_unlink_ss7_pvt(), db_create_astdb(), db_get_common(), db_open(), db_sync_thread(), decrease_call_count(), defer_full_frame(), DEFINE_SQL_STATEMENT(), 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(), finish_bookmark(), 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_codec(), 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_database_query(), handle_cli_database_show(), handle_cli_database_showkey(), handle_cli_dialplan_save(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_stats(), handle_cli_misdn_show_channel(), handle_cli_misdn_show_channels(), handle_cli_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_presencechange(), handle_pri_debug(), handle_pri_service_generic(), handle_pri_set_debug_file(), handle_pri_show_debug(), handle_request(), handle_request_do(), handle_speechrecognize(), handle_ss7_block_cic(), handle_ss7_block_linkset(), handle_ss7_unblock_cic(), handle_ss7_unblock_linkset(), handle_statechange(), 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_codec(), 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_message_by_id_helper(), play_sound_helper(), pri_dchannel(), pri_ss_thread(), private_enum_init(), prune_gateways(), pthread_timer_open(), pvt_destructor(), queue_ringing_trunk(), rcv_mac_addr(), realtime_destroy_handler(), realtime_handler(), realtime_ldap_base_ap(), realtime_multi_handler(), realtime_multi_pgsql(), realtime_pgsql(), realtime_store_handler(), realtime_update2_handler(), realtime_update_handler(), record_thread(), 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_run(), sched_thread_destroy(), schedule_calendar_event(), scheduled_destroy(), send_client(), send_command_locked(), send_lagrq(), send_ping(), send_request(), send_retransmit(), set_config(), set_hangup_source_and_cause(), set_pvt_defaults(), set_softmix_bridge_data(), 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(), sig_ss7_available(), sig_ss7_cli_show_channels(), sig_ss7_request(), signal_condition(), sip_reload(), sip_show_settings(), 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(), socket_process_helper(), softmix_bridge_poke(), softmix_bridge_thread(), softmix_bridge_write(), spandsp_fax_cli_show_stats(), speech_background(), sqlite_log(), ss7_linkset(), ss7_start_call(), ssl_lock(), start_network_thread(), start_rtp(), stop_mixmonitor_full(), 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_bysession(), unistim_fixup(), unistim_hangup_clean(), unistim_read(), unistim_register(), unistim_show_devices(), unistim_show_info(), unistim_write(), unistimsock_read(), unload_module(), update2_ldap(), update_ldap(), update_pgsql(), update_registry(), vm_execmain(), vm_instructions_en(), write_cdr(), writefile(), and xmpp_pak_message().

#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(), _unload_module(), acf_channel_read(), acf_jabberreceive_read(), acl_change_event_cb(), 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(), app_exec(), append_mailbox_mapping(), ast_atomic_fetchadd_int_slow(), 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_deltree(), ast_db_gettree(), ast_db_put(), ast_dial_join(), ast_dnsmgr_changed(), ast_features_reload(), ast_get_enum(), ast_iax2_new(), ast_merge_contexts_and_delete(), ast_module_reload(), ast_monitor_start(), ast_random(), ast_realtime_is_mapping_defined(), ast_replace_sigchld(), ast_sched_add_variable(), ast_sched_context_destroy(), ast_sched_del(), ast_sched_dump(), ast_sched_report(), ast_sched_runq(), 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(), ast_verb_update(), astdb_atexit(), auth_reject(), authenticate_reply(), auto_hangup(), blr_ebl(), blr_txt(), build_device(), build_profile(), build_reply_digest(), cache_get_callno_locked(), caldav_load_calendar(), can_safely_quit(), cb_events(), cdr_handler(), chan_ringing(), channel_to_session(), 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(), conf_start_record(), conf_stop_record_thread(), 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_sendtext(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dahdi_softhangup_all(), dahdi_unlink(), dahdi_unlink_pri_pvt(), dahdi_unlink_ss7_pvt(), db_create_astdb(), db_get_common(), db_open(), db_sync_thread(), decrease_call_count(), defer_full_frame(), DEFINE_SQL_STATEMENT(), 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(), finish_bookmark(), 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_codec(), 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_database_query(), handle_cli_database_show(), handle_cli_database_showkey(), handle_cli_dialplan_save(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_stats(), handle_cli_misdn_show_channel(), handle_cli_misdn_show_channels(), handle_cli_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_presencechange(), handle_pri_debug(), handle_pri_service_generic(), handle_pri_set_debug_file(), handle_pri_show_debug(), handle_request(), handle_request_do(), handle_speechrecognize(), handle_ss7_block_cic(), handle_ss7_block_linkset(), handle_ss7_unblock_cic(), handle_ss7_unblock_linkset(), handle_statechange(), hangup_connection(), 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_codec(), 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_message_by_id_helper(), play_sound_helper(), pri_dchannel(), pri_rel(), pri_ss_thread(), private_enum_init(), 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(), record_thread(), 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_run(), sched_thread_destroy(), schedule_calendar_event(), scheduled_destroy(), send_client(), send_command_locked(), send_lagrq(), send_ping(), send_request(), send_retransmit(), set_config(), set_dtmf_payload(), set_hangup_source_and_cause(), set_local_capabilities(), set_peer_capabilities(), set_pvt_defaults(), set_softmix_bridge_data(), 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(), sig_ss7_available(), sig_ss7_cli_show_channels(), sig_ss7_request(), signal_condition(), sip_reload(), sip_show_settings(), 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(), socket_process_helper(), socket_process_meta(), softmix_bridge_poke(), softmix_bridge_thread(), softmix_bridge_write(), spandsp_fax_cli_show_stats(), speech_background(), sqlite_log(), ss7_linkset(), ss7_rel(), ss7_start_call(), ssl_lock(), start_network_thread(), start_rtp(), stop_mixmonitor_full(), 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_bysession(), unistim_fixup(), unistim_hangup_clean(), unistim_read(), unistim_register(), unistim_show_devices(), unistim_show_info(), 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(), write_cdr(), writefile(), and xmpp_pak_message().

#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_full(), ast_presence_state_changed_literal(), ast_safe_fork(), ast_sched_start_thread(), ast_smdi_interface_destroy(), ast_taskprocessor_get(), ast_tcptls_server_start(), ast_tcptls_server_stop(), ast_xmpp_client_disconnect(), autoservice_run(), bridge_channel_join(), bridge_poke(), bridge_thread(), build_calendar(), build_conf(), build_mansession(), calendar_event_notify(), cdr_engine_shutdown(), cleanup_module(), close_logger(), conf_free(), conf_run(), conf_stop_record(), conf_stop_record_thread(), console_verboser(), dahdi_r2_destroy_links(), dahdi_r2_get_link(), dahdi_restart(), dnsmgr_shutdown(), do_reload(), generic_http_callback(), get_input(), handle_call_outgoing(), init_pvt(), inotify_daemon(), join_conference_bridge(), 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(), record_thread(), restart_monitor(), restart_pktc_thread(), sched_thread_destroy(), sig_pri_init_pri(), sig_ss7_init_linkset(), sla_destroy(), sla_load_config(), sla_queue_event_full(), smart_bridge_operation(), smdi_load(), ss7_grab(), start_conf_record_thread(), stop_poll_thread(), stop_stream(), tps_taskprocessor_destroy(), unistim_alloc_sub(), unload_module(), and xmpp_client_alloc().

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

Definition at line 549 of file lock.h.

Definition at line 550 of file lock.h.

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

wrapper for ast_rwlock_init with tracking disabled

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

Definition at line 197 of file lock.h.

Definition at line 97 of file lock.h.

Definition at line 98 of file lock.h.

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

Definition at line 201 of file lock.h.

Referenced by action_messagesend(), ast_adsi_available(), ast_adsi_begin_download(), ast_adsi_channel_restore(), ast_adsi_clear_screen(), ast_adsi_clear_soft_keys(), ast_adsi_connect_session(), ast_adsi_data_mode(), ast_adsi_disconnect_session(), ast_adsi_display(), ast_adsi_download_connect(), ast_adsi_download_disconnect(), ast_adsi_end_download(), ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_input_control(), ast_adsi_input_format(), ast_adsi_load_session(), ast_adsi_load_soft_key(), ast_adsi_print(), ast_adsi_query_cpeid(), ast_adsi_query_cpeinfo(), ast_adsi_read_encoded_dtmf(), ast_adsi_set_keys(), ast_adsi_set_line(), ast_adsi_transmit_message(), ast_adsi_transmit_message_full(), ast_adsi_unload_session(), ast_adsi_voice_mode(), ast_calendar_config_acquire(), ast_format_list_get(), ast_hashtab_get_stats(), ast_hashtab_lookup(), ast_hashtab_lookup_with_hash(), ast_hashtab_rdlock(), ast_hashtab_start_traversal(), ast_msg_send(), ast_rdlock_call_features(), ast_rdlock_context(), ast_rtp_codecs_payload_code(), ast_rtp_codecs_payload_lookup(), ast_rtp_codecs_payloads_default(), ast_rtp_codecs_payloads_set_m_type(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), ast_str_retrieve_variable(), corosync_show_config(), cpg_confchg_cb(), cpg_deliver_cb(), feature_interpret_helper(), feature_request_and_dial(), find_table(), format2index(), get_active_pvt(), get_general_options(), handle_feature_show(), handle_show_globals(), index2format(), manager_log(), msg_send_exec(), msg_tech_cmp(), msg_tech_hash(), pbx_builtin_getvar_helper(), and set_config_flags().

#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 action_messagesend(), add_format2index(), add_static_payload(), ast_adsi_available(), ast_adsi_begin_download(), ast_adsi_channel_restore(), ast_adsi_clear_screen(), ast_adsi_clear_soft_keys(), ast_adsi_connect_session(), ast_adsi_data_mode(), ast_adsi_disconnect_session(), ast_adsi_display(), ast_adsi_download_connect(), ast_adsi_download_disconnect(), ast_adsi_end_download(), ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_input_control(), ast_adsi_input_format(), ast_adsi_install_funcs(), ast_adsi_load_session(), ast_adsi_load_soft_key(), ast_adsi_print(), ast_adsi_query_cpeid(), ast_adsi_query_cpeinfo(), ast_adsi_read_encoded_dtmf(), ast_adsi_set_keys(), ast_adsi_set_line(), ast_adsi_transmit_message(), ast_adsi_transmit_message_full(), ast_adsi_unload_session(), ast_adsi_voice_mode(), ast_calendar_config_acquire(), ast_calendar_config_release(), ast_format_list_get(), ast_hashtab_destroy(), ast_hashtab_end_traversal(), ast_hashtab_get_stats(), ast_hashtab_insert_immediate(), ast_hashtab_insert_safe(), ast_hashtab_lookup(), ast_hashtab_lookup_with_hash(), ast_hashtab_remove_object_via_lookup(), ast_hashtab_remove_this_object(), ast_hashtab_unlock(), ast_msg_send(), ast_msg_tech_unregister(), ast_rtp_codecs_payload_code(), ast_rtp_codecs_payload_lookup(), ast_rtp_codecs_payloads_default(), ast_rtp_codecs_payloads_set_m_type(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_engine_unload_format(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), ast_str_retrieve_variable(), ast_unlock_call_features(), ast_unlock_context(), build_format_list_array(), corosync_show_config(), cpg_confchg_cb(), cpg_deliver_cb(), destroy_pvts(), destroy_table(), feature_interpret_helper(), feature_request_and_dial(), format2index(), get_active_pvt(), get_general_options(), handle_feature_show(), handle_show_globals(), index2format(), load_config(), load_general_config(), load_tech_calendars(), manager_log(), matrix_resize(), msg_send_exec(), msg_tech_cmp(), msg_tech_hash(), 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(), set_next_mime_type(), translate_shutdown(), and unmap_features().

#define CHANNEL_DEADLOCK_AVOIDANCE (   chan)
Value:
ast_channel_unlock(chan); \
   usleep(1); \
   ast_channel_lock(chan);

Definition at line 480 of file lock.h.

Referenced by dahdi_handle_event(), dahdi_read(), 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_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.

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.

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.

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

Definition at line 490 of file lock.c.

References pthread_cond_signal.

int __ast_cond_timedwait ( const char *  filename,
int  lineno,
const char *  func,
const char *  cond_name,
const char *  mutex_name,
ast_cond_t cond,
ast_mutex_t t,
const struct timespec *  abstime 
)

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

{
   int res;

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

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

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

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

      /* Waiting on a condition completely suspends a recursive mutex,
       * even if it's been recursively locked multiple times. Make a
       * copy of the lock tracking, and reset reentrancy to zero */
      lt_orig = *lt;
      lt->reentrancy = 0;
      ast_reentrancy_unlock(lt);

      ast_suspend_lock_info(t);
   }
#endif /* DEBUG_THREADS */

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

#ifdef DEBUG_THREADS
   if (res && (res != ETIMEDOUT)) {
      __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
               filename, lineno, func, strerror(res));
      DO_THREAD_CRASH;
   } else if (t->tracking) {
      pthread_mutex_t reentr_mutex_orig;
      ast_reentrancy_lock(lt);
      /* Restore lock tracking to what it was prior to the wait */
      reentr_mutex_orig = lt->reentr_mutex;
      *lt = lt_orig;
      /* un-trash the mutex we just copied over */
      lt->reentr_mutex = reentr_mutex_orig;
      ast_reentrancy_unlock(lt);

      ast_suspend_lock_info(t);
   }
#endif /* DEBUG_THREADS */

   return res;
}
int __ast_cond_wait ( const char *  filename,
int  lineno,
const char *  func,
const char *  cond_name,
const char *  mutex_name,
ast_cond_t cond,
ast_mutex_t t 
)

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

{
   int res;

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

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

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

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

      /* Waiting on a condition completely suspends a recursive mutex,
       * even if it's been recursively locked multiple times. Make a
       * copy of the lock tracking, and reset reentrancy to zero */
      lt_orig = *lt;
      lt->reentrancy = 0;
      ast_reentrancy_unlock(lt);

      ast_suspend_lock_info(t);
   }
#endif /* DEBUG_THREADS */

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

#ifdef DEBUG_THREADS
   if (res) {
      __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
               filename, lineno, func, strerror(res));
      DO_THREAD_CRASH;
   } else if (t->tracking) {
      pthread_mutex_t reentr_mutex_orig;
      ast_reentrancy_lock(lt);
      /* Restore lock tracking to what it was prior to the wait */
      reentr_mutex_orig = lt->reentr_mutex;
      *lt = lt_orig;
      /* un-trash the mutex we just copied over */
      lt->reentr_mutex = reentr_mutex_orig;
      ast_reentrancy_unlock(lt);

      ast_restore_lock_info(t);
   }
#endif /* DEBUG_THREADS */

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

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

{
   int res;

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

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

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

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

   res = pthread_mutex_destroy(&t->mutex);

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

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

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

{
   int res;
   pthread_mutexattr_t  attr;

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

#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */

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

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

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

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

{
   int res;

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

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

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

   if (t->tracking) {
#ifdef HAVE_BKTR
      struct ast_bt tmp;

      /* The implementation of backtrace() may have its own locks.
       * Capture the backtrace outside of the reentrancy lock to
       * avoid deadlocks. See ASTERISK-22455. */
      ast_bt_get_addresses(&tmp);

      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         lt->backtrace[lt->reentrancy] = tmp;
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);

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

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

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

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

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

{
   int res;

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

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

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

   if (t->tracking) {
#ifdef HAVE_BKTR
      struct ast_bt tmp;

      /* The implementation of backtrace() may have its own locks.
       * Capture the backtrace outside of the reentrancy lock to
       * avoid deadlocks. See ASTERISK-22455. */
      ast_bt_get_addresses(&tmp);

      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         lt->backtrace[lt->reentrancy] = tmp;
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);

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

   res = pthread_mutex_trylock(&t->mutex);

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

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

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

{
   int res;

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

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

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

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

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

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

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

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

   res = pthread_mutex_unlock(&t->mutex);

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

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

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

{
   int res;

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

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

#endif /* DEBUG_THREADS */

   res = pthread_rwlock_destroy(&t->lock);

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

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

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

{
   int res;
   pthread_rwlockattr_t attr;

#ifdef DEBUG_THREADS

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

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

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

   pthread_rwlockattr_init(&attr);

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

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

Definition at line 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 __ao2_global_obj_ref(), __ao2_lock(), and __ast_heap_rdlock().

{
   int res;

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

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

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

   if (t->tracking) {
#ifdef HAVE_BKTR
      struct ast_bt tmp;

      /* The implementation of backtrace() may have its own locks.
       * Capture the backtrace outside of the reentrancy lock to
       * avoid deadlocks. See ASTERISK-22455. */
      ast_bt_get_addresses(&tmp);

      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         lt->backtrace[lt->reentrancy] = tmp;
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);

      ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

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

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

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

   return res;
}
int __ast_rwlock_timedrdlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name,
const struct timespec *  abs_timeout 
)

Definition at line 1089 of file lock.c.

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

{
   int res;

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

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

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

   if (t->tracking) {
#ifdef HAVE_BKTR
      struct ast_bt tmp;

      /* The implementation of backtrace() may have its own locks.
       * Capture the backtrace outside of the reentrancy lock to
       * avoid deadlocks. See ASTERISK-22455. */
      ast_bt_get_addresses(&tmp);

      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         lt->backtrace[lt->reentrancy] = tmp;
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);

      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

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

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

   return res;
}
int __ast_rwlock_timedwrlock ( const char *  filename,
int  lineno,
const char *  func,
ast_rwlock_t t,
const char *  name,
const struct timespec *  abs_timeout 
)

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

{
   int res;

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

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

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

   if (t->tracking) {
#ifdef HAVE_BKTR
      struct ast_bt tmp;

      /* The implementation of backtrace() may have its own locks.
       * Capture the backtrace outside of the reentrancy lock to
       * avoid deadlocks. See ASTERISK-22455. */
      ast_bt_get_addresses(&tmp);

      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         lt->backtrace[lt->reentrancy] = tmp;
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);

      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

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

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

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

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

Referenced by __ao2_trylock().

{
   int res;

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

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

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

   if (t->tracking) {
#ifdef HAVE_BKTR
      struct ast_bt tmp;

      /* The implementation of backtrace() may have its own locks.
       * Capture the backtrace outside of the reentrancy lock to
       * avoid deadlocks. See ASTERISK-22455. */
      ast_bt_get_addresses(&tmp);

      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         lt->backtrace[lt->reentrancy] = tmp;
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);

      ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

   res = pthread_rwlock_tryrdlock(&t->lock);

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

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

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

Referenced by __ao2_trylock().

{
   int res;

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

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

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

   if (t->tracking) {
#ifdef HAVE_BKTR
      struct ast_bt tmp;

      /* The implementation of backtrace() may have its own locks.
       * Capture the backtrace outside of the reentrancy lock to
       * avoid deadlocks. See ASTERISK-22455. */
      ast_bt_get_addresses(&tmp);

      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         lt->backtrace[lt->reentrancy] = tmp;
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);

      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

   res = pthread_rwlock_trywrlock(&t->lock);

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

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

Definition at line 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 __ao2_global_obj_ref(), __ao2_global_obj_release(), __ao2_global_obj_replace(), __ao2_unlock(), and __ast_heap_unlock().

{
   int res;

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


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

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

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

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

      ast_reentrancy_unlock(lt);

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

   res = pthread_rwlock_unlock(&t->lock);

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

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

Definition at line 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 __ao2_global_obj_release(), __ao2_global_obj_replace(), __ao2_lock(), and __ast_heap_wrlock().

{
   int res;

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

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

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

   if (t->tracking) {
#ifdef HAVE_BKTR
      struct ast_bt tmp;

      /* The implementation of backtrace() may have its own locks.
       * Capture the backtrace outside of the reentrancy lock to
       * avoid deadlocks. See ASTERISK-22455. */
      ast_bt_get_addresses(&tmp);

      ast_reentrancy_lock(lt);
      if (lt->reentrancy != AST_MAX_REENTRANCY) {
         lt->backtrace[lt->reentrancy] = tmp;
         bt = &lt->backtrace[lt->reentrancy];
      }
      ast_reentrancy_unlock(lt);

      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
#else
      ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
#endif
   }
#endif /* DEBUG_THREADS */

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

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

   return res;
}
int ast_atomic_dec_and_test ( volatile int *  p) [inline]

decrement *p by 1 and return true if the variable has reached 0. Useful e.g. to check if a refcount has reached 0.

Definition at line 649 of file lock.h.

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

{
int ast_atomic_fetchadd_int ( volatile int *  p,
int  v 
) [inline]

Atomically add v to *p and return * the previous value of *p. This can be used to handle reference counts, and the return value can be used to generate unique identifiers.

Definition at line 603 of file lock.h.

Referenced by __ao2_lock(), __ao2_trylock(), __ao2_unlock(), __ast_channel_alloc_ap(), __ast_manager_event_multichan(), __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), _ast_odbc_request_obj2(), _sip_tcp_helper_thread(), accept_thread(), acf_odbc_read(), action_login(), admin_exec(), advance_event(), append_event(), ast_channel_destructor(), ast_cli_command_full(), ast_create_callid(), 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_load_queue_rt_friendly(), find_session(), find_transcoders(), generate_msg_id(), generic_fax_exec(), grab_last(), handle_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(), 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().

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

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

References ast_mutex_lock, ast_mutex_unlock, and fetchadd_m.

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