libzypp  17.35.15
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 #include <zypp-core/Globals.h>
8 
9 namespace zyppng
10 {
11  class EventDispatcher;
12 
13  struct ThreadData
14  {
15  static ZYPP_API ThreadData &current();
16 
17  template<typename T>
18  void setName( T &&name ) {
19  _threadName = std::forward<T>( name );
21  }
22 
23  const std::string &name() const;
24 
25  std::shared_ptr<EventDispatcher> dispatcher();
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
#define ZYPP_API
Definition: Globals.h:69
std::string _threadName
lazy initialized to _threadId if unset
Definition: threaddata_p.h:36
const std::string & name() const
Definition: threaddata.cc:22
Provides API related macros.
std::shared_ptr< EventDispatcher > dispatcher()
Definition: threaddata.cc:57
std::thread::native_handle_type _nativeHandle
Definition: threaddata_p.h:37
std::weak_ptr< EventDispatcher > _dispatcher
Definition: threaddata_p.h:38
ThreadData & threadData()
static ZYPP_API ThreadData & current()
Definition: threaddata.cc:16
std::shared_ptr< EventDispatcher > ensureDispatcher()
Definition: threaddata.cc:32
void setName(T &&name)
Definition: threaddata_p.h:18
void setDispatcher(const std::shared_ptr< EventDispatcher > &disp)
Definition: threaddata.cc:42