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