libzypp 17.34.1
threaddata_p.h
Go to the documentation of this file.
1#ifndef ZYPP_BASE_THREADDATA_P_DEFINED
2#define ZYPP_BASE_THREADDATA_P_DEFINED
3
4#include <memory>
5#include <thread>
6#include <string>
7
8namespace zyppng
9{
10 class EventDispatcher;
11
13 {
14 static ThreadData &current();
15
16 template<typename T>
17 void setName( T &&name ) {
18 _threadName = std::forward<T>( name );
20 }
21
22 const std::string &name() const;
23
24 std::shared_ptr<EventDispatcher> dispatcher()
25 { return _dispatcher.lock(); }
26 std::shared_ptr<EventDispatcher> ensureDispatcher();
27 void setDispatcher( const std::shared_ptr<EventDispatcher> &disp );
28
29
30 private:
31 void syncNativeName();
32 ThreadData();
33
34 private:
35 std::thread::id _threadId;
36 mutable std::string _threadName;
37 std::thread::native_handle_type _nativeHandle;
38 std::weak_ptr<EventDispatcher> _dispatcher;
39 };
40
42}
43
44
45#endif
ThreadData & threadData()
std::shared_ptr< EventDispatcher > dispatcher()
void setName(T &&name)
std::weak_ptr< EventDispatcher > _dispatcher
static ThreadData & current()
Definition threaddata.cc:16
const std::string & name() const
Definition threaddata.cc:22
std::string _threadName
lazy initialized to _threadId if unset
void setDispatcher(const std::shared_ptr< EventDispatcher > &disp)
Definition threaddata.cc:41
std::thread::native_handle_type _nativeHandle
std::shared_ptr< EventDispatcher > ensureDispatcher()
Definition threaddata.cc:32
std::thread::id _threadId