mirror of https://gitlab.com/cppit/jucipp
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.
31 lines
698 B
31 lines
698 B
#include "dispatcher.h" |
|
#include <vector> |
|
|
|
Dispatcher::Dispatcher() { |
|
connection=dispatcher.connect([this] { |
|
std::vector<std::list<std::function<void()>>::iterator> its; |
|
{ |
|
std::unique_lock<std::mutex> lock(functions_mutex); |
|
if(functions.empty()) |
|
return; |
|
its.reserve(functions.size()); |
|
for(auto it=functions.begin();it!=functions.end();++it) |
|
its.emplace_back(it); |
|
} |
|
for(auto &it: its) |
|
(*it)(); |
|
{ |
|
std::unique_lock<std::mutex> lock(functions_mutex); |
|
for(auto &it: its) |
|
functions.erase(it); |
|
} |
|
}); |
|
} |
|
|
|
Dispatcher::~Dispatcher() { |
|
disconnect(); |
|
} |
|
|
|
void Dispatcher::disconnect() { |
|
connection.disconnect(); |
|
}
|
|
|