MySQL 26.7.0
Source Code Documentation
os0event.h
Go to the documentation of this file.
1/*****************************************************************************
2Copyright (c) 1995, 2026, Oracle and/or its affiliates.
3
4This program is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License, version 2.0, as published by the
6Free Software Foundation.
7
8This program is designed to work with certain software (including
9but not limited to OpenSSL) that is licensed under separate terms,
10as designated in a particular file or component or in included license
11documentation. The authors of MySQL hereby grant you an additional
12permission to link the program and your derivative works with the
13separately licensed software that they have either included with
14the program or referenced in the documentation.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/os0event.h
28 The interface to the operating system condition variables
29
30 Created 2012-09-23 Sunny Bains (split from os0sync.h)
31 *******************************************************/
32
33#ifndef os0event_h
34#define os0event_h
35
36#include <sys/types.h>
37
38#include "univ.i"
39
40// Forward declaration.
41struct os_event;
42typedef struct os_event *os_event_t;
43
44/** Return value of os_event_wait_time() when the time is exceeded */
45constexpr uint32_t OS_SYNC_TIME_EXCEEDED = 1;
46
47#ifndef UNIV_HOTBACKUP
48/**
49Creates an event semaphore, i.e., a semaphore which may just have two states:
50signaled and nonsignaled. The created event is manual reset: it must be reset
51explicitly by calling os_event_reset().
52@return the event handle */
54
55/**
56Sets an event semaphore to the signaled state: lets waiting threads
57proceed. */
58void os_event_set(os_event_t event); /*!< in/out: event to set */
59
60/**
61Check if the event is set.
62@return true if set */
63bool os_event_is_set(const os_event_t event); /*!< in: event to set */
64
65/**
66Resets an event semaphore to the non-signaled state. Waiting threads will
67stop to wait for the event.
68The return value should be passed to os_even_wait_low() if it is desired
69that this thread should not wait in case of an intervening call to
70os_event_set() between this os_event_reset() and the
71os_event_wait_low() call. See comments for os_event_wait_low(). */
72int64_t os_event_reset(os_event_t event); /*!< in/out: event to reset */
73
74/**
75Frees an event object. */
76void os_event_destroy(os_event_t &event); /*!< in/own: event to free */
77
78/**
79Waits for an event object until it is in the signaled state.
80
81Typically, if the event has been signalled after the os_event_reset()
82we'll return immediately because event->is_set == true.
83There are, however, situations (e.g.: sync_array code) where we may
84lose this information. For example:
85
86thread A calls os_event_reset()
87thread B calls os_event_set() [event->is_set == true]
88thread C calls os_event_reset() [event->is_set == false]
89thread A calls os_event_wait() [infinite wait!]
90thread C calls os_event_wait() [infinite wait!]
91
92Where such a scenario is possible, to avoid infinite wait, the
93value returned by os_event_reset() should be passed in as
94reset_sig_count. */
95void os_event_wait_low(os_event_t event, /*!< in/out: event to wait */
96 int64_t reset_sig_count); /*!< in: zero or the value
97 returned by previous call of
98 os_event_reset(). */
99
100/** Blocking infinite wait on an event, until signalled.
101@param e - event to wait on. */
102static inline void os_event_wait(os_event_t e) { os_event_wait_low(e, 0); }
103
104/** Waits for an event object until it is in the signaled state or
105a timeout is exceeded. In Unix the timeout is always infinite.
106@param[in,out] event Event to wait for.
107@param[in] timeout Timeout, or std::chrono::microseconds::max().
108@param[in] reset_sig_count Zero or the value returned by previous call of
109os_event_reset().
110@return 0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded */
112 std::chrono::microseconds timeout,
113 int64_t reset_sig_count);
114
115/** Blocking timed wait on an event.
116@param e - event to wait on.
117@param t - timeout */
119 std::chrono::microseconds t) {
120 return os_event_wait_time_low(e, t, 0);
121}
122
123#include "os0event.ic"
124
125/** Initializes support for os_event objects. Must be called once,
126 and before any os_event object is created. */
127void os_event_global_init(void);
128
129/** Deinitializes support for os_event objects. Must be called once,
130 and after all os_event objects are destroyed. After it is called, no
131new os_event is allowed to be created. */
132void os_event_global_destroy(void);
133
134#endif /* !UNIV_HOTBACKUP */
135
136/** A RAII wrapper for os_event_t. */
138 public:
141 other.m_event = nullptr;
142 }
144
145 operator os_event_t() { return m_event; }
146
147 private:
149};
150
151#endif /* !os0event_h */
A RAII wrapper for os_event_t.
Definition: os0event.h:137
~Os_event_t()
Definition: os0event.h:143
os_event_t m_event
Definition: os0event.h:148
Os_event_t(Os_event_t &&other)
Definition: os0event.h:140
Os_event_t()
Definition: os0event.h:139
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:499
void os_event_global_destroy(void)
Deinitializes support for os_event objects.
Definition: os0event.cc:623
os_event_t os_event_create()
Creates an event semaphore, i.e., a semaphore which may just have two states: signaled and nonsignale...
Definition: os0event.cc:514
constexpr uint32_t OS_SYNC_TIME_EXCEEDED
Return value of os_event_wait_time() when the time is exceeded.
Definition: os0event.h:45
void os_event_global_init(void)
Initializes support for os_event objects.
Definition: os0event.cc:598
void os_event_destroy(os_event_t &event)
Frees an event object.
Definition: os0event.cc:579
ulint os_event_wait_time_low(os_event_t event, 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.
Definition: os0event.cc:557
static ulint os_event_wait_time(os_event_t e, std::chrono::microseconds t)
Blocking timed wait on an event.
Definition: os0event.h:118
void os_event_wait_low(os_event_t event, int64_t reset_sig_count)
Waits for an event object until it is in the signaled state.
Definition: os0event.cc:569
void os_event_set(os_event_t event)
Sets an event semaphore to the signaled state: lets waiting threads proceed.
Definition: os0event.cc:539
bool os_event_is_set(const os_event_t event)
Check if the event is set.
Definition: os0event.cc:531
static void os_event_wait(os_event_t e)
Blocking infinite wait on an event, until signalled.
Definition: os0event.h:102
struct os_event * os_event_t
Definition: os0event.h:42
int64_t os_event_reset(os_event_t event)
Resets an event semaphore to the non-signaled state.
Definition: os0event.cc:552
Inlined implementation for os_event_*.
required string event
Definition: replication_group_member_actions.proto:32
InnoDB condition variable.
Definition: os0event.cc:63
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:403