Skip to content
Snippets Groups Projects

Draft: Resolve "Multi-Threading"

Open Tobias Frisch requested to merge 43-multi-threading into develop
5 files
+ 56
26
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 20
0
#pragma once
#include <functional>
#include <mutex>
namespace vkcv {
@@ -17,6 +18,7 @@ namespace vkcv {
struct event {
private:
std::vector<typename event_function<T...>::type> m_handles;
std::mutex m_mutex;
public:
@@ -25,9 +27,13 @@ namespace vkcv {
* @param arguments of the given function
*/
void operator()(T... arguments) {
lock();
for (auto &handle : this->m_handles) {
handle(arguments...);
}
unlock();
}
/**
@@ -49,6 +55,20 @@ namespace vkcv {
this->m_handles.end()
);
}
/**
* locks the event so its function handles won't be called
*/
void lock() {
m_mutex.lock();
}
/**
* unlocks the event so its function handles can be called after locking
*/
void unlock() {
m_mutex.unlock();
}
event() = default;
Loading