paysages3d/src/core/Thread.cpp

29 lines
450 B
C++

#include "Thread.h"
Thread::Thread(ThreadFunction function) : data(0), result(0), function(function) {
go.lock();
systhread = new thread([this]{ wait(); });
}
Thread::~Thread() {
}
void Thread::wait() {
unique_lock lock(go);
run();
}
void Thread::start(void *data) {
this->data = data;
go.unlock();
}
void *Thread::join() {
systhread->join();
return result;
}
void Thread::run() {
result = function(data);
}