4 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(thrd);
7 #include "msg_thread.h"
9 msg_thread::msg_thread()
12 , thread_name("msg_thread")
16 msg_thread::msg_thread(const char* name)
23 msg_thread::~msg_thread()
26 throw std::logic_error("trying to destroy running thread");
29 void msg_thread::start()
33 throw std::logic_error("thread was already started");
34 XBT_DEBUG("launch \"%s\"", thread_name.c_str());
35 thread = MSG_process_create(thread_name.c_str(),
36 msg_thread::start_wrapper,
37 this, MSG_host_self());
42 void msg_thread::wait()
46 throw std::logic_error("trying to wait a thread that was not started");
48 XBT_DEBUG("waiting for \"%s\" to terminate",
55 int msg_thread::start_wrapper(int, char* [])
58 self = static_cast<msg_thread*>(MSG_process_get_data(MSG_process_self()));
59 XBT_DEBUG("\"%s\" started", self->thread_name.c_str());
62 XBT_DEBUG("terminate \"%s\"", self->thread_name.c_str());
63 self->mutex.acquire();
66 self->mutex.release();