X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=thread.cpp;fp=thread.cpp;h=03bfd9d8931bf9e0970ecc0878bc079b3921173d;hp=0000000000000000000000000000000000000000;hb=e1722a5c0341fd541ce57f1eed4dc76cbd3efe07;hpb=99738bd173040bf4e2d2d42ffc8c7ab8c105cf75 diff --git a/thread.cpp b/thread.cpp new file mode 100644 index 0000000..03bfd9d --- /dev/null +++ b/thread.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "thread.h" + +void Thread::run() +{ + should_stop = false; + pthread_create(&worker_thread, NULL, &Thread::do_work_thunk, this); +} + +void Thread::stop() +{ + should_stop = true; + pthread_kill(worker_thread, SIGHUP); + if (pthread_join(worker_thread, NULL) == -1) { + perror("pthread_join"); + exit(1); + } +} + +void *Thread::do_work_thunk(void *arg) +{ + Thread *thread = reinterpret_cast(arg); + thread->do_work(); + return NULL; +} +