X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fthread.cpp;h=e860d6758f9e048f070b67855e7d7810456e7c48;hp=d2451a0d819187e67f0ea41340720e62ac7f3a4a;hb=HEAD;hpb=609c9a508cfdc7b42c46c4f21d17639204165a00 diff --git a/source/core/thread.cpp b/source/core/thread.cpp index d2451a0..ad78d94 100644 --- a/source/core/thread.cpp +++ b/source/core/thread.cpp @@ -1,4 +1,4 @@ -#include +#include "except.h" #include "thread.h" #include "thread_private.h" @@ -6,50 +6,51 @@ using namespace std; namespace Msp { -Thread::Thread(): - priv_(new Private), - state_(PENDING) +Thread::Thread(const string &name): + _priv(new Private), + _name(name) { } Thread::~Thread() { kill(); join(); - delete priv_; + delete _priv; } void Thread::join() { - if(state_>=JOINED) + if(_state>=JOINED) return; platform_join(); - state_ = JOINED; + _state = JOINED; } void Thread::kill() { - if(state_!=RUNNING) + if(_state!=RUNNING) return; platform_kill(); - state_ = KILLED; + _state = KILLED; } void Thread::launch() { - if(state_>=RUNNING) - throw logic_error("already launched"); + if(_state>=RUNNING) + throw already_called("Thread::launch"); platform_launch(); - state_ = RUNNING; + _state = RUNNING; } ThreadReturn THREAD_CALL Thread::Private::main_wrapper(void *arg) { Thread *thread = reinterpret_cast(arg); + thread->platform_setname(); thread->main(); - thread->state_ = FINISHED; + thread->_state = FINISHED; return 0; }