libcamera: thread: Add a messaging passing API
Create a new Message class to model a message that can be passed to an object living in another thread. Only an invalid message type is currently defined, more messages will be added in the future. The Thread class is extended with a messages queue, and the Object class with thread affinity. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* message.h - Message queue support
|
||||
*/
|
||||
#ifndef __LIBCAMERA_MESSAGE_H__
|
||||
#define __LIBCAMERA_MESSAGE_H__
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Object;
|
||||
class Thread;
|
||||
|
||||
class Message
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
None = 0,
|
||||
};
|
||||
|
||||
Message(Type type);
|
||||
virtual ~Message();
|
||||
|
||||
Type type() const { return type_; }
|
||||
Object *receiver() const { return receiver_; }
|
||||
|
||||
private:
|
||||
friend class Thread;
|
||||
|
||||
Type type_;
|
||||
Object *receiver_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
||||
#endif /* __LIBCAMERA_MESSAGE_H__ */
|
||||
@@ -16,6 +16,8 @@
|
||||
namespace libcamera {
|
||||
|
||||
class EventDispatcher;
|
||||
class Message;
|
||||
class Object;
|
||||
class ThreadData;
|
||||
class ThreadMain;
|
||||
|
||||
@@ -49,9 +51,16 @@ private:
|
||||
void startThread();
|
||||
void finishThread();
|
||||
|
||||
void postMessage(std::unique_ptr<Message> msg, Object *receiver);
|
||||
void removeMessages(Object *receiver);
|
||||
void dispatchMessages();
|
||||
|
||||
friend class Object;
|
||||
friend class ThreadData;
|
||||
friend class ThreadMain;
|
||||
|
||||
void moveObject(Object *object);
|
||||
|
||||
std::thread thread_;
|
||||
ThreadData *data_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user