Files
NP_Midterm/impl/Utils/Thread.cpp

37 lines
531 B
C++

#include "Utils/Thread.hpp"
namespace Chattr {
Thread::Thread(Thread&& other) noexcept {
other.detach();
}
Thread& Thread::operator=(Thread&& other) noexcept {
other.detach();
return *this;
}
Thread::~Thread() {
if (!detached) {
spdlog::critical("There is not joined thread");
std::exit(EXIT_FAILURE);
}
}
void* Thread::join() {
#ifdef _WIN32
WaitForSingleObject(handle_, INFINITE);
#elif __linux__
pthread_join(handle_, returnValue);
#endif
return returnValue;
}
void Thread::detach() {
detached = true;
}
}