namespace Msp {
-Thread::Thread():
+Thread::Thread(const string &name):
priv_(new Private),
+ name_(name),
state_(PENDING)
{ }
ThreadReturn THREAD_CALL Thread::Private::main_wrapper(void *arg)
{
Thread *thread = reinterpret_cast<Thread *>(arg);
+ thread->platform_setname();
thread->main();
thread->state_ = FINISHED;
return 0;
#ifndef MSP_CORE_THREAD_H_
#define MSP_CORE_THREAD_H_
+#include <string>
+
namespace Msp {
/**
};
Private *priv_;
+ std::string name_;
State state_;
protected:
- Thread();
+ Thread(const std::string & = std::string());
private:
Thread(const Thread &);
Thread &operator=(const Thread &);
public:
virtual ~Thread();
+ const std::string &get_name() const { return name_; }
+
/** Indicates whether the thread has finished running. */
bool is_finished() { return state_>=FINISHED; }
void platform_join();
void platform_kill();
void platform_launch();
+ void platform_setname();
protected:
virtual void main() = 0;
pthread_create(&priv_->handle, 0, &Private::main_wrapper, this);
}
+void Thread::platform_setname()
+{
+ if(!name_.empty())
+ pthread_setname_np(priv_->handle, name_.c_str());
+}
+
} // namespace Msp
priv_->handle = CreateThread(0, 0, &Private::main_wrapper, this, 0, &dummy);
}
+void Thread::platform_setname()
+{
+ // TODO: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
+}
+
} // namespace Msp