X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=thread.cpp;h=d85be706ddf5e32003bad8105b1121edcf9ab315;hp=98c743c594313704281c2360f2d5688c0c691cab;hb=50651c954803c1941e6ad1bb494712891c18f7d2;hpb=0ff463f4df8e085ba88f8ede735f16b140a2bf8e diff --git a/thread.cpp b/thread.cpp index 98c743c..d85be70 100644 --- a/thread.cpp +++ b/thread.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -8,26 +7,26 @@ #include #include "log.h" -#include "mutexlock.h" #include "thread.h" +using namespace std; + Thread::~Thread() {} void Thread::run() { - pthread_mutex_init(&should_stop_mutex, NULL); should_stop_status = false; - pthread_create(&worker_thread, NULL, &Thread::do_work_thunk, this); + pthread_create(&worker_thread, nullptr, &Thread::do_work_thunk, this); } void Thread::stop() { { - MutexLock lock(&should_stop_mutex); + lock_guard lock(should_stop_mutex); should_stop_status = true; } wakeup(); - if (pthread_join(worker_thread, NULL) == -1) { + if (pthread_join(worker_thread, nullptr) == -1) { log_perror("pthread_join"); exit(1); } @@ -43,7 +42,7 @@ void *Thread::do_work_thunk(void *arg) sigset_t set; sigemptyset(&set); sigaddset(&set, SIGHUP); - int err = pthread_sigmask(SIG_BLOCK, &set, NULL); + int err = pthread_sigmask(SIG_BLOCK, &set, nullptr); if (err != 0) { errno = err; log_perror("pthread_sigmask"); @@ -62,7 +61,7 @@ void *Thread::do_work_thunk(void *arg) // Call the right thunk. thread->do_work(); - return NULL; + return nullptr; } bool Thread::wait_for_activity(int fd, short events, const struct timespec *timeout_ts) @@ -93,6 +92,6 @@ void Thread::wakeup() bool Thread::should_stop() { - MutexLock lock(&should_stop_mutex); + lock_guard lock(should_stop_mutex); return should_stop_status; }