mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-15 16:35:06 +03:00
The bound method arguments pack will need to be accessed by the method invoker in order to retrieve the method return value when using a blocking connection type. We thus can't delete the pack unconditionally in the bound method target thread. We also can't delete it unconditionally in the invoker's thread, as for queued connections the pack will be used in the target thread after the invoker completes. This shows that ownership of the arguments pack is shared between two contexts. As a result, manage it using std::shared_ptr<>. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
70 lines
1.2 KiB
C++
70 lines
1.2 KiB
C++
/* 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__
|
|
|
|
#include <atomic>
|
|
|
|
#include <libcamera/bound_method.h>
|
|
|
|
namespace libcamera {
|
|
|
|
class BoundMethodBase;
|
|
class Object;
|
|
class Semaphore;
|
|
class Thread;
|
|
|
|
class Message
|
|
{
|
|
public:
|
|
enum Type {
|
|
None = 0,
|
|
InvokeMessage = 1,
|
|
ThreadMoveMessage = 2,
|
|
UserMessage = 1000,
|
|
};
|
|
|
|
Message(Type type);
|
|
virtual ~Message();
|
|
|
|
Type type() const { return type_; }
|
|
Object *receiver() const { return receiver_; }
|
|
|
|
static Type registerMessageType();
|
|
|
|
private:
|
|
friend class Thread;
|
|
|
|
Type type_;
|
|
Object *receiver_;
|
|
|
|
static std::atomic_uint nextUserType_;
|
|
};
|
|
|
|
class InvokeMessage : public Message
|
|
{
|
|
public:
|
|
InvokeMessage(BoundMethodBase *method,
|
|
std::shared_ptr<BoundMethodPackBase> pack,
|
|
Semaphore *semaphore = nullptr,
|
|
bool deleteMethod = false);
|
|
~InvokeMessage();
|
|
|
|
Semaphore *semaphore() const { return semaphore_; }
|
|
|
|
void invoke();
|
|
|
|
private:
|
|
BoundMethodBase *method_;
|
|
std::shared_ptr<BoundMethodPackBase> pack_;
|
|
Semaphore *semaphore_;
|
|
bool deleteMethod_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_MESSAGE_H__ */
|