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:
Laurent Pinchart
2019-07-11 10:20:15 +03:00
parent 525b19c410
commit 01b930964a
7 changed files with 354 additions and 2 deletions
+37
View File
@@ -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__ */
+9
View File
@@ -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_;
};