8 #include "../invalid_operation_exception.h" 10 #include "../time_span.h" 37 template<
typename value_t>
39 struct data :
public object {
41 bool track_all_values =
false;
43 std::map<intptr, value_t>
values;
46 struct lock_guard_mutex {
47 lock_guard_mutex(
mutex&
mutex) : mutex_(mutex) {mutex_.lock();}
48 ~lock_guard_mutex() {mutex_.unlock();}
73 data_->value_factory = value_factory;
74 data_->track_all_values = track_all_values;
79 template<
typename func_t>
81 template<
typename func_t>
94 lock_guard_mutex
lock {data_->mutex};
102 lock_guard_mutex
lock {data_->mutex};
111 lock_guard_mutex
lock {data_->mutex};
121 lock_guard_mutex
lock {data_->mutex};
122 auto values = std::vector<value_t> {};
123 for (
const auto& entry : data_->values)
124 values.push_back(entry.second);
138 mutable std::shared_ptr<data> data_ = std::make_shared<data>();
std::vector< value_t > values() const
Gets a list containing the values stored by all threads that have accessed this instance.
Definition: thread_local_object.h:119
static thread & current_thread()
Gets the currently running thread.
Provides a mechanism that synchronizes access to objects with xtd::threading::monitor.
Definition: lock_guard.h:30
thread_local_object(const func< value_t > &value_factory)
Initializes the xtd::threading::thread_local_object instance with the specified value_factory functio...
Definition: thread_local_object.h:67
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
A synchronization primitive that can also be used for interprocess synchronization.
Definition: mutex.h:48
void value(value_t value) noexcept
Sets the value of this instance for the current thread.
Definition: thread_local_object.h:110
#define csf_
Provides information about the current stack frame.
Definition: current_stack_frame.h:30
ustring to_string() const noexcept override
Returns a sxd::ustring that represents the current object.
Definition: thread_local_object.h:132
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Contains xtd::threading::thread class.
intptr thread_id() const noexcept
Gets the native operating system thread id.
Provides thread-local storage of data.
Definition: thread_local_object.h:38
value_t value() const noexcept
Gets the value of this instance for the current thread.
Definition: thread_local_object.h:101
bool is_value_created() const noexcept
Gets whether xtd::threading::thread_local_object::value is initialized on the current thread...
Definition: thread_local_object.h:93
Contains xtd::threading::mutex exception.
The operating system is other.
The exception that is thrown when a method call is invalid for the object's current state...
Definition: invalid_operation_exception.h:18
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
thread_local_object(bool track_all_values)
Initializes the xtd::threading::thread_local_object instance and specifies whether all values are acc...
Definition: thread_local_object.h:64
thread_local_object()=default
Initializes the xtd::threading::thread_local_object instance.
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition: delegate.h:362
thread_local_object(const func< value_t > &value_factory, bool track_all_values)
Initializes the xtd::threading::thread_local_object instance with the specified value_factory functio...
Definition: thread_local_object.h:72