Debian Codegraph @

storage/innobase/include/os0event.h

raw
1 /*****************************************************************************
2 Copyright (c) 1995, 2026, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License, version 2.0, as published by the
6 Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 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.
41 struct os_event;
42 typedef struct os_event *os_event_t;
43
44 /** Return value of os_event_wait_time() when the time is exceeded */
45 constexpr uint32_t OS_SYNC_TIME_EXCEEDED = 1;
46
47 #ifndef UNIV_HOTBACKUP
48 /**
49 Creates an event semaphore, i.e., a semaphore which may just have two states:
50 signaled and nonsignaled. The created event is manual reset: it must be reset
51 explicitly by calling os_event_reset().
52 @return the event handle */
53 os_event_t os_event_create();
54
55 /**
56 Sets an event semaphore to the signaled state: lets waiting threads
57 proceed. */
58 void os_event_set(os_event_t event); /*!< in/out: event to set */
59
60 bool os_event_try_set(os_event_t event);
61
62 /**
63 Check if the event is set.
64 @return true if set */
65 bool os_event_is_set(const os_event_t event); /*!< in: event to set */
66
67 /**
68 Resets an event semaphore to the non-signaled state. Waiting threads will
69 stop to wait for the event.
70 The return value should be passed to os_even_wait_low() if it is desired
71 that this thread should not wait in case of an intervening call to
72 os_event_set() between this os_event_reset() and the
73 os_event_wait_low() call. See comments for os_event_wait_low(). */
74 int64_t os_event_reset(os_event_t event); /*!< in/out: event to reset */
75
76 /**
77 Frees an event object. */
78 void os_event_destroy(os_event_t &event); /*!< in/own: event to free */
79
80 /**
81 Waits for an event object until it is in the signaled state.
82
83 Typically, if the event has been signalled after the os_event_reset()
84 we'll return immediately because event->is_set == true.
85 There are, however, situations (e.g.: sync_array code) where we may
86 lose this information. For example:
87
88 thread A calls os_event_reset()
89 thread B calls os_event_set() [event->is_set == true]
90 thread C calls os_event_reset() [event->is_set == false]
91 thread A calls os_event_wait() [infinite wait!]
92 thread C calls os_event_wait() [infinite wait!]
93
94 Where such a scenario is possible, to avoid infinite wait, the
95 value returned by os_event_reset() should be passed in as
96 reset_sig_count. */
97 void os_event_wait_low(os_event_t event, /*!< in/out: event to wait */
98 int64_t reset_sig_count); /*!< in: zero or the value
99 returned by previous call of
100 os_event_reset(). */
101
102 /** Blocking infinite wait on an event, until signalled.
103 @param e - event to wait on. */
104 static inline void os_event_wait(os_event_t e) { os_event_wait_low(e, 0); }
105
106 /** Waits for an event object until it is in the signaled state or
107 a timeout is exceeded. In Unix the timeout is always infinite.
108 @param[in,out] event Event to wait for.
109 @param[in] timeout Timeout, or std::chrono::microseconds::max().
110 @param[in] reset_sig_count Zero or the value returned by previous call of
111 os_event_reset().
112 @return 0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded */
113 ulint os_event_wait_time_low(os_event_t event,
114 std::chrono::microseconds timeout,
115 int64_t reset_sig_count);
116
117 /** Blocking timed wait on an event.
118 @param e - event to wait on.
119 @param t - timeout */
120 static inline ulint os_event_wait_time(os_event_t e,
121 std::chrono::microseconds t) {
122 return os_event_wait_time_low(e, t, 0);
123 }
124
125 #include "os0event.ic"
126
127 /** Initializes support for os_event objects. Must be called once,
128 and before any os_event object is created. */
129 void os_event_global_init(void);
130
131 /** Deinitializes support for os_event objects. Must be called once,
132 and after all os_event objects are destroyed. After it is called, no
133 new os_event is allowed to be created. */
134 void os_event_global_destroy(void);
135
136 #endif /* !UNIV_HOTBACKUP */
137 #endif /* !os0event_h */