73
76
UNIV_INTERN ulint os_mutex_count = 0;
74
77
UNIV_INTERN ulint os_fast_mutex_count = 0;
79
/* The number of microsecnds in a second. */
80
static const ulint MICROSECS_IN_A_SECOND = 1000000;
76
82
/* Because a mutex is embedded inside an event and there is an
77
83
event embedded inside a mutex, on free, this generates a recursive call.
78
84
This version of the free event function doesn't acquire the global lock */
125
131
/*********************************************************//**
132
Do a timed wait on condition variable.
133
@return TRUE if timed out, FALSE otherwise */
138
os_cond_t* cond, /*!< in: condition variable. */
139
os_fast_mutex_t* mutex, /*!< in: fast mutex */
141
const struct timespec* abstime /*!< in: timeout */
143
DWORD time_in_ms /*!< in: timeout in
145
#endif /* !__WIN__ */
152
ut_a(sleep_condition_variable != NULL);
154
ret = sleep_condition_variable(cond, mutex, time_in_ms);
157
err = GetLastError();
158
/* From http://msdn.microsoft.com/en-us/library/ms686301%28VS.85%29.aspx,
159
"Condition variables are subject to spurious wakeups
160
(those not associated with an explicit wake) and stolen wakeups
161
(another thread manages to run before the woken thread)."
162
Check for both types of timeouts.
163
Conditions are checked by the caller.*/
164
if ((err == WAIT_TIMEOUT) || (err == ERROR_TIMEOUT)) {
175
ret = pthread_cond_timedwait(cond, mutex, abstime);
180
/* We play it safe by checking for EINTR even though
181
according to the POSIX documentation it can't return EINTR. */
186
fprintf(stderr, " InnoDB: pthread_cond_timedwait() returned: "
187
"%d: abstime={%lu,%lu}\n",
188
ret, (ulong) abstime->tv_sec, (ulong) abstime->tv_nsec);
192
return(ret == ETIMEDOUT);
195
/*********************************************************//**
126
196
Wait on condition variable */
646
/**********************************************************//**
647
Waits for an event object until it is in the signaled state or
648
a timeout is exceeded.
649
@return 0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded */
652
os_event_wait_time_low(
653
/*===================*/
654
os_event_t event, /*!< in: event to wait */
655
ulint time_in_usec, /*!< in: timeout in
657
OS_SYNC_INFINITE_TIME */
658
ib_int64_t reset_sig_count) /*!< in: zero or the value
659
returned by previous call of
663
ibool timed_out = FALSE;
664
ib_int64_t old_signal_count;
669
if (!srv_use_native_conditions) {
674
if (time_in_usec != OS_SYNC_INFINITE_TIME) {
675
time_in_ms = time_in_usec / 1000;
676
err = WaitForSingleObject(event->handle, time_in_ms);
678
err = WaitForSingleObject(event->handle, INFINITE);
681
if (err == WAIT_OBJECT_0) {
683
} else if ((err == WAIT_TIMEOUT) || (err == ERROR_TIMEOUT)) {
684
return(OS_SYNC_TIME_EXCEEDED);
688
/* Dummy value to eliminate compiler warning. */
691
ut_a(sleep_condition_variable != NULL);
693
if (time_in_usec != OS_SYNC_INFINITE_TIME) {
694
time_in_ms = time_in_usec / 1000;
696
time_in_ms = INFINITE;
700
struct timespec abstime;
702
if (time_in_usec != OS_SYNC_INFINITE_TIME) {
708
ret = ut_usectime(&sec, &usec);
714
tv.tv_usec += time_in_usec;
716
if ((ulint) tv.tv_usec >= MICROSECS_IN_A_SECOND) {
717
tv.tv_sec += time_in_usec / MICROSECS_IN_A_SECOND;
718
tv.tv_usec %= MICROSECS_IN_A_SECOND;
721
abstime.tv_sec = tv.tv_sec;
722
abstime.tv_nsec = tv.tv_usec * 1000;
724
abstime.tv_nsec = 999999999;
725
abstime.tv_sec = (time_t) ULINT_MAX;
728
ut_a(abstime.tv_nsec <= 999999999);
732
os_fast_mutex_lock(&event->os_mutex);
734
if (reset_sig_count) {
735
old_signal_count = reset_sig_count;
737
old_signal_count = event->signal_count;
741
if (event->is_set == TRUE
742
|| event->signal_count != old_signal_count) {
747
timed_out = os_cond_wait_timed(
748
&event->cond_var, &event->os_mutex,
753
#endif /* !__WIN__ */
756
} while (!timed_out);
758
os_fast_mutex_unlock(&event->os_mutex);
760
if (srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS) {
762
os_thread_exit(NULL);
765
return(timed_out ? OS_SYNC_TIME_EXCEEDED : 0);
576
768
/*********************************************************//**
577
769
Creates an operating system mutex semaphore. Because these are slow, the
578
770
mutex semaphore of InnoDB itself (mutex_t) should be used where possible.