1
/******************************************************
2
The interface to the operating system
3
synchronization primitives.
7
Created 9/6/1995 Heikki Tuuri
8
*******************************************************/
17
#define os_fast_mutex_t CRITICAL_SECTION
19
typedef HANDLE os_native_event_t;
21
typedef struct os_event_struct os_event_struct_t;
22
typedef os_event_struct_t* os_event_t;
24
struct os_event_struct {
25
os_native_event_t handle;
27
UT_LIST_NODE_T(os_event_struct_t) os_event_list;
28
/* list of all created events */
31
typedef pthread_mutex_t os_fast_mutex_t;
33
typedef struct os_event_struct os_event_struct_t;
34
typedef os_event_struct_t* os_event_t;
36
struct os_event_struct {
37
os_fast_mutex_t os_mutex; /* this mutex protects the next
39
ibool is_set; /* this is TRUE when the event is
40
in the signaled state, i.e., a thread
41
does not stop if it tries to wait for
43
ib_longlong signal_count; /* this is incremented each time
44
the event becomes signaled */
45
pthread_cond_t cond_var; /* condition variable is used in
46
waiting for the event */
47
UT_LIST_NODE_T(os_event_struct_t) os_event_list;
48
/* list of all created events */
52
typedef struct os_mutex_struct os_mutex_str_t;
53
typedef os_mutex_str_t* os_mutex_t;
55
#define OS_SYNC_INFINITE_TIME ((ulint)(-1))
57
#define OS_SYNC_TIME_EXCEEDED 1
59
/* Mutex protecting counts and the event and OS 'slow' mutex lists */
60
extern os_mutex_t os_sync_mutex;
62
/* This is incremented by 1 in os_thread_create and decremented by 1 in
64
extern ulint os_thread_count;
66
extern ulint os_event_count;
67
extern ulint os_mutex_count;
68
extern ulint os_fast_mutex_count;
70
/*************************************************************
71
Initializes global event and OS 'slow' mutex lists. */
76
/*************************************************************
77
Frees created events and OS 'slow' mutexes. */
82
/*************************************************************
83
Creates an event semaphore, i.e., a semaphore which may just have two states:
84
signaled and nonsignaled. The created event is manual reset: it must be reset
85
explicitly by calling sync_os_reset_event. */
90
/* out: the event handle */
91
const char* name); /* in: the name of the event, if NULL
92
the event is created without a name */
94
/*************************************************************
95
Creates an auto-reset event semaphore, i.e., an event which is automatically
96
reset when a single thread is released. Works only in Windows. */
100
/*=================*/
101
/* out: the event handle */
102
const char* name); /* in: the name of the event, if NULL
103
the event is created without a name */
105
/**************************************************************
106
Sets an event semaphore to the signaled state: lets waiting threads
112
os_event_t event); /* in: event to set */
113
/**************************************************************
114
Resets an event semaphore to the nonsignaled state. Waiting threads will
115
stop to wait for the event. */
120
os_event_t event); /* in: event to reset */
121
/**************************************************************
122
Frees an event object. */
127
os_event_t event); /* in: event to free */
128
/**************************************************************
129
Waits for an event object until it is in the signaled state. If
130
srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the
131
waiting thread when the event becomes signaled (or immediately if the
132
event is already in the signaled state). */
137
os_event_t event); /* in: event to wait */
138
/**************************************************************
139
Waits for an event object until it is in the signaled state or
140
a timeout is exceeded. In Unix the timeout is always infinite. */
145
/* out: 0 if success,
146
OS_SYNC_TIME_EXCEEDED if timeout
148
os_event_t event, /* in: event to wait */
149
ulint time); /* in: timeout in microseconds, or
150
OS_SYNC_INFINITE_TIME */
152
/**************************************************************
153
Waits for any event in an OS native event array. Returns if even a single
154
one is signaled or becomes signaled. */
157
os_event_wait_multiple(
158
/*===================*/
159
/* out: index of the event
160
which was signaled */
161
ulint n, /* in: number of events in the
163
os_native_event_t* native_event_array);
164
/* in: pointer to an array of event
167
/*************************************************************
168
Creates an operating system mutex semaphore. Because these are slow, the
169
mutex semaphore of InnoDB itself (mutex_t) should be used where possible. */
174
/* out: the mutex handle */
175
const char* name); /* in: the name of the mutex, if NULL
176
the mutex is created without a name */
177
/**************************************************************
178
Acquires ownership of a mutex semaphore. */
183
os_mutex_t mutex); /* in: mutex to acquire */
184
/**************************************************************
185
Releases ownership of a mutex. */
190
os_mutex_t mutex); /* in: mutex to release */
191
/**************************************************************
192
Frees an mutex object. */
197
os_mutex_t mutex); /* in: mutex to free */
198
/**************************************************************
199
Acquires ownership of a fast mutex. Currently in Windows this is the same
200
as os_fast_mutex_lock! */
203
os_fast_mutex_trylock(
204
/*==================*/
205
/* out: 0 if success, != 0 if
206
was reserved by another
208
os_fast_mutex_t* fast_mutex); /* in: mutex to acquire */
209
/**************************************************************
210
Releases ownership of a fast mutex. */
213
os_fast_mutex_unlock(
214
/*=================*/
215
os_fast_mutex_t* fast_mutex); /* in: mutex to release */
216
/*************************************************************
217
Initializes an operating system fast mutex semaphore. */
222
os_fast_mutex_t* fast_mutex); /* in: fast mutex */
223
/**************************************************************
224
Acquires ownership of a fast mutex. */
229
os_fast_mutex_t* fast_mutex); /* in: mutex to acquire */
230
/**************************************************************
231
Frees an mutex object. */
236
os_fast_mutex_t* fast_mutex); /* in: mutex to free */
239
#include "os0sync.ic"