-#include <stdexcept>
+#include "except.h"
#include "thread.h"
#include "thread_private.h"
namespace Msp {
Thread::Thread(const string &name):
- priv_(new Private),
- name_(name),
- state_(PENDING)
+ _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<Thread *>(arg);
thread->platform_setname();
thread->main();
- thread->state_ = FINISHED;
+ thread->_state = FINISHED;
return 0;
}