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
9typedef struct _GMainContext GMainContext;
10
11namespace zyppng
12{
13 class EventDispatcher;
14
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
Provides API related macros.
struct _GMainContext GMainContext
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
ThreadData & threadData()
std::shared_ptr< EventDispatcher > dispatcher()
Definition threaddata.cc:59
void setName(T &&name)
std::weak_ptr< EventDispatcher > _dispatcher
static ZYPP_API 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:44
std::thread::native_handle_type _nativeHandle
std::thread::id _threadId
std::shared_ptr< EventDispatcher > ensureDispatcher(GMainContext *ctx=0)
Definition threaddata.cc:32