BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
thread_specific.hpp
Go to the documentation of this file.
1 #pragma once
2 #include "thread.hpp"
3 
4 namespace fc
5 {
6  namespace detail
7  {
10  }
11 
12  template <typename T>
14  {
15  private:
16  unsigned slot;
17  public:
20  {}
21 
22  T* get() const
23  {
24  return static_cast<T*>(detail::get_thread_specific_data(slot));
25  }
26  T* operator->() const
27  {
28  return get();
29  }
30  T& operator*() const
31  {
32  return *get();
33  }
34  operator bool() const
35  {
36  return get() != static_cast<T*>(0);
37  }
38  static void cleanup_function(void* obj)
39  {
40  delete static_cast<T*>(obj);
41  }
42  void reset(T* new_value = 0)
43  {
45  }
46  };
47 
48  template <typename T>
50  {
51  private:
52  unsigned slot;
53  public:
55  slot(detail::get_next_unused_task_storage_slot())
56  {}
57 
58  T* get() const
59  {
60  return static_cast<T*>(detail::get_task_specific_data(slot));
61  }
62  T* operator->() const
63  {
64  return get();
65  }
66  T& operator*() const
67  {
68  return *get();
69  }
70  operator bool() const
71  {
72  return get() != static_cast<T*>(0);
73  }
74  static void cleanup_function(void* obj)
75  {
76  delete static_cast<T*>(obj);
77  }
78  void reset(T* new_value = 0)
79  {
81  }
82  };
83 
84 }
fc::task_specific_ptr::task_specific_ptr
task_specific_ptr()
Definition: thread_specific.hpp:54
fc::task_specific_ptr::get
T * get() const
Definition: thread_specific.hpp:58
fc::detail::get_task_specific_data
void * get_task_specific_data(unsigned slot)
Definition: thread_specific.cpp:41
fc::task_specific_ptr::cleanup_function
static void cleanup_function(void *obj)
Definition: thread_specific.hpp:74
fc::detail::set_task_specific_data
void set_task_specific_data(unsigned slot, void *new_value, void(*cleanup)(void *))
Definition: thread_specific.cpp:51
fc::task_specific_ptr::operator->
T * operator->() const
Definition: thread_specific.hpp:62
fc::detail::get_next_unused_task_storage_slot
unsigned get_next_unused_task_storage_slot()
Definition: thread_specific.cpp:37
fc::task_specific_ptr::operator*
T & operator*() const
Definition: thread_specific.hpp:66
fc
Definition: api.hpp:15
fc::thread_specific_ptr::get
T * get() const
Definition: thread_specific.hpp:22
fc::thread_specific_ptr::cleanup_function
static void cleanup_function(void *obj)
Definition: thread_specific.hpp:38
fc::task_specific_ptr
Definition: thread_specific.hpp:49
fc::thread_specific_ptr::thread_specific_ptr
thread_specific_ptr()
Definition: thread_specific.hpp:18
fc::detail::get_thread_specific_data
void * get_thread_specific_data(unsigned slot)
Definition: thread_specific.cpp:28
fc::thread_specific_ptr
Definition: thread_specific.hpp:13
thread.hpp
fc::thread_specific_ptr::operator*
T & operator*() const
Definition: thread_specific.hpp:30
fc::detail::get_next_unused_thread_storage_slot
unsigned get_next_unused_thread_storage_slot()
Definition: thread_specific.cpp:11
fc::thread_specific_ptr::reset
void reset(T *new_value=0)
Definition: thread_specific.hpp:42
fc::task_specific_ptr::reset
void reset(T *new_value=0)
Definition: thread_specific.hpp:78
fc::detail::set_thread_specific_data
void set_thread_specific_data(unsigned slot, void *new_value, void(*cleanup)(void *))
Definition: thread_specific.cpp:32
fc::thread_specific_ptr::operator->
T * operator->() const
Definition: thread_specific.hpp:26