Tue Aug 20 16:35:06 2013

Asterisk developer's documentation


lock.h File Reference

Asterisk locking-related definitions:

More...

#include <pthread.h>
#include <time.h>
#include <sys/param.h>
#include <execinfo.h>
#include "asterisk/logger.h"
#include "asterisk/compiler.h"
#include "asterisk/inline_api.h"

Go to the source code of this file.

Data Structures

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

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:

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

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

Definition at line 558 of file lock.h.

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

Definition at line 89 of file lock.h.

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

Definition at line 538 of file lock.h.

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

Definition at line 539 of file lock.h.

#define ast_mutex_destroy (  )     __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)

Definition at line 153 of file lock.h.

#define AST_MUTEX_INIT_VALUE   { PTHREAD_MUTEX_INIT_VALUE, NULL, 1 }

Definition at line 94 of file lock.h.

#define AST_MUTEX_INIT_VALUE_NOTRACKING   { PTHREAD_MUTEX_INIT_VALUE, NULL, 0 }

Definition at line 95 of file lock.h.

#define AST_MUTEX_INITIALIZER   __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__

Definition at line 580 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 (  )     __ast_pthread_mutex_lock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)

Definition at line 155 of file lock.h.

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

#define ast_mutex_trylock (  )     __ast_pthread_mutex_trylock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)
#define ast_mutex_unlock (  )     __ast_pthread_mutex_unlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, #a, a)

Definition at line 156 of file lock.h.

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

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

Definition at line 561 of file lock.h.

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

Definition at line 562 of file lock.h.

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

wrapper for rwlock with tracking enabled

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

Definition at line 190 of file lock.h.

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

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

wrapper for ast_rwlock_init with tracking disabled

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

Definition at line 197 of file lock.h.

#define AST_RWLOCK_INIT_VALUE   { __AST_RWLOCK_INIT_VALUE, NULL, 1 }

Definition at line 97 of file lock.h.

#define AST_RWLOCK_INIT_VALUE_NOTRACKING   { __AST_RWLOCK_INIT_VALUE, NULL, 0 }

Definition at line 98 of file lock.h.

#define ast_rwlock_rdlock (  )     __ast_rwlock_rdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)
#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 (  )     __ast_rwlock_tryrdlock(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, #a)

Definition at line 203 of file lock.h.

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

Definition at line 204 of file lock.h.

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

Definition at line 200 of file lock.h.

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

#define ast_rwlock_wrlock (  )     __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)

Definition at line 510 of file lock.h.

Referenced by dahdi_handle_event().

#define DLA_UNLOCK ( lock   )     ast_mutex_unlock(lock)

Definition at line 508 of file lock.h.

Referenced by dahdi_handle_event().

#define gethostbyname   __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__

Definition at line 582 of file lock.h.

Referenced by connect_sphinx().

#define pthread_cond_broadcast   use_ast_cond_broadcast_instead_of_pthread_cond_broadcast

Definition at line 576 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 574 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 573 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 575 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 566 of file lock.h.

#define pthread_cond_timedwait   use_ast_cond_timedwait_instead_of_pthread_cond_timedwait

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

Referenced by __ast_cond_wait().

#define pthread_create   __use_ast_pthread_create_instead__

Definition at line 585 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 572 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 571 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_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)

Typedef Documentation

typedef pthread_cond_t ast_cond_t

Definition at line 144 of file lock.h.

typedef struct ast_mutex_info ast_mutex_t

Definition at line 140 of file lock.h.

typedef struct ast_rwlock_info ast_rwlock_t

Definition at line 142 of file lock.h.


Function Documentation

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

Definition at line 463 of file lock.c.

References pthread_cond_broadcast.

00465 {
00466    return pthread_cond_broadcast(cond);
00467 }

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

Definition at line 469 of file lock.c.

References pthread_cond_destroy.

00471 {
00472    return pthread_cond_destroy(cond);
00473 }

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

References pthread_cond_init.

00453 {
00454    return pthread_cond_init(cond, cond_attr);
00455 }

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

Definition at line 457 of file lock.c.

References pthread_cond_signal.

00459 {
00460    return pthread_cond_signal(cond);
00461 }

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

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

