trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [trafficserver] branch master updated: Optimize: Avoid meaningless lock operations
Date Wed, 19 Dec 2018 06:47:00 GMT
This is an automated email from the ASF dual-hosted git repository.

oknet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new d9732a5  Optimize: Avoid meaningless lock operations
d9732a5 is described below

commit d9732a5a95d81d963c4b26dccc3a3622e78ac0f5
Author: Oknet Xu <xuchao@skyguard.com.cn>
AuthorDate: Tue Dec 18 17:18:43 2018 +0800

    Optimize: Avoid meaningless lock operations
---
 iocore/eventsystem/ProtectedQueue.cc | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/iocore/eventsystem/ProtectedQueue.cc b/iocore/eventsystem/ProtectedQueue.cc
index bb9466b..c4b5377 100644
--- a/iocore/eventsystem/ProtectedQueue.cc
+++ b/iocore/eventsystem/ProtectedQueue.cc
@@ -114,10 +114,15 @@ ProtectedQueue::dequeue_external()
 void
 ProtectedQueue::wait(ink_hrtime timeout)
 {
-  ink_mutex_acquire(&lock);
+  // If there are no external events available, don't do a cond_timedwait.
   if (INK_ATOMICLIST_EMPTY(al)) {
-    timespec ts = ink_hrtime_to_timespec(timeout);
-    ink_cond_timedwait(&might_have_data, &lock, &ts);
+    ink_mutex_acquire(&lock);
+    // The "al" may have new events while waiting for the mutex become available.
+    // We have to recheck the external queue again.
+    if (INK_ATOMICLIST_EMPTY(al)) {
+      timespec ts = ink_hrtime_to_timespec(timeout);
+      ink_cond_timedwait(&might_have_data, &lock, &ts);
+    }
+    ink_mutex_release(&lock);
   }
-  ink_mutex_release(&lock);
 }


Mime
View raw message