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