00586 {
00587    int res;
00588 
00589 #ifdef DEBUG_THREADS
00590    struct ast_lock_track *lt;
00591    int canlog = strcmp(filename, "logger.c") & t->tracking;
00592 #ifdef HAVE_BKTR
00593    struct ast_bt *bt = NULL;
00594 #endif
00595 
00596 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00597    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00598       __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
00599                filename, lineno, func, mutex_name);
00600       res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
00601       if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00602          __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
00603                 filename, lineno, func, mutex_name);
00604       }
00605       return res;
00606    }
00607 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00608 
00609    if (t->tracking && !t->track) {
00610       ast_reentrancy_init(&t->track);
00611    }
00612    lt = t->track;
00613 
00614    if (t->tracking) {
00615       ast_reentrancy_lock(lt);
00616       if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
00617          __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
00618                   filename, lineno, func, mutex_name);
00619          __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
00620                   lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
00621 #ifdef HAVE_BKTR
00622          __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00623 #endif
00624          DO_THREAD_CRASH;
00625       }
00626 
00627       if (--lt->reentrancy < 0) {
00628          __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
00629                   filename, lineno, func, mutex_name);
00630          lt->reentrancy = 0;
00631       }
00632 
00633       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00634          lt->file[lt->reentrancy] = NULL;
00635          lt->lineno[lt->reentrancy] = 0;
00636          lt->func[lt->reentrancy] = NULL;
00637          lt->thread[lt->reentrancy] = 0;
00638       }
00639 #ifdef HAVE_BKTR
00640       if (lt->reentrancy) {
00641          bt = &lt->backtrace[lt->reentrancy - 1];
00642       }
00643 #endif
00644       ast_reentrancy_unlock(lt);
00645 
00646 #ifdef HAVE_BKTR
00647       ast_remove_lock_info(t, bt);
00648 #else
00649       ast_remove_lock_info(t);
00650 #endif
00651    }
00652 #endif /* DEBUG_THREADS */
00653 
00654    res = pthread_cond_timedwait(cond, &t->mutex, abstime);
00655 
00656 #ifdef DEBUG_THREADS
00657    if (res && (res != ETIMEDOUT)) {
00658       __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
00659                filename, lineno, func, strerror(res));
00660       DO_THREAD_CRASH;
00661    } else if (t->tracking) {
00662       ast_reentrancy_lock(lt);
00663       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00664          lt->file[lt->reentrancy] = filename;
00665          lt->lineno[lt->reentrancy] = lineno;
00666          lt->func[lt->reentrancy] = func;
00667          lt->thread[lt->reentrancy] = pthread_self();
00668 #ifdef HAVE_BKTR
00669          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
00670          bt = &lt->backtrace[lt->reentrancy];
00671 #endif
00672          lt->reentrancy++;
00673       } else {
00674          __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
00675                         filename, lineno, func, mutex_name);
00676       }
00677       ast_reentrancy_unlock(lt);
00678 
00679 #ifdef HAVE_BKTR
00680       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
00681 #else
00682       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
00683 #endif
00684    }
00685 #endif /* DEBUG_THREADS */
00686 
00687    return res;
00688 }

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

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

00478 {
00479    int res;
00480 
00481 #ifdef DEBUG_THREADS
00482    struct ast_lock_track *lt;
00483    int canlog = strcmp(filename, "logger.c") & t->tracking;
00484 #ifdef HAVE_BKTR
00485    struct ast_bt *bt = NULL;
00486 #endif
00487 
00488 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00489    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00490       __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
00491                filename, lineno, func, mutex_name);
00492       res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
00493       if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00494          __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
00495                 filename, lineno, func, mutex_name);
00496       }
00497       return res;
00498    }
00499 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00500 
00501    if (t->tracking && !t->track) {
00502       ast_reentrancy_init(&t->track);
00503    }
00504    lt = t->track;
00505 
00506    if (t->tracking) {
00507       ast_reentrancy_lock(lt);
00508       if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
00509          __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
00510                   filename, lineno, func, mutex_name);
00511          __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
00512                   lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
00513 #ifdef HAVE_BKTR
00514          __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00515 #endif
00516          DO_THREAD_CRASH;
00517       }
00518 
00519       if (--lt->reentrancy < 0) {
00520          __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
00521                filename, lineno, func, mutex_name);
00522          lt->reentrancy = 0;
00523       }
00524 
00525       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00526          lt->file[lt->reentrancy] = NULL;
00527          lt->lineno[lt->reentrancy] = 0;
00528          lt->func[lt->reentrancy] = NULL;
00529          lt->thread[lt->reentrancy] = 0;
00530       }
00531 
00532 #ifdef HAVE_BKTR
00533       if (lt->reentrancy) {
00534          bt = &lt->backtrace[lt->reentrancy - 1];
00535       }
00536 #endif
00537       ast_reentrancy_unlock(lt);
00538 
00539 #ifdef HAVE_BKTR
00540       ast_remove_lock_info(t, bt);
00541 #else
00542       ast_remove_lock_info(t);
00543 #endif
00544    }
00545 #endif /* DEBUG_THREADS */
00546 
00547    res = pthread_cond_wait(cond, &t->mutex);
00548 
00549 #ifdef DEBUG_THREADS
00550    if (res) {
00551       __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",
00552                filename, lineno, func, strerror(res));
00553       DO_THREAD_CRASH;
00554    } else if (t->tracking) {
00555       ast_reentrancy_lock(lt);
00556       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00557          lt->file[lt->reentrancy] = filename;
00558          lt->lineno[lt->reentrancy] = lineno;
00559          lt->func[lt->reentrancy] = func;
00560          lt->thread[lt->reentrancy] = pthread_self();
00561 #ifdef HAVE_BKTR
00562          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
00563          bt = &lt->backtrace[lt->reentrancy];
00564 #endif
00565          lt->reentrancy++;
00566       } else {
00567          __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
00568                         filename, lineno, func, mutex_name);
00569       }
00570       ast_reentrancy_unlock(lt);
00571 
00572 #ifdef HAVE_BKTR
00573       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
00574 #else
00575       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
00576 #endif
00577    }
00578 #endif /* DEBUG_THREADS */
00579 
00580    return res;
00581 }

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

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

