You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2020/02/11 23:58:59 UTC

[trafficserver] branch 9.0.x updated: Avoid cross-thread mutex conflicts

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new a709cf1  Avoid cross-thread mutex conflicts
a709cf1 is described below

commit a709cf17a70edd2454bbc79e5c7090f16f0187a7
Author: Susan Hinrichs <sh...@oath.com>
AuthorDate: Fri Jan 17 14:31:37 2020 +0000

    Avoid cross-thread mutex conflicts
    
    (cherry picked from commit 9b78e8e270962773446d39560d5a77e7532ef84c)
---
 iocore/eventsystem/P_UnixEventProcessor.h | 2 --
 iocore/eventsystem/UnixEThread.cc         | 9 ++++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/iocore/eventsystem/P_UnixEventProcessor.h b/iocore/eventsystem/P_UnixEventProcessor.h
index df4d419..6e89d5b 100644
--- a/iocore/eventsystem/P_UnixEventProcessor.h
+++ b/iocore/eventsystem/P_UnixEventProcessor.h
@@ -115,8 +115,6 @@ EventProcessor::schedule(Event *e, EventType etype, bool fast_signal)
 
   if (e->continuation->mutex) {
     e->mutex = e->continuation->mutex;
-  } else {
-    e->mutex = e->continuation->mutex = e->ethread->mutex;
   }
   e->ethread->EventQueueExternal.enqueue(e, fast_signal);
   return e;
diff --git a/iocore/eventsystem/UnixEThread.cc b/iocore/eventsystem/UnixEThread.cc
index 715c7e4..1cfbb16 100644
--- a/iocore/eventsystem/UnixEThread.cc
+++ b/iocore/eventsystem/UnixEThread.cc
@@ -34,6 +34,8 @@
 #include <sys/eventfd.h>
 #endif
 
+#include <typeinfo>
+
 struct AIOCallback;
 
 #define NO_HEARTBEAT -1
@@ -118,7 +120,7 @@ void
 EThread::process_event(Event *e, int calling_code)
 {
   ink_assert((!e->in_the_prot_queue && !e->in_the_priority_queue));
-  MUTEX_TRY_LOCK(lock, e->mutex, this);
+  WEAK_MUTEX_TRY_LOCK(lock, e->mutex, this);
   if (!lock.is_locked()) {
     e->timeout_at = cur_time + DELAY_FOR_RETRY;
     EventQueueExternal.enqueue_local(e);
@@ -130,6 +132,11 @@ EThread::process_event(Event *e, int calling_code)
     Continuation *c_temp = e->continuation;
     // Make sure that the continuation is locked before calling the handler
 
+    // Give a heads up if we are processing through a continuation without a mutex
+    if (!e->mutex) {
+      Warning("event processing for continuation %s without a mutex", typeid(*c_temp).name());
+    }
+
     // Restore the client IP debugging flags
     set_cont_flags(e->continuation->control_flags);