24#ifndef MYSQL_SCHEDULER_TASK_REGISTRY_MULTI_H
25#define MYSQL_SCHEDULER_TASK_REGISTRY_MULTI_H
31#include <unordered_map>
73template <
typename Task_
id_type,
typename Task_
object_type>
84 for (std::size_t idx = 0; idx < capacity; ++idx) {
85 m_buckets.emplace_back(std::make_unique<Bucket>());
97 [[nodiscard]]
bool apply(Task_id_type
id,
T &&func) {
99 std::scoped_lock scope_guard(
bucket->m_lock);
100 auto it =
bucket->m_entries.find(
id);
101 if (it !=
bucket->m_entries.end()) {
102 func(it->second.m_obj);
116 std::scoped_lock scope_guard(
bucket->m_lock);
117 auto map_entry =
bucket->m_entries.emplace(
118 std::piecewise_construct, std::forward_as_tuple(
id),
119 std::forward_as_tuple(std::move(obj)));
120 if (map_entry.second) {
121 bucket->m_num_entries.fetch_add(1, std::memory_order_relaxed);
123 return map_entry.second;
131 std::scoped_lock scope_guard(
bucket->m_lock);
132 size_t erased =
bucket->m_entries.erase(
id);
134 bucket->m_num_entries.fetch_sub(1, std::memory_order_relaxed);
144 size_t hash_value =
id.get() %
m_buckets.size();
145 return m_buckets[hash_value]->m_num_entries.load(
146 std::memory_order_relaxed) > 0;
169 concurrency::detail::hardware_destructive_interference_size)
Bucket {
182 auto hash_value =
id.get() %
m_buckets.size();
#endif
Implementation of a spin-lock mutex.
Definition: spin_lock_mutex.h:59
This template class provides a concurrent registry for tasks that handles hash conflicts by allowing ...
Definition: task_registry_multi.h:74
std::unique_ptr< Bucket > Bucket_ptr
Definition: task_registry_multi.h:175
std::vector< Bucket_ptr > m_buckets
Buckets, synchronized independently.
Definition: task_registry_multi.h:187
bool bucket_active(Task_id_type id) const
Checks if the bucket for the given task ID is active (contains any tasks)
Definition: task_registry_multi.h:143
~Task_registry_multi()=default
Destruct registry, deinitialize if applicable.
Bucket_ptr & get_bucket(Task_id_type id)
Obtains the bucket handle handling a given id, for internal use.
Definition: task_registry_multi.h:180
bool activate(Task_id_type id, Task_object &&obj)
Registers and activates a task.
Definition: task_registry_multi.h:114
Task_object_type Task_object
Definition: task_registry_multi.h:76
Task_registry_multi(std::size_t capacity=default_capacity)
Constructs buckets using defined capacity.
Definition: task_registry_multi.h:82
static constexpr std::size_t default_capacity
Definition: task_registry_multi.h:79
bool apply(Task_id_type id, T &&func)
Calls 'func' on a given task object if active.
Definition: task_registry_multi.h:97
bool deactivate(Task_id_type id)
Deactivates a task.
Definition: task_registry_multi.h:129
#define T
Definition: jit_executor_value.cc:373
Definition: base_dependency_tracker.h:41
Define std::hash<Gtid>.
Definition: gtid.h:355
Definition: completion_hash.h:40
Represents a bucket, capable of handling many subentries.
Definition: task_registry_multi.h:168
std::unordered_map< Task_id_type, Sub_entry > m_entries
Definition: task_registry_multi.h:170
Bucket()
Definition: task_registry_multi.h:169
std::atomic< size_t > m_num_entries
Definition: task_registry_multi.h:172
Mutex m_lock
Definition: task_registry_multi.h:171
Each bucket is capable of handling many subentries.
Definition: task_registry_multi.h:155
Sub_entry(Task_object &&obj)
Construct from object.
Definition: task_registry_multi.h:162
Task_object m_obj
Internal object, type defined by the caller.
Definition: task_registry_multi.h:157