00084 {
00085    int res;
00086 
00087 #ifdef DEBUG_THREADS
00088    struct ast_lock_track *lt;
00089    int canlog = strcmp(filename, "logger.c") & t->tracking;
00090 
00091 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00092    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00093       /* Don't try to uninitialize non initialized mutex
00094        * This may no effect on linux
00095        * And always ganerate core on *BSD with
00096        * linked libpthread
00097        * This not error condition if the mutex created on the fly.
00098        */
00099       __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n",
00100                filename, lineno, func, mutex_name);
00101       return 0;
00102    }
00103 #endif
00104 
00105    if (t->tracking && !t->track) {
00106       ast_reentrancy_init(&t->track);
00107    }
00108    lt = t->track;
00109 
00110    res = pthread_mutex_trylock(&t->mutex);
00111    switch (res) {
00112    case 0:
00113       pthread_mutex_unlock(&t->mutex);
00114       break;
00115    case EINVAL:
00116       __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",
00117               filename, lineno, func, mutex_name);
00118       break;
00119    case EBUSY:
00120       __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",
00121                filename, lineno, func, mutex_name);
00122       if (t->tracking) {
00123          ast_reentrancy_lock(lt);
00124          __ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",
00125                 lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
00126 #ifdef HAVE_BKTR
00127          __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00128 #endif
00129          ast_reentrancy_unlock(lt);
00130       }
00131       break;
00132    }
00133 #endif /* DEBUG_THREADS */
00134 
00135    res = pthread_mutex_destroy(&t->mutex);
00136 
00137 #ifdef DEBUG_THREADS
00138    if (res) {
00139       __ast_mutex_logger("%s line %d (%s): Error destroying mutex %s: %s\n",
00140                filename, lineno, func, mutex_name, strerror(res));
00141    }
00142    if (t->tracking) {
00143       ast_reentrancy_lock(lt);
00144       lt->file[0] = filename;
00145       lt->lineno[0] = lineno;
00146       lt->func[0] = func;
00147       lt->reentrancy = 0;
00148       lt->thread[0] = 0;
00149 #ifdef HAVE_BKTR
00150       memset(&lt->backtrace[0], 0, sizeof(lt->backtrace[0]));
00151 #endif
00152       ast_reentrancy_unlock(lt);
00153       delete_reentrancy_cs(&t->track);
00154    }
00155 #endif /* DEBUG_THREADS */
00156 
00157    return res;
00158 }

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 48 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().

00050 {
00051    int res;
00052    pthread_mutexattr_t  attr;
00053 
00054 #ifdef DEBUG_THREADS
00055    t->track = NULL;
00056 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00057    if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00058 /*
00059       int canlog = strcmp(filename, "logger.c") & track;
00060       __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is already initialized.\n",
00061                filename, lineno, func, mutex_name);
00062       DO_THREAD_CRASH;
00063 */
00064       return 0;
00065    }
00066 
00067 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00068 
00069    if ((t->tracking = tracking)) {
00070       ast_reentrancy_init(&t->track);
00071    }
00072 #endif /* DEBUG_THREADS */
00073 
00074    pthread_mutexattr_init(&attr);
00075    pthread_mutexattr_settype(&attr, AST_MUTEX_KIND);
00076 
00077    res = pthread_mutex_init(&t->mutex, &attr);
00078    pthread_mutexattr_destroy(&attr);
00079    return res;
00080 }

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

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

00162 {
00163    int res;
00164 
00165 #ifdef DEBUG_THREADS
00166    struct ast_lock_track *lt;
00167    int canlog = strcmp(filename, "logger.c") & t->tracking;
00168 #ifdef HAVE_BKTR
00169    struct ast_bt *bt = NULL;
00170 #endif
00171 
00172 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00173    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00174       /* Don't warn abount uninitialized mutex.
00175        * Simple try to initialize it.
00176        * May be not needed in linux system.
00177        */
00178       res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
00179       if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00180          __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
00181                 filename, lineno, func, mutex_name);
00182          return res;
00183       }
00184    }
00185 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00186 
00187    if (t->tracking && !t->track) {
00188       ast_reentrancy_init(&t->track);
00189    }
00190    lt = t->track;
00191 
00192    if (t->tracking) {
00193 #ifdef HAVE_BKTR
00194       ast_reentrancy_lock(lt);
00195       if (lt->reentrancy != AST_MAX_REENTRANCY) {
00196          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
00197          bt = &lt->backtrace[lt->reentrancy];
00198       }
00199       ast_reentrancy_unlock(lt);
00200       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
00201 #else
00202       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
00203 #endif
00204    }
00205 #endif /* DEBUG_THREADS */
00206 
00207 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
00208    {
00209       time_t seconds = time(NULL);
00210       time_t wait_time, reported_wait = 0;
00211       do {
00212 #ifdef   HAVE_MTX_PROFILE
00213          ast_mark(mtx_prof, 1);
00214 #endif
00215          res = pthread_mutex_trylock(&t->mutex);
00216 #ifdef   HAVE_MTX_PROFILE
00217          ast_mark(mtx_prof, 0);
00218 #endif
00219          if (res == EBUSY) {
00220             wait_time = time(NULL) - seconds;
00221             if (wait_time > reported_wait && (wait_time % 5) == 0) {
00222                __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
00223                         filename, lineno, func, (int) wait_time, mutex_name);
00224                ast_reentrancy_lock(lt);
00225 #ifdef HAVE_BKTR
00226                __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
00227 #endif
00228                __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
00229                         lt->file[ROFFSET], lt->lineno[ROFFSET],
00230                         lt->func[ROFFSET], mutex_name);
00231 #ifdef HAVE_BKTR
00232                __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00233 #endif
00234                ast_reentrancy_unlock(lt);
00235                reported_wait = wait_time;
00236             }
00237             usleep(200);
00238          }
00239       } while (res == EBUSY);
00240    }
00241 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
00242 #ifdef   HAVE_MTX_PROFILE
00243    ast_mark(mtx_prof, 1);
00244    res = pthread_mutex_trylock(&t->mutex);
00245    ast_mark(mtx_prof, 0);
00246    if (res)
00247 #endif
00248    res = pthread_mutex_lock(&t->mutex);
00249 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
00250 
00251 #ifdef DEBUG_THREADS
00252    if (t->tracking && !res) {
00253       ast_reentrancy_lock(lt);
00254       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00255          lt->file[lt->reentrancy] = filename;
00256          lt->lineno[lt->reentrancy] = lineno;
00257          lt->func[lt->reentrancy] = func;
00258          lt->thread[lt->reentrancy] = pthread_self();
00259          lt->reentrancy++;
00260       } else {
00261          __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
00262                         filename, lineno, func, mutex_name);
00263       }
00264       ast_reentrancy_unlock(lt);
00265       if (t->tracking) {
00266          ast_mark_lock_acquired(t);
00267       }
00268    } else if (t->tracking) {
00269 #ifdef HAVE_BKTR
00270       if (lt->reentrancy) {
00271          ast_reentrancy_lock(lt);
00272          bt = &lt->backtrace[lt->reentrancy-1];
00273          ast_reentrancy_unlock(lt);
00274       } else {
00275          bt = NULL;
00276       }
00277       ast_remove_lock_info(t, bt);
00278 #else
00279       ast_remove_lock_info(t);
00280 #endif
00281    }
00282    if (res) {
00283       __ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",
00284                filename, lineno, func, strerror(res));
00285       DO_THREAD_CRASH;
00286    }
00287 #endif /* DEBUG_THREADS */
00288 
00289    return res;
00290 }

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

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

