<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19121">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">lock.c: Add AMI event for deadlocks.<br><br>Adds an AMI event to indicate that a deadlock<br>has likely started, when Asterisk is compiled<br>with DETECT_DEADLOCKS enabled. This can make<br>it easier to perform automated deadlock detection<br>and take appropriate action (such as doing a core<br>dump). Unlike the deadlock warnings, the AMI event<br>is emitted only once per deadlock.<br><br>ASTERISK-30161 #close<br><br>Change-Id: Ifc6ed3e390f8b4cff7f8077a50e4d7a5b54e42fb<br>---<br>A doc/CHANGES-staging/lock_deadlock.txt<br>M main/lock.c<br>2 files changed, 45 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/19121/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/lock_deadlock.txt b/doc/CHANGES-staging/lock_deadlock.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..5fad3ee</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/lock_deadlock.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: locks</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+A new AMI event, DeadlockStart, is now available</span><br><span style="color: hsl(120, 100%, 40%);">+when Asterisk is compiled with DETECT_DEADLOCKS,</span><br><span style="color: hsl(120, 100%, 40%);">+and can indicate that a deadlock has occured.</span><br><span>diff --git a/main/lock.c b/main/lock.c</span><br><span>index fcf0839..8d09f00 100644</span><br><span>--- a/main/lock.c</span><br><span>+++ b/main/lock.c</span><br><span>@@ -38,6 +38,7 @@</span><br><span> </span><br><span> #include "asterisk/utils.h"</span><br><span> #include "asterisk/lock.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/manager.h"</span><br><span> </span><br><span> /* Allow direct use of pthread_mutex_* / pthread_cond_* */</span><br><span> #undef pthread_mutex_init</span><br><span>@@ -311,6 +312,26 @@</span><br><span> ast_reentrancy_unlock(lt);</span><br><span> }</span><br><span> reported_wait = wait_time;</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((int) wait_time < 10) { /* Only emit an event when a deadlock starts, not every 5 seconds */</span><br><span style="color: hsl(120, 100%, 40%);">+ /*** DOCUMENTATION</span><br><span style="color: hsl(120, 100%, 40%);">+ <managerEvent language="en_US" name="DeadlockStart"></span><br><span style="color: hsl(120, 100%, 40%);">+ <managerEventInstance class="EVENT_FLAG_SYSTEM"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>Raised when a probable deadlock has started.</span><br><span style="color: hsl(120, 100%, 40%);">+ Delivery of this event is attempted but not guaranteed,</span><br><span style="color: hsl(120, 100%, 40%);">+ and could fail for example if the manager itself is deadlocked.</span><br><span style="color: hsl(120, 100%, 40%);">+ </synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="Mutex"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>The mutex involved in the deadlock.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </parameter></span><br><span style="color: hsl(120, 100%, 40%);">+ </syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ </managerEventInstance></span><br><span style="color: hsl(120, 100%, 40%);">+ </managerEvent></span><br><span style="color: hsl(120, 100%, 40%);">+ ***/</span><br><span style="color: hsl(120, 100%, 40%);">+ manager_event(EVENT_FLAG_SYSTEM, "DeadlockStart",</span><br><span style="color: hsl(120, 100%, 40%);">+ "Mutex: %s\r\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ mutex_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> usleep(200);</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19121">change 19121</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19121"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 20 </div>
<div style="display:none"> Gerrit-Change-Id: Ifc6ed3e390f8b4cff7f8077a50e4d7a5b54e42fb </div>
<div style="display:none"> Gerrit-Change-Number: 19121 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>