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

libzypp 17.38.5

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
9namespace 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 );
20 syncNativeName();
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
41 ThreadData& threadData();
42}
43
44
45#endif
Globals.h
Provides API related macros.
zyppng::EventDispatcher
Definition eventdispatcher.h:42
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::threadData
ThreadData & threadData()
zyppng::ThreadData
Definition threaddata_p.h:14
zyppng::ThreadData::dispatcher
std::shared_ptr< EventDispatcher > dispatcher()
Definition threaddata.cc:57
zyppng::ThreadData::ThreadData
ThreadData()
Definition threaddata.cc:10
zyppng::ThreadData::syncNativeName
void syncNativeName()
Definition threaddata.cc:51
zyppng::ThreadData::setName
void setName(T &&name)
Definition threaddata_p.h:18
zyppng::ThreadData::_dispatcher
std::weak_ptr< EventDispatcher > _dispatcher
Definition threaddata_p.h:38
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:36
zyppng::ThreadData::setDispatcher
void setDispatcher(const std::shared_ptr< EventDispatcher > &disp)
Definition threaddata.cc:42
zyppng::ThreadData::_nativeHandle
std::thread::native_handle_type _nativeHandle
Definition threaddata_p.h:37
zyppng::ThreadData::ensureDispatcher
std::shared_ptr< EventDispatcher > ensureDispatcher()
Definition threaddata.cc:32
zyppng::ThreadData::_threadId
std::thread::id _threadId
Definition threaddata_p.h:35