00294 {
00295    int res;
00296 
00297 #ifdef DEBUG_THREADS
00298    struct ast_lock_track *lt;
00299    int canlog = strcmp(filename, "logger.c") & t->tracking;
00300 #ifdef HAVE_BKTR
00301    struct ast_bt *bt = NULL;
00302 #endif
00303 
00304 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00305    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00306       /* Don't warn abount uninitialized mutex.
00307        * Simple try to initialize it.
00308        * May be not needed in linux system.
00309        */
00310       res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
00311       if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00312          __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
00313                 filename, lineno, func, mutex_name);
00314          return res;
00315       }
00316    }
00317 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00318 
00319    if (t->tracking && !t->track) {
00320       ast_reentrancy_init(&t->track);
00321    }
00322    lt = t->track;
00323 
00324    if (t->tracking) {
00325 #ifdef HAVE_BKTR
00326       ast_reentrancy_lock(lt);
00327       if (lt->reentrancy != AST_MAX_REENTRANCY) {
00328          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
00329          bt = &lt->backtrace[lt->reentrancy];
00330       }
00331       ast_reentrancy_unlock(lt);
00332       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
00333 #else
00334       ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
00335 #endif
00336    }
00337 #endif /* DEBUG_THREADS */
00338 
00339    res = pthread_mutex_trylock(&t->mutex);
00340 
00341 #ifdef DEBUG_THREADS
00342    if (t->tracking && !res) {
00343       ast_reentrancy_lock(lt);
00344       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00345          lt->file[lt->reentrancy] = filename;
00346          lt->lineno[lt->reentrancy] = lineno;
00347          lt->func[lt->reentrancy] = func;
00348          lt->thread[lt->reentrancy] = pthread_self();
00349          lt->reentrancy++;
00350       } else {
00351          __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
00352                   filename, lineno, func, mutex_name);
00353       }
00354       ast_reentrancy_unlock(lt);
00355       if (t->tracking) {
00356          ast_mark_lock_acquired(t);
00357       }
00358    } else if (t->tracking) {
00359       ast_mark_lock_failed(t);
00360    }
00361 #endif /* DEBUG_THREADS */
00362 
00363    return res;
00364 }

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

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

