{"id":2234,"url":"https://patchwork.libcamera.org/api/patches/2234/?format=json","web_url":"https://patchwork.libcamera.org/patch/2234/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20191027203335.26888-4-jacopo@jmondi.org>","date":"2019-10-27T20:33:32","name":"[libcamera-devel,3/6] libcamera: object: Add ObjectConditionVariable class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f9160db2c7f979ce69c1e1aca2725e5faae711e3","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/2234/mbox/","series":[{"id":558,"url":"https://patchwork.libcamera.org/api/series/558/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=558","date":"2019-10-27T20:33:29","name":"Add support for blocking method invocation","version":1,"mbox":"https://patchwork.libcamera.org/series/558/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2234/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2234/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A17A61509\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 27 Oct 2019 21:31:49 +0100 (CET)","from uno.localdomain (143.121.2.93.rev.sfr.net [93.2.121.143])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 3F71DC0006;\n\tSun, 27 Oct 2019 20:31:49 +0000 (UTC)"],"X-Originating-IP":"93.2.121.143","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Sun, 27 Oct 2019 21:33:32 +0100","Message-Id":"<20191027203335.26888-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.23.0","In-Reply-To":"<20191027203335.26888-1-jacopo@jmondi.org>","References":"<20191027203335.26888-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 3/6] libcamera: object: Add\n\tObjectConditionVariable class","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sun, 27 Oct 2019 20:31:50 -0000"},"content":"Add ObjectConditionVariable class that implements an Object\nsynchronization primitive used to synchronize message delivery between\nObject running in different execution contexts.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/object.h | 19 ++++++++++++++++\n src/libcamera/object.cpp   | 46 ++++++++++++++++++++++++++++++++++++++\n 2 files changed, 65 insertions(+)","diff":"diff --git a/include/libcamera/object.h b/include/libcamera/object.h\nindex be07611c25c6..c6477f18417d 100644\n--- a/include/libcamera/object.h\n+++ b/include/libcamera/object.h\n@@ -7,8 +7,10 @@\n #ifndef __LIBCAMERA_OBJECT_H__\n #define __LIBCAMERA_OBJECT_H__\n \n+#include <condition_variable>\n #include <list>\n #include <memory>\n+#include <mutex>\n #include <vector>\n \n #include <libcamera/bound_method.h>\n@@ -28,6 +30,23 @@ enum InvocationType {\n \tInvocationTypeBlocking,\n };\n \n+class ObjectConditionVariable\n+{\n+public:\n+\tObjectConditionVariable()\n+\t\t: delivered_(false)\n+\t{\n+\t}\n+\n+\tvoid notifyReception();\n+\tvoid waitDelivery();\n+\n+private:\n+\tstd::condition_variable cv_;\n+\tstd::mutex mutex_;\n+\tbool delivered_;\n+};\n+\n class Object\n {\n public:\ndiff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp\nindex d7c9ac970d1c..88054aba3454 100644\n--- a/src/libcamera/object.cpp\n+++ b/src/libcamera/object.cpp\n@@ -52,6 +52,52 @@ LOG_DEFINE_CATEGORY(Object)\n  * the called method is not executed\n  */\n \n+/**\n+ * \\class ObjectConditionVariable\n+ * \\brief Object synchronization primitive that wraps a std::condition_variable\n+ *\n+ * The ObjectConditionVariable class provides an object synchronization\n+ * primitive to synchronize Object running in different execution context.\n+ *\n+ * It wraps an std::condition_variable that protects a shared variable.\n+ *\n+ * The class is used to implement blocking message delivery between Object\n+ * instances running in different execution context.\n+ */\n+\n+/**\n+ * \\fn ObjectConditionVariable::ObjectConditionVariable()\n+ * \\brief Create an ObjectConditionVariable with the shared variable initialized\n+ * to false\n+ */\n+\n+/**\n+ * \\brief Notify the ObjectConditionVariable to signal message reception\n+ */\n+void ObjectConditionVariable::notifyReception()\n+{\n+\t{\n+\t\tMutexLocker locker(mutex_);\n+\t\tdelivered_ = true;\n+\t}\n+\tcv_.notify_one();\n+}\n+\n+/**\n+ * \\brief Wait for the ObjectConditionVariable to be signaled\n+ *\n+ * Wait for the ObjectConditionVariable to be signaled by suspending the Object\n+ * on the wrapped std::condition_variable. If the shared condition\n+ * variable has already been set to true by the Object that was meant to\n+ * signal the ObjectConditionVariable before waitDelivery() is invoked,\n+ * the operation returns immediately.\n+ */\n+void ObjectConditionVariable::waitDelivery()\n+{\n+\tMutexLocker locker(mutex_);\n+\tcv_.wait(locker, [&] { return delivered_; });\n+}\n+\n /**\n  * \\class Object\n  * \\brief Base object to support automatic signal disconnection\n","prefixes":["libcamera-devel","3/6"]}