24#ifndef MYSQL_CONCURRENCY_LOCKING_QUEUE
25#define MYSQL_CONCURRENCY_LOCKING_QUEUE
27#include <condition_variable>
99 auto stop_waiting = [
this, &pred]() ->
bool {
100 return pred() || !
m_queue.empty();
104 assert(stop_waiting());
105 return std::make_pair(
ElemType{},
false);
109 return std::make_pair(elem,
true);
Polymorphism-free memory resource class with custom allocator and deallocator functions.
Definition: memory_resource.h:88
MySQL wrapper for a condition variable, using mysql_cond_t as implementation of a condition variable ...
Definition: condition_variable_wrapper.h:37
void notify_one()
Notify one waiting thread.
Definition: condition_variable_wrapper.cpp:38
void notify_all()
Notify all waiting threads.
Definition: condition_variable_wrapper.cpp:40
void wait(std::unique_lock< Mutex_wrapper > &lock, Predicate pred)
Wait until notified or predicate is false.
Definition: condition_variable_wrapper_impl.hpp:29
Synchronized unbounded FIFO queue for thread-safe producer-consumer operations, using a single mutex ...
Definition: locking_queue.h:47
bool enqueue(ElemType &&elem)
Enqueues an element into the queue (called by producers).
Definition: locking_queue.h:71
Locking_queue & operator=(const Locking_queue< ElemType > &src)=delete
Locking_queue(Memory_resource memory_resource={})
Constructs the queue.
Definition: locking_queue.h:54
concurrency::Mutex m_mutex_access_queue
Mutex protecting all queue operations.
Definition: locking_queue.h:121
void notify_all()
Wakes all waiting consumers (e.g., during shutdown to check pred and exit).
Definition: locking_queue.h:115
Memory_resource m_memory_resource
Reserved for future custom allocation; currently unused.
Definition: locking_queue.h:125
Locking_queue(Locking_queue< ElemType > &&)=delete
ET ElemType
Definition: locking_queue.h:49
std::queue< ElemType > m_queue
Underlying unbounded FIFO queue.
Definition: locking_queue.h:119
Locking_queue(const Locking_queue< ElemType > &)=delete
std::pair< ElemType, bool > dequeue(P &&pred)
Consumes (dequeues) an element from the front of the queue.
Definition: locking_queue.h:97
bool empty() const
Checks if the queue is empty.
Definition: locking_queue.h:83
Locking_queue & operator=(Locking_queue< ElemType > &&src)=delete
concurrency::Condition_variable m_cv_empty_queue
Condition variable for waiting on non-empty queue.
Definition: locking_queue.h:123
MySQL wrapper for a mutex, template which may be specialized with a specific implementation of a mute...
Definition: mutex_wrapper.h:38
#define MYSQL_CONCURRENCY_DEFINE_CV_PSI_KEY(key)
Definition: condition_variable_srv.h:34
#define P
Definition: dtoa.cc:620
Class that wraps resources in a polymorphic manner.
#define MYSQL_CONCURRENCY_DEFINE_MT_PSI_KEY(key)
Definition: mutex_srv.h:35
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
Definition: cache_line_size.h:31
static std::mutex lock
Definition: net_ns.cc:56