00368 {
00369    int res;
00370 
00371 #ifdef DEBUG_THREADS
00372    struct ast_lock_track *lt;
00373    int canlog = strcmp(filename, "logger.c") & t->tracking;
00374 #ifdef HAVE_BKTR
00375    struct ast_bt *bt = NULL;
00376 #endif
00377 
00378 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00379    if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00380       __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",
00381                filename, lineno, func, mutex_name);
00382       res = __ast_pthread_mutex_init(t->tracking, filename, lineno, func, mutex_name, t);
00383       if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
00384          __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized and unable to initialize.\n",
00385                 filename, lineno, func, mutex_name);
00386       }
00387       return res;
00388    }
00389 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00390 
00391    if (t->tracking && !t->track) {
00392       ast_reentrancy_init(&t->track);
00393    }
00394    lt = t->track;
00395 
00396    if (t->tracking) {
00397       ast_reentrancy_lock(lt);
00398       if (lt->reentrancy && (lt->thread[ROFFSET] != pthread_self())) {
00399          __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
00400                   filename, lineno, func, mutex_name);
00401          __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
00402                   lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);
00403 #ifdef HAVE_BKTR
00404          __dump_backtrace(&lt->backtrace[ROFFSET], canlog);
00405 #endif
00406          DO_THREAD_CRASH;
00407       }
00408 
00409       if (--lt->reentrancy < 0) {
00410          __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",
00411                   filename, lineno, func, mutex_name);
00412          lt->reentrancy = 0;
00413       }
00414 
00415       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00416          lt->file[lt->reentrancy] = NULL;
00417          lt->lineno[lt->reentrancy] = 0;
00418          lt->func[lt->reentrancy] = NULL;
00419          lt->thread[lt->reentrancy] = 0;
00420       }
00421 
00422 #ifdef HAVE_BKTR
00423       if (lt->reentrancy) {
00424          bt = &lt->backtrace[lt->reentrancy - 1];
00425       }
00426 #endif
00427       ast_reentrancy_unlock(lt);
00428 
00429 #ifdef HAVE_BKTR
00430       ast_remove_lock_info(t, bt);
00431 #else
00432       ast_remove_lock_info(t);
00433 #endif
00434    }
00435 #endif /* DEBUG_THREADS */
00436 
00437    res = pthread_mutex_unlock(&t->mutex);
00438 
00439 #ifdef DEBUG_THREADS
00440    if (res) {
00441       __ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n",
00442                filename, lineno, func, strerror(res));
00443       DO_THREAD_CRASH;
00444    }
00445 #endif /* DEBUG_THREADS */
00446 
00447    return res;
00448 }

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

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

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

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 690 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().

00691 {
00692    int res;
00693    pthread_rwlockattr_t attr;
00694 
00695 #ifdef DEBUG_THREADS
00696 
00697 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00698    int canlog = strcmp(filename, "logger.c") & t->tracking;
00699 
00700    if (t->lock != ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
00701       __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is already initialized.\n",
00702             filename, lineno, func, rwlock_name);
00703       return 0;
00704    }
00705 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00706 
00707    if ((t->tracking = tracking)) {
00708       ast_reentrancy_init(&t->track);
00709    }
00710 #endif /* DEBUG_THREADS */
00711 
00712    pthread_rwlockattr_init(&attr);
00713 
00714 #ifdef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
00715    pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NP);
00716 #endif
00717 
00718    res = pthread_rwlock_init(&t->lock, &attr);
00719    pthread_rwlockattr_destroy(&attr);
00720    return res;
00721 }

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

Definition at line 852 of file lock.c.

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

Referenced by __ast_heap_rdlock().

00853 {
00854    int res;
00855 
00856 #ifdef DEBUG_THREADS
00857    struct ast_lock_track *lt;
00858    int canlog = strcmp(filename, "logger.c") & t->tracking;
00859 #ifdef HAVE_BKTR
00860    struct ast_bt *bt = NULL;
00861 #endif
00862 
00863 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00864    if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
00865        /* Don't warn abount uninitialized lock.
00866         * Simple try to initialize it.
00867         * May be not needed in linux system.
00868         */
00869       res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
00870       if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
00871          __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
00872                filename, line, func, name);
00873          return res;
00874       }
00875    }
00876 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00877 
00878    if (t->tracking && !t->track) {
00879       ast_reentrancy_init(&t->track);
00880    }
00881    lt = t->track;
00882 
00883    if (t->tracking) {
00884 #ifdef HAVE_BKTR
00885       ast_reentrancy_lock(lt);
00886       if (lt->reentrancy != AST_MAX_REENTRANCY) {
00887          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
00888          bt = &lt->backtrace[lt->reentrancy];
00889       }
00890       ast_reentrancy_unlock(lt);
00891       ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
00892 #else
00893       ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
00894 #endif
00895    }
00896 #endif /* DEBUG_THREADS */
00897 
00898 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
00899    {
00900       time_t seconds = time(NULL);
00901       time_t wait_time, reported_wait = 0;
00902       do {
00903          res = pthread_rwlock_tryrdlock(&t->lock);
00904          if (res == EBUSY) {
00905             wait_time = time(NULL) - seconds;
00906             if (wait_time > reported_wait && (wait_time % 5) == 0) {
00907                __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for readlock '%s'?\n",
00908                   filename, line, func, (int)wait_time, name);
00909                if (t->tracking) {
00910                   ast_reentrancy_lock(lt);
00911 #ifdef HAVE_BKTR
00912                   __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
00913 #endif
00914                   __ast_mutex_logger("%s line %d (%s): '%s' was locked  here.\n",
00915                         lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
00916                         lt->func[lt->reentrancy-1], name);
00917 #ifdef HAVE_BKTR
00918                   __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
00919 #endif
00920                   ast_reentrancy_unlock(lt);
00921                }
00922                reported_wait = wait_time;
00923             }
00924             usleep(200);
00925          }
00926       } while (res == EBUSY);
00927    }
00928 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
00929    res = pthread_rwlock_rdlock(&t->lock);
00930 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
00931 
00932 #ifdef DEBUG_THREADS
00933    if (!res && t->tracking) {
00934       ast_reentrancy_lock(lt);
00935       if (lt->reentrancy < AST_MAX_REENTRANCY) {
00936          lt->file[lt->reentrancy] = filename;
00937          lt->lineno[lt->reentrancy] = line;
00938          lt->func[lt->reentrancy] = func;
00939          lt->thread[lt->reentrancy] = pthread_self();
00940          lt->reentrancy++;
00941       }
00942       ast_reentrancy_unlock(lt);
00943       if (t->tracking) {
00944          ast_mark_lock_acquired(t);
00945       }
00946    } else if (t->tracking) {
00947 #ifdef HAVE_BKTR
00948       if (lt->reentrancy) {
00949          ast_reentrancy_lock(lt);
00950          bt = &lt->backtrace[lt->reentrancy-1];
00951          ast_reentrancy_unlock(lt);
00952       } else {
00953          bt = NULL;
00954       }
00955       ast_remove_lock_info(t, bt);
00956 #else
00957       ast_remove_lock_info(t);
00958 #endif
00959    }
00960 
00961    if (res) {
00962       __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
00963             filename, line, func, strerror(res));
00964       DO_THREAD_CRASH;
00965    }
00966 #endif /* DEBUG_THREADS */
00967 
00968    return res;
00969 }

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

