[RFC,v2,1/2] libcamera: base: thread: Make `removeMessages()` public
diff mbox series

Message ID 20250813102501.1645940-2-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: pipeline: virtual: Move image generation to separate thread
Related show

Commit Message

Barnabás Pőcze Aug. 13, 2025, 10:25 a.m. UTC
Sometimes there is a need to remove pending messages of an object. For example,
when the main purpose of a thread is to carry out work asynchronously using
invoke messages, then there might be a need to stop processing because some
kind of state has changed. This can be done in two main ways: flushing messages
or removing them. This changes enables the second option, which is useful if
the effects of the pending messages are no longer desired.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/base/thread.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Laurent Pinchart Aug. 13, 2025, 11:46 a.m. UTC | #1
Hi Barnabás,

Thank you for the patch.

On Wed, Aug 13, 2025 at 12:25:00PM +0200, Barnabás Pőcze wrote:
> Sometimes there is a need to remove pending messages of an object. For example,
> when the main purpose of a thread is to carry out work asynchronously using
> invoke messages, then there might be a need to stop processing because some
> kind of state has changed. This can be done in two main ways: flushing messages
> or removing them. This changes enables the second option, which is useful if
> the effects of the pending messages are no longer desired.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  include/libcamera/base/thread.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h
> index b9284c2c0..eb1a52ab1 100644
> --- a/include/libcamera/base/thread.h
> +++ b/include/libcamera/base/thread.h
> @@ -50,6 +50,7 @@ public:
>  
>  	void dispatchMessages(Message::Type type = Message::Type::None,
>  			      Object *receiver = nullptr);
> +	void removeMessages(Object *receiver);

I wonder if we should extend this with a message type, like in
dispatchMessages(). I suppose it can be done later.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
>  protected:
>  	int exec();
> @@ -64,7 +65,6 @@ private:
>  	void setThreadAffinityInternal();
>  
>  	void postMessage(std::unique_ptr<Message> msg, Object *receiver);
> -	void removeMessages(Object *receiver);
>  
>  	friend class Object;
>  	friend class ThreadData;
Barnabás Pőcze Aug. 13, 2025, 11:53 a.m. UTC | #2
2025. 08. 13. 13:46 keltezéssel, Laurent Pinchart írta:
> Hi Barnabás,
> 
> Thank you for the patch.
> 
> On Wed, Aug 13, 2025 at 12:25:00PM +0200, Barnabás Pőcze wrote:
>> Sometimes there is a need to remove pending messages of an object. For example,
>> when the main purpose of a thread is to carry out work asynchronously using
>> invoke messages, then there might be a need to stop processing because some
>> kind of state has changed. This can be done in two main ways: flushing messages
>> or removing them. This changes enables the second option, which is useful if
>> the effects of the pending messages are no longer desired.
>>
>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
>> ---
>>   include/libcamera/base/thread.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h
>> index b9284c2c0..eb1a52ab1 100644
>> --- a/include/libcamera/base/thread.h
>> +++ b/include/libcamera/base/thread.h
>> @@ -50,6 +50,7 @@ public:
>>   
>>   	void dispatchMessages(Message::Type type = Message::Type::None,
>>   			      Object *receiver = nullptr);
>> +	void removeMessages(Object *receiver);
> 
> I wonder if we should extend this with a message type, like in
> dispatchMessages(). I suppose it can be done later.

I'd started doing that but in the end I decided to take the simplest approach.


> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
>>   
>>   protected:
>>   	int exec();
>> @@ -64,7 +65,6 @@ private:
>>   	void setThreadAffinityInternal();
>>   
>>   	void postMessage(std::unique_ptr<Message> msg, Object *receiver);
>> -	void removeMessages(Object *receiver);
>>   
>>   	friend class Object;
>>   	friend class ThreadData;
>
Laurent Pinchart Aug. 13, 2025, 11:59 a.m. UTC | #3
On Wed, Aug 13, 2025 at 01:53:10PM +0200, Barnabás Pőcze wrote:
> 2025. 08. 13. 13:46 keltezéssel, Laurent Pinchart írta:
> > On Wed, Aug 13, 2025 at 12:25:00PM +0200, Barnabás Pőcze wrote:
> >> Sometimes there is a need to remove pending messages of an object. For example,
> >> when the main purpose of a thread is to carry out work asynchronously using
> >> invoke messages, then there might be a need to stop processing because some
> >> kind of state has changed. This can be done in two main ways: flushing messages
> >> or removing them. This changes enables the second option, which is useful if
> >> the effects of the pending messages are no longer desired.
> >>
> >> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> >> ---
> >>   include/libcamera/base/thread.h | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h
> >> index b9284c2c0..eb1a52ab1 100644
> >> --- a/include/libcamera/base/thread.h
> >> +++ b/include/libcamera/base/thread.h
> >> @@ -50,6 +50,7 @@ public:
> >>   
> >>   	void dispatchMessages(Message::Type type = Message::Type::None,
> >>   			      Object *receiver = nullptr);
> >> +	void removeMessages(Object *receiver);
> > 
> > I wonder if we should extend this with a message type, like in
> > dispatchMessages(). I suppose it can be done later.
> 
> I'd started doing that but in the end I decided to take the simplest approach.

In this particular use case I don't expect other message types to exist
in the queue, so it should be fine. I'm wondering if we won't regret it
later, when we'll post other types of messages and wonder why they don't
get delivered :-)

By the way, could you please also post a fix for the software ISP ?

> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > 
> >>   
> >>   protected:
> >>   	int exec();
> >> @@ -64,7 +65,6 @@ private:
> >>   	void setThreadAffinityInternal();
> >>   
> >>   	void postMessage(std::unique_ptr<Message> msg, Object *receiver);
> >> -	void removeMessages(Object *receiver);
> >>   
> >>   	friend class Object;
> >>   	friend class ThreadData;

Patch
diff mbox series

diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h
index b9284c2c0..eb1a52ab1 100644
--- a/include/libcamera/base/thread.h
+++ b/include/libcamera/base/thread.h
@@ -50,6 +50,7 @@  public:
 
 	void dispatchMessages(Message::Type type = Message::Type::None,
 			      Object *receiver = nullptr);
+	void removeMessages(Object *receiver);
 
 protected:
 	int exec();
@@ -64,7 +65,6 @@  private:
 	void setThreadAffinityInternal();
 
 	void postMessage(std::unique_ptr<Message> msg, Object *receiver);
-	void removeMessages(Object *receiver);
 
 	friend class Object;
 	friend class ThreadData;