[{"id":2408,"web_url":"https://patchwork.libcamera.org/comment/2408/","msgid":"<20190815090923.6uuevzzt4joqoj2y@uno.localdomain>","date":"2019-08-15T09:09:23","subject":"Re: [libcamera-devel] [PATCH 07/18] libcamera: object: Notify\n\tobjects of thread move","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Mon, Aug 12, 2019 at 03:46:31PM +0300, Laurent Pinchart wrote:\n> Send a synchronous message to objects just before they get moved to a\n> new thread. This allows the object to perform any required processing.\n> EventNotifier and Timer objects will use this mechanism to move\n> themselves to the new thread's event disaptcher.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  include/libcamera/object.h      |  3 +++\n>  src/libcamera/include/message.h |  1 +\n>  src/libcamera/message.cpp       |  2 ++\n>  src/libcamera/object.cpp        | 26 ++++++++++++++++++++++++++\n>  4 files changed, 32 insertions(+)\n>\n> diff --git a/include/libcamera/object.h b/include/libcamera/object.h\n> index 869200a57d8c..14b939a9bd3d 100644\n> --- a/include/libcamera/object.h\n> +++ b/include/libcamera/object.h\n> @@ -27,6 +27,7 @@ public:\n>  \tvirtual ~Object();\n>\n>  \tvoid postMessage(std::unique_ptr<Message> msg);\n> +\tvoid sendMessage(Message *msg);\n>\n>  \ttemplate<typename T, typename... Args, typename std::enable_if<std::is_base_of<Object, T>::value>::type * = nullptr>\n>  \tvoid invokeMethod(void (T::*func)(Args...), Args... args)\n> @@ -52,6 +53,8 @@ private:\n>\n>  \tvoid invokeMethod(BoundMethodBase *method, void *pack);\n>\n> +\tvoid notifyThreadMove();\n> +\n>  \tvoid connect(SignalBase *signal);\n>  \tvoid disconnect(SignalBase *signal);\n>\n> diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h\n> index 92717e316cc3..1cfde5669ede 100644\n> --- a/src/libcamera/include/message.h\n> +++ b/src/libcamera/include/message.h\n> @@ -23,6 +23,7 @@ public:\n>  \tenum Type {\n>  \t\tNone = 0,\n>  \t\tInvokeMessage = 1,\n> +\t\tThreadMoveMessage = 2,\n>  \t\tUserMessage = 1000,\n>  \t};\n>\n> diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp\n> index f6c39d40fc73..efafb655c17e 100644\n> --- a/src/libcamera/message.cpp\n> +++ b/src/libcamera/message.cpp\n> @@ -47,6 +47,8 @@ std::atomic_uint Message::nextUserType_{ Message::UserMessage };\n>   * \\brief Invalid message type\n>   * \\var Message::InvokeMessage\n>   * \\brief Asynchronous method invocation across threads\n> + * \\var Message::ThreadMoveMessage\n> + * \\brief Object is being moved to a different thread\n>   * \\var Message::UserMessage\n>   * \\brief First value available for user-defined messages\n>   */\n> diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp\n> index 7d70ce21b5d0..7c68ec01f78c 100644\n> --- a/src/libcamera/object.cpp\n> +++ b/src/libcamera/object.cpp\n> @@ -74,6 +74,20 @@ void Object::postMessage(std::unique_ptr<Message> msg)\n>  \tthread()->postMessage(std::move(msg), this);\n>  }\n>\n> +/**\n> + * \\brief Send a message directly to the object\n> + * \\param[in] msg The message\n> + *\n> + * This method sends the message \\a msg directly to the object, delivering it\n> + * synchronously through the message() method in the current thread. Message\n> + * ownership is not passed to the method, and the caller shall delete the\n> + * message after this call.\n> + */\n> +void Object::sendMessage(Message *msg)\n> +{\n> +\tmessage(msg);\n> +}\n> +\n>  /**\n>   * \\brief Message handler for the object\n>   * \\param[in] msg The message\n> @@ -135,6 +149,10 @@ void Object::invokeMethod(BoundMethodBase *method, void *args)\n>   * This method moves the object from the current thread to the new \\a thread.\n>   * It shall be called from the thread in which the object currently lives,\n>   * otherwise the behaviour is undefined.\n> + *\n> + * Before the object is moved, a Message::ThreadMoveMessage message is sent to\n> + * it. The message() method can be reimplement in derived classes to be notified\n> + * of the upcoming thread move and perform any required processing.\n>   */\n>  void Object::moveToThread(Thread *thread)\n>  {\n> @@ -143,9 +161,17 @@ void Object::moveToThread(Thread *thread)\n>  \tif (thread_ == thread)\n>  \t\treturn;\n>\n> +\tnotifyThreadMove();\n> +\n>  \tthread->moveObject(this);\n>  }\n>\n> +void Object::notifyThreadMove()\n> +{\n> +\tMessage msg(Message::ThreadMoveMessage);\n> +\tsendMessage(&msg);\n\nI missed why you can't call message(&msg) directly here.\n\n> +}\n> +\n>  void Object::connect(SignalBase *signal)\n>  {\n>  \tsignals_.push_back(signal);\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D96060E2C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Aug 2019 11:07:57 +0200 (CEST)","from uno.localdomain\n\t(host64-130-dynamic.5-87-r.retail.telecomitalia.it [87.5.130.64])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id 96FC9240004;\n\tThu, 15 Aug 2019 09:07:56 +0000 (UTC)"],"Date":"Thu, 15 Aug 2019 11:09:23 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190815090923.6uuevzzt4joqoj2y@uno.localdomain>","References":"<20190812124642.24287-1-laurent.pinchart@ideasonboard.com>\n\t<20190812124642.24287-8-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"xhtj6ok6zf65n7hi\"","Content-Disposition":"inline","In-Reply-To":"<20190812124642.24287-8-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 07/18] libcamera: object: Notify\n\tobjects of thread move","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Thu, 15 Aug 2019 09:07:57 -0000"}},{"id":2411,"web_url":"https://patchwork.libcamera.org/comment/2411/","msgid":"<20190815095155.GC5011@pendragon.ideasonboard.com>","date":"2019-08-15T09:51:55","subject":"Re: [libcamera-devel] [PATCH 07/18] libcamera: object: Notify\n\tobjects of thread move","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Thu, Aug 15, 2019 at 11:09:23AM +0200, Jacopo Mondi wrote:\n> On Mon, Aug 12, 2019 at 03:46:31PM +0300, Laurent Pinchart wrote:\n> > Send a synchronous message to objects just before they get moved to a\n> > new thread. This allows the object to perform any required processing.\n> > EventNotifier and Timer objects will use this mechanism to move\n> > themselves to the new thread's event disaptcher.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  include/libcamera/object.h      |  3 +++\n> >  src/libcamera/include/message.h |  1 +\n> >  src/libcamera/message.cpp       |  2 ++\n> >  src/libcamera/object.cpp        | 26 ++++++++++++++++++++++++++\n> >  4 files changed, 32 insertions(+)\n> >\n> > diff --git a/include/libcamera/object.h b/include/libcamera/object.h\n> > index 869200a57d8c..14b939a9bd3d 100644\n> > --- a/include/libcamera/object.h\n> > +++ b/include/libcamera/object.h\n> > @@ -27,6 +27,7 @@ public:\n> >  \tvirtual ~Object();\n> >\n> >  \tvoid postMessage(std::unique_ptr<Message> msg);\n> > +\tvoid sendMessage(Message *msg);\n> >\n> >  \ttemplate<typename T, typename... Args, typename std::enable_if<std::is_base_of<Object, T>::value>::type * = nullptr>\n> >  \tvoid invokeMethod(void (T::*func)(Args...), Args... args)\n> > @@ -52,6 +53,8 @@ private:\n> >\n> >  \tvoid invokeMethod(BoundMethodBase *method, void *pack);\n> >\n> > +\tvoid notifyThreadMove();\n> > +\n> >  \tvoid connect(SignalBase *signal);\n> >  \tvoid disconnect(SignalBase *signal);\n> >\n> > diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h\n> > index 92717e316cc3..1cfde5669ede 100644\n> > --- a/src/libcamera/include/message.h\n> > +++ b/src/libcamera/include/message.h\n> > @@ -23,6 +23,7 @@ public:\n> >  \tenum Type {\n> >  \t\tNone = 0,\n> >  \t\tInvokeMessage = 1,\n> > +\t\tThreadMoveMessage = 2,\n> >  \t\tUserMessage = 1000,\n> >  \t};\n> >\n> > diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp\n> > index f6c39d40fc73..efafb655c17e 100644\n> > --- a/src/libcamera/message.cpp\n> > +++ b/src/libcamera/message.cpp\n> > @@ -47,6 +47,8 @@ std::atomic_uint Message::nextUserType_{ Message::UserMessage };\n> >   * \\brief Invalid message type\n> >   * \\var Message::InvokeMessage\n> >   * \\brief Asynchronous method invocation across threads\n> > + * \\var Message::ThreadMoveMessage\n> > + * \\brief Object is being moved to a different thread\n> >   * \\var Message::UserMessage\n> >   * \\brief First value available for user-defined messages\n> >   */\n> > diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp\n> > index 7d70ce21b5d0..7c68ec01f78c 100644\n> > --- a/src/libcamera/object.cpp\n> > +++ b/src/libcamera/object.cpp\n> > @@ -74,6 +74,20 @@ void Object::postMessage(std::unique_ptr<Message> msg)\n> >  \tthread()->postMessage(std::move(msg), this);\n> >  }\n> >\n> > +/**\n> > + * \\brief Send a message directly to the object\n> > + * \\param[in] msg The message\n> > + *\n> > + * This method sends the message \\a msg directly to the object, delivering it\n> > + * synchronously through the message() method in the current thread. Message\n> > + * ownership is not passed to the method, and the caller shall delete the\n> > + * message after this call.\n> > + */\n> > +void Object::sendMessage(Message *msg)\n> > +{\n> > +\tmessage(msg);\n> > +}\n> > +\n> >  /**\n> >   * \\brief Message handler for the object\n> >   * \\param[in] msg The message\n> > @@ -135,6 +149,10 @@ void Object::invokeMethod(BoundMethodBase *method, void *args)\n> >   * This method moves the object from the current thread to the new \\a thread.\n> >   * It shall be called from the thread in which the object currently lives,\n> >   * otherwise the behaviour is undefined.\n> > + *\n> > + * Before the object is moved, a Message::ThreadMoveMessage message is sent to\n> > + * it. The message() method can be reimplement in derived classes to be notified\n> > + * of the upcoming thread move and perform any required processing.\n> >   */\n> >  void Object::moveToThread(Thread *thread)\n> >  {\n> > @@ -143,9 +161,17 @@ void Object::moveToThread(Thread *thread)\n> >  \tif (thread_ == thread)\n> >  \t\treturn;\n> >\n> > +\tnotifyThreadMove();\n> > +\n> >  \tthread->moveObject(this);\n> >  }\n> >\n> > +void Object::notifyThreadMove()\n> > +{\n> > +\tMessage msg(Message::ThreadMoveMessage);\n> > +\tsendMessage(&msg);\n> \n> I missed why you can't call message(&msg) directly here.\n\nI could do that. I wanted to provide a public function to send messages\nto objects though, and I thought I could then as well use it here. It\nmakes no difference today, but maybe we'll have more code in\nsendMessage() tomorrow. We could of course then change this function.\nShould I drop sendMessage() for now ?\n\n> > +}\n> > +\n> >  void Object::connect(SignalBase *signal)\n> >  {\n> >  \tsignals_.push_back(signal);","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ED94A60E2C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Aug 2019 11:51:58 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 59A862B2;\n\tThu, 15 Aug 2019 11:51:58 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565862718;\n\tbh=ZeO7KLThmW9c2Q8dXJt6Fydfw+HvVPqhcaXHBze1pF4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=nlsOi91WrfFFnzwHQH2T7xHz6Z0ZwnZ4BphVwj2nSD3VTnE8Z4hF+nDs8lcjmyQXy\n\t4MnHgupUMTNvzst/PiObmSp4HuGCeuuPRJwMS0cYVqNI5M3hR9uDWRawKI+iLpDOfg\n\tmy0gIWZ0CRjrDrWsYcbdLzBPj9Q6LExbNXy3lTzo=","Date":"Thu, 15 Aug 2019 12:51:55 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190815095155.GC5011@pendragon.ideasonboard.com>","References":"<20190812124642.24287-1-laurent.pinchart@ideasonboard.com>\n\t<20190812124642.24287-8-laurent.pinchart@ideasonboard.com>\n\t<20190815090923.6uuevzzt4joqoj2y@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190815090923.6uuevzzt4joqoj2y@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 07/18] libcamera: object: Notify\n\tobjects of thread move","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Thu, 15 Aug 2019 09:51:59 -0000"}},{"id":2416,"web_url":"https://patchwork.libcamera.org/comment/2416/","msgid":"<20190815100106.v2zefmy7cpdzq63p@uno.localdomain>","date":"2019-08-15T10:01:06","subject":"Re: [libcamera-devel] [PATCH 07/18] libcamera: object: Notify\n\tobjects of thread move","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Thu, Aug 15, 2019 at 12:51:55PM +0300, Laurent Pinchart wrote:\n> Hi Jacopo,\n>\n> On Thu, Aug 15, 2019 at 11:09:23AM +0200, Jacopo Mondi wrote:\n> > On Mon, Aug 12, 2019 at 03:46:31PM +0300, Laurent Pinchart wrote:\n> > > Send a synchronous message to objects just before they get moved to a\n> > > new thread. This allows the object to perform any required processing.\n> > > EventNotifier and Timer objects will use this mechanism to move\n> > > themselves to the new thread's event disaptcher.\n> > >\n> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > ---\n> > >  include/libcamera/object.h      |  3 +++\n> > >  src/libcamera/include/message.h |  1 +\n> > >  src/libcamera/message.cpp       |  2 ++\n> > >  src/libcamera/object.cpp        | 26 ++++++++++++++++++++++++++\n> > >  4 files changed, 32 insertions(+)\n> > >\n> > > diff --git a/include/libcamera/object.h b/include/libcamera/object.h\n> > > index 869200a57d8c..14b939a9bd3d 100644\n> > > --- a/include/libcamera/object.h\n> > > +++ b/include/libcamera/object.h\n> > > @@ -27,6 +27,7 @@ public:\n> > >  \tvirtual ~Object();\n> > >\n> > >  \tvoid postMessage(std::unique_ptr<Message> msg);\n> > > +\tvoid sendMessage(Message *msg);\n> > >\n> > >  \ttemplate<typename T, typename... Args, typename std::enable_if<std::is_base_of<Object, T>::value>::type * = nullptr>\n> > >  \tvoid invokeMethod(void (T::*func)(Args...), Args... args)\n> > > @@ -52,6 +53,8 @@ private:\n> > >\n> > >  \tvoid invokeMethod(BoundMethodBase *method, void *pack);\n> > >\n> > > +\tvoid notifyThreadMove();\n> > > +\n> > >  \tvoid connect(SignalBase *signal);\n> > >  \tvoid disconnect(SignalBase *signal);\n> > >\n> > > diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h\n> > > index 92717e316cc3..1cfde5669ede 100644\n> > > --- a/src/libcamera/include/message.h\n> > > +++ b/src/libcamera/include/message.h\n> > > @@ -23,6 +23,7 @@ public:\n> > >  \tenum Type {\n> > >  \t\tNone = 0,\n> > >  \t\tInvokeMessage = 1,\n> > > +\t\tThreadMoveMessage = 2,\n> > >  \t\tUserMessage = 1000,\n> > >  \t};\n> > >\n> > > diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp\n> > > index f6c39d40fc73..efafb655c17e 100644\n> > > --- a/src/libcamera/message.cpp\n> > > +++ b/src/libcamera/message.cpp\n> > > @@ -47,6 +47,8 @@ std::atomic_uint Message::nextUserType_{ Message::UserMessage };\n> > >   * \\brief Invalid message type\n> > >   * \\var Message::InvokeMessage\n> > >   * \\brief Asynchronous method invocation across threads\n> > > + * \\var Message::ThreadMoveMessage\n> > > + * \\brief Object is being moved to a different thread\n> > >   * \\var Message::UserMessage\n> > >   * \\brief First value available for user-defined messages\n> > >   */\n> > > diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp\n> > > index 7d70ce21b5d0..7c68ec01f78c 100644\n> > > --- a/src/libcamera/object.cpp\n> > > +++ b/src/libcamera/object.cpp\n> > > @@ -74,6 +74,20 @@ void Object::postMessage(std::unique_ptr<Message> msg)\n> > >  \tthread()->postMessage(std::move(msg), this);\n> > >  }\n> > >\n> > > +/**\n> > > + * \\brief Send a message directly to the object\n> > > + * \\param[in] msg The message\n> > > + *\n> > > + * This method sends the message \\a msg directly to the object, delivering it\n> > > + * synchronously through the message() method in the current thread. Message\n> > > + * ownership is not passed to the method, and the caller shall delete the\n> > > + * message after this call.\n> > > + */\n> > > +void Object::sendMessage(Message *msg)\n> > > +{\n> > > +\tmessage(msg);\n> > > +}\n> > > +\n> > >  /**\n> > >   * \\brief Message handler for the object\n> > >   * \\param[in] msg The message\n> > > @@ -135,6 +149,10 @@ void Object::invokeMethod(BoundMethodBase *method, void *args)\n> > >   * This method moves the object from the current thread to the new \\a thread.\n> > >   * It shall be called from the thread in which the object currently lives,\n> > >   * otherwise the behaviour is undefined.\n> > > + *\n> > > + * Before the object is moved, a Message::ThreadMoveMessage message is sent to\n> > > + * it. The message() method can be reimplement in derived classes to be notified\n> > > + * of the upcoming thread move and perform any required processing.\n> > >   */\n> > >  void Object::moveToThread(Thread *thread)\n> > >  {\n> > > @@ -143,9 +161,17 @@ void Object::moveToThread(Thread *thread)\n> > >  \tif (thread_ == thread)\n> > >  \t\treturn;\n> > >\n> > > +\tnotifyThreadMove();\n> > > +\n> > >  \tthread->moveObject(this);\n> > >  }\n> > >\n> > > +void Object::notifyThreadMove()\n> > > +{\n> > > +\tMessage msg(Message::ThreadMoveMessage);\n> > > +\tsendMessage(&msg);\n> >\n> > I missed why you can't call message(&msg) directly here.\n>\n> I could do that. I wanted to provide a public function to send messages\n> to objects though, and I thought I could then as well use it here. It\n> makes no difference today, but maybe we'll have more code in\n> sendMessage() tomorrow. We could of course then change this function.\n> Should I drop sendMessage() for now ?\n>\n\nNot something I feel strong about, just wondering if I were missing\nsomething. Although providing a public 'sendMessage()' and not using\nit if not internally might open doors to misuse?\n\nI'll let you judge what's better here\n\nThanks\n   j\n\n> > > +}\n> > > +\n> > >  void Object::connect(SignalBase *signal)\n> > >  {\n> > >  \tsignals_.push_back(signal);\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net\n\t[217.70.183.197])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 62DB360E2C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Aug 2019 11:59:48 +0200 (CEST)","from uno.localdomain\n\t(host64-130-dynamic.5-87-r.retail.telecomitalia.it [87.5.130.64])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay5-d.mail.gandi.net (Postfix) with ESMTPSA id AB8D01C000A;\n\tThu, 15 Aug 2019 09:59:47 +0000 (UTC)"],"X-Originating-IP":"87.5.130.64","Date":"Thu, 15 Aug 2019 12:01:06 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190815100106.v2zefmy7cpdzq63p@uno.localdomain>","References":"<20190812124642.24287-1-laurent.pinchart@ideasonboard.com>\n\t<20190812124642.24287-8-laurent.pinchart@ideasonboard.com>\n\t<20190815090923.6uuevzzt4joqoj2y@uno.localdomain>\n\t<20190815095155.GC5011@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"iggpt6rxrz6cd6m7\"","Content-Disposition":"inline","In-Reply-To":"<20190815095155.GC5011@pendragon.ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 07/18] libcamera: object: Notify\n\tobjects of thread move","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Thu, 15 Aug 2019 09:59:48 -0000"}},{"id":2434,"web_url":"https://patchwork.libcamera.org/comment/2434/","msgid":"<20190817144026.GK16603@wyvern>","date":"2019-08-17T14:40:26","subject":"Re: [libcamera-devel] [PATCH 07/18] libcamera: object: Notify\n\tobjects of thread move","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nOn 2019-08-15 12:51:55 +0300, Laurent Pinchart wrote:\n> Hi Jacopo,\n> \n> On Thu, Aug 15, 2019 at 11:09:23AM +0200, Jacopo Mondi wrote:\n> > On Mon, Aug 12, 2019 at 03:46:31PM +0300, Laurent Pinchart wrote:\n> > > Send a synchronous message to objects just before they get moved to a\n> > > new thread. This allows the object to perform any required processing.\n> > > EventNotifier and Timer objects will use this mechanism to move\n> > > themselves to the new thread's event disaptcher.\n> > >\n> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > ---\n> > >  include/libcamera/object.h      |  3 +++\n> > >  src/libcamera/include/message.h |  1 +\n> > >  src/libcamera/message.cpp       |  2 ++\n> > >  src/libcamera/object.cpp        | 26 ++++++++++++++++++++++++++\n> > >  4 files changed, 32 insertions(+)\n> > >\n> > > diff --git a/include/libcamera/object.h b/include/libcamera/object.h\n> > > index 869200a57d8c..14b939a9bd3d 100644\n> > > --- a/include/libcamera/object.h\n> > > +++ b/include/libcamera/object.h\n> > > @@ -27,6 +27,7 @@ public:\n> > >  \tvirtual ~Object();\n> > >\n> > >  \tvoid postMessage(std::unique_ptr<Message> msg);\n> > > +\tvoid sendMessage(Message *msg);\n> > >\n> > >  \ttemplate<typename T, typename... Args, typename std::enable_if<std::is_base_of<Object, T>::value>::type * = nullptr>\n> > >  \tvoid invokeMethod(void (T::*func)(Args...), Args... args)\n> > > @@ -52,6 +53,8 @@ private:\n> > >\n> > >  \tvoid invokeMethod(BoundMethodBase *method, void *pack);\n> > >\n> > > +\tvoid notifyThreadMove();\n> > > +\n> > >  \tvoid connect(SignalBase *signal);\n> > >  \tvoid disconnect(SignalBase *signal);\n> > >\n> > > diff --git a/src/libcamera/include/message.h b/src/libcamera/include/message.h\n> > > index 92717e316cc3..1cfde5669ede 100644\n> > > --- a/src/libcamera/include/message.h\n> > > +++ b/src/libcamera/include/message.h\n> > > @@ -23,6 +23,7 @@ public:\n> > >  \tenum Type {\n> > >  \t\tNone = 0,\n> > >  \t\tInvokeMessage = 1,\n> > > +\t\tThreadMoveMessage = 2,\n> > >  \t\tUserMessage = 1000,\n> > >  \t};\n> > >\n> > > diff --git a/src/libcamera/message.cpp b/src/libcamera/message.cpp\n> > > index f6c39d40fc73..efafb655c17e 100644\n> > > --- a/src/libcamera/message.cpp\n> > > +++ b/src/libcamera/message.cpp\n> > > @@ -47,6 +47,8 @@ std::atomic_uint Message::nextUserType_{ Message::UserMessage };\n> > >   * \\brief Invalid message type\n> > >   * \\var Message::InvokeMessage\n> > >   * \\brief Asynchronous method invocation across threads\n> > > + * \\var Message::ThreadMoveMessage\n> > > + * \\brief Object is being moved to a different thread\n> > >   * \\var Message::UserMessage\n> > >   * \\brief First value available for user-defined messages\n> > >   */\n> > > diff --git a/src/libcamera/object.cpp b/src/libcamera/object.cpp\n> > > index 7d70ce21b5d0..7c68ec01f78c 100644\n> > > --- a/src/libcamera/object.cpp\n> > > +++ b/src/libcamera/object.cpp\n> > > @@ -74,6 +74,20 @@ void Object::postMessage(std::unique_ptr<Message> msg)\n> > >  \tthread()->postMessage(std::move(msg), this);\n> > >  }\n> > >\n> > > +/**\n> > > + * \\brief Send a message directly to the object\n> > > + * \\param[in] msg The message\n> > > + *\n> > > + * This method sends the message \\a msg directly to the object, delivering it\n> > > + * synchronously through the message() method in the current thread. Message\n> > > + * ownership is not passed to the method, and the caller shall delete the\n> > > + * message after this call.\n> > > + */\n> > > +void Object::sendMessage(Message *msg)\n> > > +{\n> > > +\tmessage(msg);\n> > > +}\n> > > +\n> > >  /**\n> > >   * \\brief Message handler for the object\n> > >   * \\param[in] msg The message\n> > > @@ -135,6 +149,10 @@ void Object::invokeMethod(BoundMethodBase *method, void *args)\n> > >   * This method moves the object from the current thread to the new \\a thread.\n> > >   * It shall be called from the thread in which the object currently lives,\n> > >   * otherwise the behaviour is undefined.\n> > > + *\n> > > + * Before the object is moved, a Message::ThreadMoveMessage message is sent to\n> > > + * it. The message() method can be reimplement in derived classes to be notified\n> > > + * of the upcoming thread move and perform any required processing.\n> > >   */\n> > >  void Object::moveToThread(Thread *thread)\n> > >  {\n> > > @@ -143,9 +161,17 @@ void Object::moveToThread(Thread *thread)\n> > >  \tif (thread_ == thread)\n> > >  \t\treturn;\n> > >\n> > > +\tnotifyThreadMove();\n> > > +\n> > >  \tthread->moveObject(this);\n> > >  }\n> > >\n> > > +void Object::notifyThreadMove()\n> > > +{\n> > > +\tMessage msg(Message::ThreadMoveMessage);\n> > > +\tsendMessage(&msg);\n> > \n> > I missed why you can't call message(&msg) directly here.\n> \n> I could do that. I wanted to provide a public function to send messages\n> to objects though, and I thought I could then as well use it here. It\n> makes no difference today, but maybe we'll have more code in\n> sendMessage() tomorrow. We could of course then change this function.\n> Should I drop sendMessage() for now ?\n\nThis is rather complex as it is, so if it's not used I think we should \ndrop it until it's needed. But I don't feel strongly about it.\n\nWith or without sendMessage() removed,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> \n> > > +}\n> > > +\n> > >  void Object::connect(SignalBase *signal)\n> > >  {\n> > >  \tsignals_.push_back(signal);\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-ed1-x544.google.com (mail-ed1-x544.google.com\n\t[IPv6:2a00:1450:4864:20::544])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C6C45600F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 16:40:29 +0200 (CEST)","by mail-ed1-x544.google.com with SMTP id g8so7506975edm.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 07:40:29 -0700 (PDT)","from localhost ([185.224.57.161]) by smtp.gmail.com with ESMTPSA id\n\tw8sm919483edx.89.2019.08.17.07.40.28\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 17 Aug 2019 07:40:28 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=sFgDV75M/ChA5/QW/FA0xzMCdnqtN2H3ZQv0/Dc+h/c=;\n\tb=jbjPa9glByaB6jgtcoa46c7TC95pU9rHztAs2kcb/6kN53VuExt8KR+TMORzE/0Rv2\n\tcbD4HHEWI4wS1XfcwMj+cNlI3u3DZhB0la+QaQ9SxvLs3HUXj9wRkve+0BmwxY9OSN7j\n\tHT6DRevlsKHroYFSo4F3Q+XmkgwQMUtGfWTeZ7xRqPUoMzqhNVeV8XpH4fSnywHm9LOT\n\tRmcn4KCDzmIK9H+E7iGCQY3yRa2MeK1Ok2Vf0y6/8qkHFwz5ME953bKAcO5GMLGEaNfA\n\tHOWwXHnQWEVv4UYhBAMLX3+X5JrOiBzrXbpWqCbhECbKjvPUKpFSPgQayCXUzuIjlePe\n\tH5pQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=sFgDV75M/ChA5/QW/FA0xzMCdnqtN2H3ZQv0/Dc+h/c=;\n\tb=IpPlctNJCp2402OYCYQH+k+Gd3UtxsV/7poWVdpZQJJx13vskAHILY56kKDIGMaDZe\n\tNFmvJ6CUBKyavjsxqjRSqiV+0WxAIXj4ocIHILEtbRny9kW9igZKj7aMzPOIkn4EHCUt\n\t5MvpOtarEWMnnZSORvCM8hY2zItM/xN1ZLZlutYqN+QMhd6jipt8rDDdMPTwqIpR85IQ\n\tuH4JD0rI5z4Mw2/9Ec2uobS/dpSLS/T/hMPZI0RTCR8pIqnrdKktlLmEf7THrHR5ffmt\n\tg4xCm7SQzJ4ZNK64VQdLLNbxO4ga1ieuE44fQKKsJZd6qeclDm/J3eDFinoIlHojrOnn\n\tnilg==","X-Gm-Message-State":"APjAAAVjGsL54m4eECgYU9DhbJbhHxw7+9A6pIhD2WIFOMqRGwt3980U\n\thp0Lp2ws8KcZsTXLD0T2zXZjWOBljwM=","X-Google-Smtp-Source":"APXvYqxmPKOj4qzduM3eZXWosYlDeQxXJC4qtA803XS+UjDSO8+GVZ20Zxxzq6LllhnhviElA4ARxw==","X-Received":"by 2002:a17:906:bb0f:: with SMTP id\n\tjz15mr2344374ejb.264.1566052829366; \n\tSat, 17 Aug 2019 07:40:29 -0700 (PDT)","Date":"Sat, 17 Aug 2019 16:40:26 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo@jmondi.org>, libcamera-devel@lists.libcamera.org","Message-ID":"<20190817144026.GK16603@wyvern>","References":"<20190812124642.24287-1-laurent.pinchart@ideasonboard.com>\n\t<20190812124642.24287-8-laurent.pinchart@ideasonboard.com>\n\t<20190815090923.6uuevzzt4joqoj2y@uno.localdomain>\n\t<20190815095155.GC5011@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190815095155.GC5011@pendragon.ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH 07/18] libcamera: object: Notify\n\tobjects of thread move","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Sat, 17 Aug 2019 14:40:30 -0000"}}]