01095 {
01096    int res;
01097 
01098 #ifdef DEBUG_THREADS
01099    struct ast_lock_track *lt;
01100    int canlog = strcmp(filename, "logger.c") & t->tracking;
01101 #ifdef HAVE_BKTR
01102    struct ast_bt *bt = NULL;
01103 #endif
01104 
01105 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
01106    if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
01107        /* Don't warn abount uninitialized lock.
01108         * Simple try to initialize it.
01109         * May be not needed in linux system.
01110         */
01111       res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
01112       if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
01113          __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
01114                filename, line, func, name);
01115          return res;
01116       }
01117    }
01118 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
01119 
01120    if (t->tracking && !t->track) {
01121       ast_reentrancy_init(&t->track);
01122    }
01123    lt = t->track;
01124 
01125    if (t->tracking) {
01126 #ifdef HAVE_BKTR
01127       ast_reentrancy_lock(lt);
01128       if (lt->reentrancy != AST_MAX_REENTRANCY) {
01129          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
01130          bt = &lt->backtrace[lt->reentrancy];
01131       }
01132       ast_reentrancy_unlock(lt);
01133       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
01134 #else
01135       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
01136 #endif
01137    }
01138 #endif /* DEBUG_THREADS */
01139 
01140 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
01141    res = pthread_rwlock_timedrdlock(&t->lock, abs_timeout);
01142 #else
01143    do {
01144       struct timeval _now;
01145       for (;;) {
01146          if (!(res = pthread_rwlock_tryrdlock(&t->lock))) {
01147             break;
01148          }
01149          _now = ast_tvnow();
01150          if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
01151             break;
01152          }
01153          usleep(1);
01154       }
01155    } while (0);
01156 #endif
01157 
01158 #ifdef DEBUG_THREADS
01159    if (!res && t->tracking) {
01160       ast_reentrancy_lock(lt);
01161       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01162          lt->file[lt->reentrancy] = filename;
01163          lt->lineno[lt->reentrancy] = line;
01164          lt->func[lt->reentrancy] = func;
01165          lt->thread[lt->reentrancy] = pthread_self();
01166          lt->reentrancy++;
01167       }
01168       ast_reentrancy_unlock(lt);
01169       if (t->tracking) {
01170          ast_mark_lock_acquired(t);
01171       }
01172    } else if (t->tracking) {
01173 #ifdef HAVE_BKTR
01174       if (lt->reentrancy) {
01175          ast_reentrancy_lock(lt);
01176          bt = &lt->backtrace[lt->reentrancy-1];
01177          ast_reentrancy_unlock(lt);
01178       } else {
01179          bt = NULL;
01180       }
01181       ast_remove_lock_info(t, bt);
01182 #else
01183       ast_remove_lock_info(t);
01184 #endif
01185    }
01186    if (res) {
01187       __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
01188             filename, line, func, strerror(res));
01189       DO_THREAD_CRASH;
01190    }
01191 #endif /* DEBUG_THREADS */
01192 
01193    return res;
01194 }

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

01198 {
01199    int res;
01200 
01201 #ifdef DEBUG_THREADS
01202    struct ast_lock_track *lt;
01203    int canlog = strcmp(filename, "logger.c") & t->tracking;
01204 #ifdef HAVE_BKTR
01205    struct ast_bt *bt = NULL;
01206 #endif
01207 
01208 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
01209    if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
01210        /* Don't warn abount uninitialized lock.
01211         * Simple try to initialize it.
01212         * May be not needed in linux system.
01213         */
01214       res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
01215       if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
01216          __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
01217                filename, line, func, name);
01218          return res;
01219       }
01220    }
01221 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
01222 
01223    if (t->tracking && !t->track) {
01224       ast_reentrancy_init(&t->track);
01225    }
01226    lt = t->track;
01227 
01228    if (t->tracking) {
01229 #ifdef HAVE_BKTR
01230       ast_reentrancy_lock(lt);
01231       if (lt->reentrancy != AST_MAX_REENTRANCY) {
01232          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
01233          bt = &lt->backtrace[lt->reentrancy];
01234       }
01235       ast_reentrancy_unlock(lt);
01236       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
01237 #else
01238       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
01239 #endif
01240    }
01241 #endif /* DEBUG_THREADS */
01242 
01243 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
01244    res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout);
01245 #else
01246    do {
01247       struct timeval _now;
01248       for (;;) {
01249          if (!(res = pthread_rwlock_trywrlock(&t->lock))) {
01250             break;
01251          }
01252          _now = ast_tvnow();
01253          if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
01254             break;
01255          }
01256          usleep(1);
01257       }
01258    } while (0);
01259 #endif
01260 
01261 #ifdef DEBUG_THREADS
01262    if (!res && t->tracking) {
01263       ast_reentrancy_lock(lt);
01264       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01265          lt->file[lt->reentrancy] = filename;
01266          lt->lineno[lt->reentrancy] = line;
01267          lt->func[lt->reentrancy] = func;
01268          lt->thread[lt->reentrancy] = pthread_self();
01269          lt->reentrancy++;
01270       }
01271       ast_reentrancy_unlock(lt);
01272       if (t->tracking) {
01273          ast_mark_lock_acquired(t);
01274       }
01275    } else if (t->tracking) {
01276 #ifdef HAVE_BKTR
01277       if (lt->reentrancy) {
01278          ast_reentrancy_lock(lt);
01279          bt = &lt->backtrace[lt->reentrancy-1];
01280          ast_reentrancy_unlock(lt);
01281       } else {
01282          bt = NULL;
01283       }
01284       if (t->tracking) {
01285          ast_remove_lock_info(t, bt);
01286       }
01287 #else
01288       if (t->tracking) {
01289          ast_remove_lock_info(t);
01290       }
01291 #endif
01292    }
01293    if (res) {
01294       __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
01295             filename, line, func, strerror(res));
01296       DO_THREAD_CRASH;
01297    }
01298 #endif /* DEBUG_THREADS */
01299 
01300    return res;
01301 }

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

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

