Files
external_libcamera/include/libcamera/timer.h
Laurent Pinchart 6ecf99a708 libcamera: timer: Bind timers to threads
The Timer instances are registered with the event dispatcher instance of
the CameraManager. This makes it impossible to use timers in other
threads.

Fix this by inheriting from Object, which allows binding instances to a
thread, and register them with the event dispatcher for the thread they
are bound to.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-08-17 18:32:42 +03:00

48 lines
786 B
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* timer.h - Generic timer
*/
#ifndef __LIBCAMERA_TIMER_H__
#define __LIBCAMERA_TIMER_H__
#include <cstdint>
#include <libcamera/object.h>
#include <libcamera/signal.h>
namespace libcamera {
class Message;
class Timer : public Object
{
public:
Timer();
~Timer();
void start(unsigned int msec);
void stop();
bool isRunning() const;
unsigned int interval() const { return interval_; }
uint64_t deadline() const { return deadline_; }
Signal<Timer *> timeout;
protected:
void message(Message *msg) override;
private:
void registerTimer();
void unregisterTimer();
unsigned int interval_;
uint64_t deadline_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_TIMER_H__ */