libzypp  17.38.7
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 typedef struct _GMainContext GMainContext;
10 
11 namespace zyppng
12 {
13  class EventDispatcher;
14 
15  struct ThreadData
16  {
17  static ZYPP_API ThreadData &current();
18 
19  template<typename T>
20  void setName( T &&name ) {
21  _threadName = std::forward<T>( name );
23  }
24 
25  const std::string &name() const;
26 
27  std::shared_ptr<EventDispatcher> dispatcher();
28  std::shared_ptr<EventDispatcher> ensureDispatcher( GMainContext *ctx = 0 );
29  void setDispatcher( const std::shared_ptr<EventDispatcher> &disp );
30 
31 
32  private:
33  void syncNativeName();
34  ThreadData();
35 
36  private:
37  std::thread::id _threadId;
38  mutable std::string _threadName;
39  std::thread::native_handle_type _nativeHandle;
40  std::weak_ptr<EventDispatcher> _dispatcher;
41  };
42 
44 }
45 
46 
47 #endif
std::thread::id _threadId
Definition: threaddata_p.h:37
std::string _threadName
lazy initialized to _threadId if unset
Definition: threaddata_p.h:38
const std::string & name() const
Definition: threaddata.cc:22
std::shared_ptr< EventDispatcher > dispatcher()
Definition: threaddata.cc:59
std::thread::native_handle_type _nativeHandle
Definition: threaddata_p.h:39
std::shared_ptr< EventDispatcher > ensureDispatcher(GMainContext *ctx=0)
Definition: threaddata.cc:32
Provides API related macros.
#define ZYPP_API
Definition: Globals.h:69
std::weak_ptr< EventDispatcher > _dispatcher
Definition: threaddata_p.h:40
ThreadData & threadData()
static ZYPP_API ThreadData & current()
Definition: threaddata.cc:16
void setName(T &&name)
Definition: threaddata_p.h:20
void setDispatcher(const std::shared_ptr< EventDispatcher > &disp)
Definition: threaddata.cc:44
struct _GMainContext GMainContext