01304 {
01305    int res;
01306 
01307 #ifdef DEBUG_THREADS
01308    struct ast_lock_track *lt;
01309 #ifdef HAVE_BKTR
01310    struct ast_bt *bt = NULL;
01311 #endif
01312 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
01313    int canlog = strcmp(filename, "logger.c") & t->tracking;
01314 
01315    if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
01316        /* Don't warn abount uninitialized lock.
01317         * Simple try to initialize it.
01318         * May be not needed in linux system.
01319         */
01320       res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
01321       if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
01322          __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
01323                filename, line, func, name);
01324          return res;
01325       }
01326    }
01327 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
01328 
01329    if (t->tracking && !t->track) {
01330       ast_reentrancy_init(&t->track);
01331    }
01332    lt = t->track;
01333 
01334    if (t->tracking) {
01335 #ifdef HAVE_BKTR
01336       ast_reentrancy_lock(lt);
01337       if (lt->reentrancy != AST_MAX_REENTRANCY) {
01338          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
01339          bt = &lt->backtrace[lt->reentrancy];
01340       }
01341       ast_reentrancy_unlock(lt);
01342       ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
01343 #else
01344       ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
01345 #endif
01346    }
01347 #endif /* DEBUG_THREADS */
01348 
01349    res = pthread_rwlock_tryrdlock(&t->lock);
01350 
01351 #ifdef DEBUG_THREADS
01352    if (!res && t->tracking) {
01353       ast_reentrancy_lock(lt);
01354       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01355          lt->file[lt->reentrancy] = filename;
01356          lt->lineno[lt->reentrancy] = line;
01357          lt->func[lt->reentrancy] = func;
01358          lt->thread[lt->reentrancy] = pthread_self();
01359          lt->reentrancy++;
01360       }
01361       ast_reentrancy_unlock(lt);
01362       if (t->tracking) {
01363          ast_mark_lock_acquired(t);
01364       }
01365    } else if (t->tracking) {
01366       ast_mark_lock_failed(t);
01367    }
01368 #endif /* DEBUG_THREADS */
01369 
01370    return res;
01371 }

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

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

01374 {
01375    int res;
01376 
01377 #ifdef DEBUG_THREADS
01378    struct ast_lock_track *lt;
01379 #ifdef HAVE_BKTR
01380    struct ast_bt *bt = NULL;
01381 #endif
01382 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
01383    int canlog = strcmp(filename, "logger.c") & t->tracking;
01384 
01385    if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
01386        /* Don't warn abount uninitialized lock.
01387         * Simple try to initialize it.
01388         * May be not needed in linux system.
01389         */
01390       res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
01391       if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
01392          __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
01393                filename, line, func, name);
01394          return res;
01395       }
01396    }
01397 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
01398 
01399    if (t->tracking && !t->track) {
01400       ast_reentrancy_init(&t->track);
01401    }
01402    lt = t->track;
01403 
01404    if (t->tracking) {
01405 #ifdef HAVE_BKTR
01406       ast_reentrancy_lock(lt);
01407       if (lt->reentrancy != AST_MAX_REENTRANCY) {
01408          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
01409          bt = &lt->backtrace[lt->reentrancy];
01410       }
01411       ast_reentrancy_unlock(lt);
01412       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
01413 #else
01414       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
01415 #endif
01416    }
01417 #endif /* DEBUG_THREADS */
01418 
01419    res = pthread_rwlock_trywrlock(&t->lock);
01420 
01421 #ifdef DEBUG_THREADS
01422    if (!res && t->tracking) {
01423       ast_reentrancy_lock(lt);
01424       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01425          lt->file[lt->reentrancy] = filename;
01426          lt->lineno[lt->reentrancy] = line;
01427          lt->func[lt->reentrancy] = func;
01428          lt->thread[lt->reentrancy] = pthread_self();
01429          lt->reentrancy++;
01430       }
01431       ast_reentrancy_unlock(lt);
01432       ast_mark_lock_acquired(t);
01433    } else if (t->tracking) {
01434       ast_mark_lock_failed(t);
01435    }
01436 #endif /* DEBUG_THREADS */
01437 
01438    return res;
01439 }

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

