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 
8 namespace zyppng
9 {
10  class EventDispatcher;
11 
12  struct ThreadData
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
std::thread::id _threadId
Definition: threaddata_p.h:35
std::string _threadName
lazy initialized to _threadId if unset
Definition: threaddata_p.h:36
const std::string & name() const
Definition: threaddata.cc:22
std::thread::native_handle_type _nativeHandle
Definition: threaddata_p.h:37
std::weak_ptr< EventDispatcher > _dispatcher
Definition: threaddata_p.h:38
ThreadData & threadData()
static ThreadData & current()
Definition: threaddata.cc:16
std::shared_ptr< EventDispatcher > ensureDispatcher()
Definition: threaddata.cc:32
std::shared_ptr< EventDispatcher > dispatcher()
Definition: threaddata_p.h:24
void setName(T &&name)
Definition: threaddata_p.h:17
void setDispatcher(const std::shared_ptr< EventDispatcher > &disp)
Definition: threaddata.cc:41