Ken Van Hoeylandt 85e26636a3
C++ conversion (#80)
Converted project to C++
2024-11-22 20:26:08 +01:00

36 lines
619 B
C++

/**
* @file Dispatcher.h
*
* Dispatcher is a thread-safe code execution queue.
*/
#pragma once
#include "MessageQueue.h"
#include "Mutex.h"
namespace tt {
typedef void (*Callback)(void* data);
class Dispatcher {
private:
typedef struct {
Callback callback;
void* context;
} DispatcherMessage;
MessageQueue queue;
Mutex mutex;
DispatcherMessage buffer; // Buffer for consuming a message
public:
explicit Dispatcher(size_t queueLimit = 8);
~Dispatcher();
void dispatch(Callback callback, void* context);
bool consume(uint32_t timeout_ticks);
};
} // namespace