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