38
38
#include "ut0lst.h"
41
/** Native event (slow)*/
42
typedef HANDLE os_native_event_t;
43
42
/** Native mutex */
44
typedef CRITICAL_SECTION os_fast_mutex_t;
45
/** Native condition variable. */
46
typedef CONDITION_VARIABLE os_cond_t;
43
#define os_fast_mutex_t CRITICAL_SECTION
46
typedef HANDLE os_native_event_t;
48
/** Operating system event */
49
typedef struct os_event_struct os_event_struct_t;
50
/** Operating system event handle */
51
typedef os_event_struct_t* os_event_t;
53
/** An asynchronous signal sent between threads */
54
struct os_event_struct {
55
os_native_event_t handle;
57
UT_LIST_NODE_T(os_event_struct_t) os_event_list;
58
/*!< list of all created events */
48
61
/** Native mutex */
49
typedef pthread_mutex_t os_fast_mutex_t;
50
/** Native condition variable */
51
typedef pthread_cond_t os_cond_t;
62
typedef pthread_mutex_t os_fast_mutex_t;
54
64
/** Operating system event */
55
65
typedef struct os_event_struct os_event_struct_t;
59
69
/** An asynchronous signal sent between threads */
60
70
struct os_event_struct {
62
HANDLE handle; /*!< kernel event object, slow,
63
used on older Windows */
65
71
os_fast_mutex_t os_mutex; /*!< this mutex protects the next
67
73
ibool is_set; /*!< this is TRUE when the event is
71
77
ib_int64_t signal_count; /*!< this is incremented each time
72
78
the event becomes signaled */
73
os_cond_t cond_var; /*!< condition variable is used in
79
pthread_cond_t cond_var; /*!< condition variable is used in
74
80
waiting for the event */
75
81
UT_LIST_NODE_T(os_event_struct_t) os_event_list;
76
82
/*!< list of all created events */
79
86
/** Operating system mutex */
80
87
typedef struct os_mutex_struct os_mutex_str_t;
81
88
/** Operating system mutex handle */
82
89
typedef os_mutex_str_t* os_mutex_t;
91
/** Denotes an infinite delay for os_event_wait_time() */
92
#define OS_SYNC_INFINITE_TIME ((ulint)(-1))
94
/** Return value of os_event_wait_time() when the time is exceeded */
95
#define OS_SYNC_TIME_EXCEEDED 1
84
97
/** Mutex protecting counts and the event and OS 'slow' mutex lists */
85
98
extern os_mutex_t os_sync_mutex;
175
188
#define os_event_wait(event) os_event_wait_low(event, 0)
190
/**********************************************************//**
191
Waits for an event object until it is in the signaled state or
192
a timeout is exceeded. In Unix the timeout is always infinite.
193
@return 0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded */
198
os_event_t event, /*!< in: event to wait */
199
ulint time); /*!< in: timeout in microseconds, or
200
OS_SYNC_INFINITE_TIME */
202
/**********************************************************//**
203
Waits for any event in an OS native event array. Returns if even a single
204
one is signaled or becomes signaled.
205
@return index of the event which was signaled */
208
os_event_wait_multiple(
209
/*===================*/
210
ulint n, /*!< in: number of events in the
212
os_native_event_t* native_event_array);
213
/*!< in: pointer to an array of event
177
216
/*********************************************************//**
178
217
Creates an operating system mutex semaphore. Because these are slow, the
179
218
mutex semaphore of InnoDB itself (mutex_t) should be used where possible.
180
219
@return the mutex handle */
183
os_mutex_create(void);
184
/*=================*/
224
const char* name); /*!< in: the name of the mutex, if NULL
225
the mutex is created without a name */
185
226
/**********************************************************//**
186
227
Acquires ownership of a mutex semaphore. */
289
330
Returns the old value of *ptr, atomically sets *ptr to new_val */
291
332
# define os_atomic_test_and_set_byte(ptr, new_val) \
292
__sync_lock_test_and_set(ptr, (byte) new_val)
333
__sync_lock_test_and_set(ptr, new_val)
294
335
#elif defined(HAVE_SOLARIS_ATOMICS)