MySQL 8.0.32
Source Code Documentation
os_event Struct Reference

InnoDB condition variable. More...

Public Member Functions

 os_event () 1
 Constructor. More...
 
 ~os_event () 1
 Destructor. More...
 
void destroy () 1
 Destroys a condition variable. More...
 
void set () 1
 Set the event. More...
 
bool try_set () 1
 
int64_t reset () 1
 
void wait_low (int64_t reset_sig_count) 1
 Waits for an event object until it is in the signaled state. More...
 
ulint wait_time_low (std::chrono::microseconds timeout, int64_t reset_sig_count) 1
 Waits for an event object until it is in the signaled state or a timeout is exceeded. More...
 
bool is_set () const 1
 

Protected Member Functions

 os_event (const os_event &)
 
os_eventoperator= (const os_event &)
 

Private Member Functions

void init () 1
 Initialize a condition variable. More...
 
void wait () 1
 Wait on condition variable. More...
 
void broadcast () 1
 Wakes all threads waiting for condition variable. More...
 
void signal () 1
 Wakes one thread waiting for condition variable. More...
 
bool timed_wait (const timespec *abstime)
 Do a timed wait on condition variable. More...
 
struct timespec get_wait_timelimit (std::chrono::microseconds timeout)
 Returns absolute time until which we should wait if we wanted to wait for timeout since now. More...
 

Private Attributes

bool m_set
 this is true when the event is in the signaled state, i.e., a thread does not stop if it tries to wait for this event More...
 
int64_t signal_count
 this is incremented each time the event becomes signaled More...
 
EventMutex mutex
 this mutex protects the next fields More...
 
os_cond_t cond_var
 condition variable is used in waiting for the event More...
 

Static Private Attributes

static pthread_condattr_t cond_attr
 Attributes object passed to pthread_cond_* functions. More...
 
static bool cond_attr_has_monotonic_clock {false}
 True iff usage of the monotonic clock has been successfully enabled for the cond_attr object. More...
 
static bool global_initialized {false}
 
static std::atomic_size_t n_objects_alive {0}
 

Friends

void os_event_global_init ()
 Initializes support for os_event objects. More...
 
void os_event_global_destroy ()
 Deinitializes support for os_event objects. More...
 

Detailed Description

InnoDB condition variable.

Constructor & Destructor Documentation

◆ os_event() [1/2]

os_event::os_event ( )

Constructor.

◆ ~os_event()

os_event::~os_event ( )

Destructor.

◆ os_event() [2/2]

os_event::os_event ( const os_event )
protected

Member Function Documentation

◆ broadcast()

void os_event::broadcast ( )
inlineprivate

Wakes all threads waiting for condition variable.

◆ destroy()

void os_event::destroy ( )
inline

Destroys a condition variable.

◆ get_wait_timelimit()

struct timespec os_event::get_wait_timelimit ( std::chrono::microseconds  timeout)
private

Returns absolute time until which we should wait if we wanted to wait for timeout since now.

This method could be removed if we switched to the usage of std::condition_variable.

◆ init()

void os_event::init ( void  )
inlineprivate

Initialize a condition variable.

◆ is_set()

bool os_event::is_set ( ) const
inline
Returns
true if the event is in the signalled state.

◆ operator=()

os_event & os_event::operator= ( const os_event )
protected

◆ reset()

int64_t os_event::reset ( void  )
inline

◆ set()

void os_event::set ( )
inline

Set the event.

◆ signal()

void os_event::signal ( )
inlineprivate

Wakes one thread waiting for condition variable.

◆ timed_wait()

bool os_event::timed_wait ( const timespec *  abstime)
private

Do a timed wait on condition variable.

Returns
true if timed out, false otherwise
Parameters
abstimeTimeout.

◆ try_set()

bool os_event::try_set ( )
inline

◆ wait()

void os_event::wait ( )
inlineprivate

Wait on condition variable.

◆ wait_low()

void os_event::wait_low ( int64_t  reset_sig_count)

Waits for an event object until it is in the signaled state.

Typically, if the event has been signalled after the os_event_reset() we'll return immediately because event->m_set == true. There are, however, situations (e.g.: sync_array code) where we may lose this information. For example:

thread A calls os_event_reset() thread B calls os_event_set() [event->m_set == true] thread C calls os_event_reset() [event->m_set == false] thread A calls os_event_wait() [infinite wait!] thread C calls os_event_wait() [infinite wait!]

Where such a scenario is possible, to avoid infinite wait, the value returned by reset() should be passed in as reset_sig_count.

◆ wait_time_low()

ulint os_event::wait_time_low ( std::chrono::microseconds  timeout,
int64_t  reset_sig_count 
)

Waits for an event object until it is in the signaled state or a timeout is exceeded.

Parameters
timeoutTimeout in microseconds, or std::chrono::microseconds::max()
reset_sig_countZero or the value returned by previous call of os_event_reset().
Returns
0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded

Friends And Related Function Documentation

◆ os_event_global_destroy

void os_event_global_destroy ( void  )
friend

Deinitializes support for os_event objects.

Must be called once, and after all os_event objects are destroyed. After it is called, no new os_event is allowed to be created.

◆ os_event_global_init

void os_event_global_init ( void  )
friend

Initializes support for os_event objects.

Must be called once, and before any os_event object is created.

Member Data Documentation

◆ cond_attr

pthread_condattr_t os_event::cond_attr
staticprivate

Attributes object passed to pthread_cond_* functions.

Defines usage of the monotonic clock if it's available. Initialized once, in the os_event::global_init(), and destroyed in the os_event::global_destroy().

◆ cond_attr_has_monotonic_clock

bool os_event::cond_attr_has_monotonic_clock {false}
staticprivate

True iff usage of the monotonic clock has been successfully enabled for the cond_attr object.

◆ cond_var

os_cond_t os_event::cond_var
private

condition variable is used in waiting for the event

◆ global_initialized

bool os_event::global_initialized {false}
staticprivate

◆ m_set

bool os_event::m_set
private

this is true when the event is in the signaled state, i.e., a thread does not stop if it tries to wait for this event

◆ mutex

EventMutex os_event::mutex
private

this mutex protects the next fields

◆ n_objects_alive

std::atomic_size_t os_event::n_objects_alive {0}
staticprivate

◆ signal_count

int64_t os_event::signal_count
private

this is incremented each time the event becomes signaled


The documentation for this struct was generated from the following file: