You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

30 lines
594 B

#include "dispatcher.h"
Dispatcher::Dispatcher() {
connection=dispatcher.connect([this] {
functions_mutex.lock();
for(auto &function: functions) {
function();
}
functions.clear();
functions_mutex.unlock();
});
}
Dispatcher::~Dispatcher() {
disconnect();
functions_mutex.lock();
functions.clear();
functions_mutex.unlock();
}
void Dispatcher::post(std::function<void()> &&function) {
functions_mutex.lock();
functions.emplace_back(function);
functions_mutex.unlock();
dispatcher();
}
void Dispatcher::disconnect() {
connection.disconnect();
}