libzypp 17.37.17
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
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
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
ThreadData & threadData()
std::shared_ptr< EventDispatcher > dispatcher()
Definition threaddata.cc:57
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:42
std::thread::native_handle_type _nativeHandle
std::shared_ptr< EventDispatcher > ensureDispatcher()
Definition threaddata.cc:32
std::thread::id _threadId
Provides API related macros.