Skip to content
Snippets Groups Projects
Commit c4874256 authored by Naveen Albert's avatar Naveen Albert Committed by Friendly Automation
Browse files

lock.c: Add AMI event for deadlocks.

Adds an AMI event to indicate that a deadlock
has likely started, when Asterisk is compiled
with DETECT_DEADLOCKS enabled. This can make
it easier to perform automated deadlock detection
and take appropriate action (such as doing a core
dump). Unlike the deadlock warnings, the AMI event
is emitted only once per deadlock.

ASTERISK-30161 #close

Change-Id: Ifc6ed3e390f8b4cff7f8077a50e4d7a5b54e42fb
parent 205c7c8d
No related branches found
No related tags found
3 merge requests!138Merge branch asterisk-20.3.0 into devel properly,!123Merge asterisk '20.3.0' into devel,!118Draft: manager: AOC-S support for AOCMessage
Subject: locks
A new AMI event, DeadlockStart, is now available
when Asterisk is compiled with DETECT_DEADLOCKS,
and can indicate that a deadlock has occured.
...@@ -38,6 +38,7 @@ static void __attribute__((constructor)) __mtx_init(void) ...@@ -38,6 +38,7 @@ static void __attribute__((constructor)) __mtx_init(void)
#include "asterisk/utils.h" #include "asterisk/utils.h"
#include "asterisk/lock.h" #include "asterisk/lock.h"
#include "asterisk/manager.h"
/* Allow direct use of pthread_mutex_* / pthread_cond_* */ /* Allow direct use of pthread_mutex_* / pthread_cond_* */
#undef pthread_mutex_init #undef pthread_mutex_init
...@@ -311,6 +312,26 @@ int __ast_pthread_mutex_lock(const char *filename, int lineno, const char *func, ...@@ -311,6 +312,26 @@ int __ast_pthread_mutex_lock(const char *filename, int lineno, const char *func,
ast_reentrancy_unlock(lt); ast_reentrancy_unlock(lt);
} }
reported_wait = wait_time; reported_wait = wait_time;
if ((int) wait_time < 10) { /* Only emit an event when a deadlock starts, not every 5 seconds */
/*** DOCUMENTATION
<managerEvent language="en_US" name="DeadlockStart">
<managerEventInstance class="EVENT_FLAG_SYSTEM">
<synopsis>Raised when a probable deadlock has started.
Delivery of this event is attempted but not guaranteed,
and could fail for example if the manager itself is deadlocked.
</synopsis>
<syntax>
<parameter name="Mutex">
<para>The mutex involved in the deadlock.</para>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
***/
manager_event(EVENT_FLAG_SYSTEM, "DeadlockStart",
"Mutex: %s\r\n",
mutex_name);
}
} }
usleep(200); usleep(200);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment