Decrease service thread lock thrashing 07/277807/5
authorKonrad Lipinski <k.lipinski2@samsung.com>
Wed, 13 Jul 2022 14:13:55 +0000 (16:13 +0200)
committerKonrad Lipinski <k.lipinski2@samsung.com>
Tue, 19 Jul 2022 10:11:15 +0000 (12:11 +0200)
By not releasing the lock right after wait() returns.

Change-Id: Ic689aed448b9a00370252be2b09d7cb653bdcdc5

src/server/main/service-thread.cpp

index ca5a104..176fd64 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2022 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * This file is licensed under the terms of MIT License or the Apache License
  * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
@@ -65,27 +65,27 @@ ServiceThread::~ServiceThread() {
 
 void ServiceThread::ThreadLoop() {
     for (;;) {
-        EventDescription description = {NULL, NULL};
+        EventDescription description;
         {
             std::unique_lock<std::mutex> ulock(m_eventQueueMutex);
-            if (m_quit)
-                return;
-            if (!m_eventQueue.empty()) {
-                description = m_eventQueue.front();
-                m_eventQueue.pop();
-            } else {
+            for (;;) {
+                if (m_quit)
+                    return;
+                if (!m_eventQueue.empty()) {
+                    description = m_eventQueue.front();
+                    m_eventQueue.pop();
+                    break;
+                }
                 m_waitCondition.wait(ulock);
             }
         }
 
-        if (description.eventPtr != NULL) {
-            UNHANDLED_EXCEPTION_HANDLER_BEGIN
-            {
-                (this->*description.eventFunctionPtr)(description);
-                delete description.eventPtr;
-            }
-            UNHANDLED_EXCEPTION_HANDLER_END
+        UNHANDLED_EXCEPTION_HANDLER_BEGIN
+        {
+            (this->*description.eventFunctionPtr)(description);
+            delete description.eventPtr;
         }
+        UNHANDLED_EXCEPTION_HANDLER_END
     }
 }