libzypp: zypp-core/ng/base/private/threaddata_p.h Source File

libzypp 17.38.11

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
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 );
22 syncNativeName();
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
43 ThreadData& threadData();
44}
45
46
47#endif
Globals.h
Provides API related macros.
zyppng::EventDispatcher
Definition eventdispatcher.h:43
GMainContext
struct _GMainContext GMainContext
Definition eventdispatcher.h:24
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::threadData
ThreadData & threadData()
zyppng::ThreadData
Definition threaddata_p.h:16
zyppng::ThreadData::dispatcher
std::shared_ptr< EventDispatcher > dispatcher()
Definition threaddata.cc:59
zyppng::ThreadData::ThreadData
ThreadData()
Definition threaddata.cc:10
zyppng::ThreadData::syncNativeName
void syncNativeName()
Definition threaddata.cc:53
zyppng::ThreadData::setName
void setName(T &&name)
Definition threaddata_p.h:20
zyppng::ThreadData::_dispatcher
std::weak_ptr< EventDispatcher > _dispatcher
Definition threaddata_p.h:40
zyppng::ThreadData::current
static ZYPP_API ThreadData & current()
Definition threaddata.cc:16
zyppng::ThreadData::name
const std::string & name() const
Definition threaddata.cc:22
zyppng::ThreadData::_threadName
std::string _threadName
lazy initialized to _threadId if unset
Definition threaddata_p.h:38
zyppng::ThreadData::setDispatcher
void setDispatcher(const std::shared_ptr< EventDispatcher > &disp)
Definition threaddata.cc:44
zyppng::ThreadData::_nativeHandle
std::thread::native_handle_type _nativeHandle
Definition threaddata_p.h:39
zyppng::ThreadData::_threadId
std::thread::id _threadId
Definition threaddata_p.h:37
zyppng::ThreadData::ensureDispatcher
std::shared_ptr< EventDispatcher > ensureDispatcher(GMainContext *ctx=0)
Definition threaddata.cc:32