This commit is contained in:
Nekotekina 2015-08-21 14:07:31 +03:00
parent 5e14310071
commit e551e2bc5d
12 changed files with 107 additions and 37 deletions

View file

@ -7,15 +7,20 @@ class thread_ctrl_t final
{
friend class named_thread_t;
template<typename T> friend void current_thread_register_atexit(T);
// thread handler
std::thread m_thread;
// name getter
const std::function<std::string()> name;
const std::function<std::string()> m_name;
// functions executed at thread exit (temporarily)
std::vector<std::function<void()>> m_atexit;
public:
thread_ctrl_t(std::function<std::string()> name)
: name(std::move(name))
: m_name(std::move(name))
{
}
@ -23,6 +28,14 @@ public:
std::string get_name() const;
};
// register function at thread exit (temporarily)
template<typename T> void current_thread_register_atexit(T func)
{
extern thread_local thread_ctrl_t* g_tls_this_thread;
g_tls_this_thread->m_atexit.emplace_back(func);
}
class named_thread_t
{
// pointer to managed resource (shared with actual thread)