2020-02-15 11:15:43 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-10-09 14:16:51 +08:00
|
|
|
#include "concurrency/OSThread.h"
|
2020-07-06 00:54:30 +02:00
|
|
|
|
2020-10-09 14:16:51 +08:00
|
|
|
namespace concurrency
|
|
|
|
|
{
|
2020-02-15 11:15:43 -08:00
|
|
|
|
|
|
|
|
/**
|
2020-10-09 14:16:51 +08:00
|
|
|
* @brief Periodically invoke a callback. This just provides C-style callback conventions
|
2020-07-06 00:54:30 +02:00
|
|
|
* rather than a virtual function - FIXME, remove?
|
2020-02-15 11:15:43 -08:00
|
|
|
*/
|
2020-10-09 14:16:51 +08:00
|
|
|
class Periodic : public OSThread
|
2020-02-15 11:15:43 -08:00
|
|
|
{
|
2020-10-10 09:57:57 +08:00
|
|
|
int32_t (*callback)();
|
2020-02-15 11:15:43 -08:00
|
|
|
|
2020-03-18 19:15:51 -07:00
|
|
|
public:
|
|
|
|
|
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
|
2020-10-10 09:57:57 +08:00
|
|
|
Periodic(const char *name, int32_t (*_callback)()) : OSThread(name), callback(_callback) {}
|
2020-02-21 08:41:36 -08:00
|
|
|
|
2020-03-18 19:15:51 -07:00
|
|
|
protected:
|
2022-01-24 17:24:40 +00:00
|
|
|
int32_t runOnce() override { return callback(); }
|
2020-02-15 11:15:43 -08:00
|
|
|
};
|
2020-07-06 00:54:30 +02:00
|
|
|
|
|
|
|
|
} // namespace concurrency
|