Definition at line 766 of file lock.c.

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

Referenced by __ast_heap_unlock().

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

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

Definition at line 971 of file lock.c.

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

Referenced by __ast_heap_wrlock().

00972 {
00973    int res;
00974 
00975 #ifdef DEBUG_THREADS
00976    struct ast_lock_track *lt;
00977    int canlog = strcmp(filename, "logger.c") & t->tracking;
00978 #ifdef HAVE_BKTR
00979    struct ast_bt *bt = NULL;
00980 #endif
00981 
00982 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
00983    if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
00984        /* Don't warn abount uninitialized lock.
00985         * Simple try to initialize it.
00986         * May be not needed in linux system.
00987         */
00988       res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
00989       if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
00990          __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
00991                filename, line, func, name);
00992          return res;
00993       }
00994    }
00995 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
00996 
00997    if (t->tracking && !t->track) {
00998       ast_reentrancy_init(&t->track);
00999    }
01000    lt = t->track;
01001 
01002    if (t->tracking) {
01003 #ifdef HAVE_BKTR
01004       ast_reentrancy_lock(lt);
01005       if (lt->reentrancy != AST_MAX_REENTRANCY) {
01006          ast_bt_get_addresses(&lt->backtrace[lt->reentrancy]);
01007          bt = &lt->backtrace[lt->reentrancy];
01008       }
01009       ast_reentrancy_unlock(lt);
01010       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
01011 #else
01012       ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
01013 #endif
01014    }
01015 #endif /* DEBUG_THREADS */
01016 
01017 #if defined(DETECT_DEADLOCKS) && defined(DEBUG_THREADS)
01018    {
01019       time_t seconds = time(NULL);
01020       time_t wait_time, reported_wait = 0;
01021       do {
01022          res = pthread_rwlock_trywrlock(&t->lock);
01023          if (res == EBUSY) {
01024             wait_time = time(NULL) - seconds;
01025             if (wait_time > reported_wait && (wait_time % 5) == 0) {
01026                __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for writelock '%s'?\n",
01027                   filename, line, func, (int)wait_time, name);
01028                if (t->tracking) {
01029                   ast_reentrancy_lock(lt);
01030 #ifdef HAVE_BKTR
01031                   __dump_backtrace(&lt->backtrace[lt->reentrancy], canlog);
01032 #endif
01033                   __ast_mutex_logger("%s line %d (%s): '%s' was locked  here.\n",
01034                         lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],
01035                         lt->func[lt->reentrancy-1], name);
01036 #ifdef HAVE_BKTR
01037                   __dump_backtrace(&lt->backtrace[lt->reentrancy-1], canlog);
01038 #endif
01039                   ast_reentrancy_unlock(lt);
01040                }
01041                reported_wait = wait_time;
01042             }
01043             usleep(200);
01044          }
01045       } while (res == EBUSY);
01046    }
01047 #else /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
01048    res = pthread_rwlock_wrlock(&t->lock);
01049 #endif /* !DETECT_DEADLOCKS || !DEBUG_THREADS */
01050 
01051 #ifdef DEBUG_THREADS
01052    if (!res && t->tracking) {
01053       ast_reentrancy_lock(lt);
01054       if (lt->reentrancy < AST_MAX_REENTRANCY) {
01055          lt->file[lt->reentrancy] = filename;
01056          lt->lineno[lt->reentrancy] = line;
01057          lt->func[lt->reentrancy] = func;
01058          lt->thread[lt->reentrancy] = pthread_self();
01059          lt->reentrancy++;
01060       }
01061       ast_reentrancy_unlock(lt);
01062       if (t->tracking) {
01063          ast_mark_lock_acquired(t);
01064       }
01065    } else if (t->tracking) {
01066 #ifdef HAVE_BKTR
01067       if (lt->reentrancy) {
01068          ast_reentrancy_lock(lt);
01069          bt = &lt->backtrace[lt->reentrancy-1];
01070          ast_reentrancy_unlock(lt);
01071       } else {
01072          bt = NULL;
01073       }
01074       if (t->tracking) {
01075          ast_remove_lock_info(t, bt);
01076       }
01077 #else
01078       if (t->tracking) {
01079          ast_remove_lock_info(t);
01080       }
01081 #endif
01082    }
01083    if (res) {
01084       __ast_mutex_logger("%s line %d (%s): Error obtaining write lock: %s\n",
01085             filename, line, func, strerror(res));
01086       DO_THREAD_CRASH;
01087    }
01088 #endif /* DEBUG_THREADS */
01089 
01090    return res;
01091 }

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

Definition at line 661 of file lock.h.

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

00664 {

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

Definition at line 615 of file lock.h.

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

00618 {

int ast_atomic_fetchadd_int_slow ( volatile int *  p,
int  v 
)

Definition at line 1940 of file utils.c.

References ast_mutex_lock, ast_mutex_unlock, and fetchadd_m.

01941 {
01942    int ret;
01943    ast_mutex_lock(&fetchadd_m);
01944    ret = *p;
01945    *p += v;
01946    ast_mutex_unlock(&fetchadd_m);
01947    return ret;
01948 }


Generated on 20 Aug 2013 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1