43 typedef HANDLE os_native_event_t;
60 struct PSI_mutex* pfs_psi;
89 #define OS_SYNC_INFINITE_TIME ULINT_UNDEFINED
92 #define OS_SYNC_TIME_EXCEEDED 1
104 extern ulint os_event_count;
105 extern ulint os_mutex_count;
106 extern ulint os_fast_mutex_count;
179 ib_int64_t reset_sig_count);
183 #define os_event_wait(event) os_event_wait_low(event, 0)
184 #define os_event_wait_time(event, t) os_event_wait_time_low(event, t, 0)
198 ib_int64_t reset_sig_count);
254 #ifdef UNIV_PFS_MUTEX
255 # define os_fast_mutex_init(K, M) \
256 pfs_os_fast_mutex_init(K, M)
258 # define os_fast_mutex_lock(M) \
259 pfs_os_fast_mutex_lock(M, __FILE__, __LINE__)
261 # define os_fast_mutex_unlock(M) pfs_os_fast_mutex_unlock(M)
263 # define os_fast_mutex_free(M) pfs_os_fast_mutex_free(M)
272 pfs_os_fast_mutex_init(
284 pfs_os_fast_mutex_free(
293 pfs_os_fast_mutex_lock(
296 const char* file_name,
305 pfs_os_fast_mutex_unlock(
311 # define os_fast_mutex_init(K, M) \
312 os_fast_mutex_init_func(&((os_fast_mutex_t*)(M))->mutex)
314 # define os_fast_mutex_lock(M) \
315 os_fast_mutex_lock_func(&((os_fast_mutex_t*)(M))->mutex)
317 # define os_fast_mutex_unlock(M) \
318 os_fast_mutex_unlock_func(&((os_fast_mutex_t*)(M))->mutex)
320 # define os_fast_mutex_free(M) \
321 os_fast_mutex_free_func(&((os_fast_mutex_t*)(M))->mutex)
356 #if defined(HAVE_IB_GCC_ATOMIC_BUILTINS)
358 # define HAVE_ATOMIC_BUILTINS
360 # ifdef HAVE_IB_GCC_ATOMIC_BUILTINS_64
361 # define HAVE_ATOMIC_BUILTINS_64
368 # define os_compare_and_swap(ptr, old_val, new_val) \
369 __sync_bool_compare_and_swap(ptr, old_val, new_val)
371 # define os_compare_and_swap_ulint(ptr, old_val, new_val) \
372 os_compare_and_swap(ptr, old_val, new_val)
374 # define os_compare_and_swap_lint(ptr, old_val, new_val) \
375 os_compare_and_swap(ptr, old_val, new_val)
377 # ifdef HAVE_IB_ATOMIC_PTHREAD_T_GCC
378 # define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
379 os_compare_and_swap(ptr, old_val, new_val)
380 # define INNODB_RW_LOCKS_USE_ATOMICS
381 # define IB_ATOMICS_STARTUP_MSG \
382 "Mutexes and rw_locks use GCC atomic builtins"
384 # define IB_ATOMICS_STARTUP_MSG \
385 "Mutexes use GCC atomic builtins, rw_locks do not"
392 # define os_atomic_increment(ptr, amount) \
393 __sync_add_and_fetch(ptr, amount)
395 # define os_atomic_increment_lint(ptr, amount) \
396 os_atomic_increment(ptr, amount)
398 # define os_atomic_increment_ulint(ptr, amount) \
399 os_atomic_increment(ptr, amount)
401 # define os_atomic_increment_uint64(ptr, amount) \
402 os_atomic_increment(ptr, amount)
407 # define os_atomic_decrement(ptr, amount) \
408 __sync_sub_and_fetch(ptr, amount)
410 # define os_atomic_decrement_lint(ptr, amount) \
411 os_atomic_decrement(ptr, amount)
413 # define os_atomic_decrement_ulint(ptr, amount) \
414 os_atomic_decrement(ptr, amount)
416 # define os_atomic_decrement_uint64(ptr, amount) \
417 os_atomic_decrement(ptr, amount)
422 # define os_atomic_test_and_set_byte(ptr, new_val) \
423 __sync_lock_test_and_set(ptr, (byte) new_val)
425 # define os_atomic_test_and_set_ulint(ptr, new_val) \
426 __sync_lock_test_and_set(ptr, new_val)
428 #elif defined(HAVE_IB_SOLARIS_ATOMICS)
430 # define HAVE_ATOMIC_BUILTINS
431 # define HAVE_ATOMIC_BUILTINS_64
442 # define os_compare_and_swap_ulint(ptr, old_val, new_val) \
443 (atomic_cas_ulong(ptr, old_val, new_val) == old_val)
445 # define os_compare_and_swap_lint(ptr, old_val, new_val) \
446 ((lint) atomic_cas_ulong((ulong_t*) ptr, old_val, new_val) == old_val)
448 # ifdef HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS
449 # if SIZEOF_PTHREAD_T == 4
450 # define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
451 ((pthread_t) atomic_cas_32(ptr, old_val, new_val) == old_val)
452 # elif SIZEOF_PTHREAD_T == 8
453 # define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
454 ((pthread_t) atomic_cas_64(ptr, old_val, new_val) == old_val)
456 # error "SIZEOF_PTHREAD_T != 4 or 8"
458 # define INNODB_RW_LOCKS_USE_ATOMICS
459 # define IB_ATOMICS_STARTUP_MSG \
460 "Mutexes and rw_locks use Solaris atomic functions"
462 # define IB_ATOMICS_STARTUP_MSG \
463 "Mutexes use Solaris atomic functions, rw_locks do not"
470 # define os_atomic_increment_ulint(ptr, amount) \
471 atomic_add_long_nv(ptr, amount)
473 # define os_atomic_increment_lint(ptr, amount) \
474 os_atomic_increment_ulint((ulong_t*) ptr, amount)
476 # define os_atomic_increment_uint64(ptr, amount) \
477 atomic_add_64_nv(ptr, amount)
482 # define os_atomic_decrement_lint(ptr, amount) \
483 os_atomic_increment_ulint((ulong_t*) ptr, -(amount))
485 # define os_atomic_decrement_ulint(ptr, amount) \
486 os_atomic_increment_ulint(ptr, -(amount))
488 # define os_atomic_decrement_uint64(ptr, amount) \
489 os_atomic_increment_uint64(ptr, -(amount))
494 # define os_atomic_test_and_set_byte(ptr, new_val) \
495 atomic_swap_uchar(ptr, new_val)
497 # define os_atomic_test_and_set_ulint(ptr, new_val) \
498 atomic_swap_ulong(ptr, new_val)
500 #elif defined(HAVE_WINDOWS_ATOMICS)
502 # define HAVE_ATOMIC_BUILTINS
505 # define HAVE_ATOMIC_BUILTINS_64
514 win_cmp_and_xchg_lint(
536 win_cmp_and_xchg_ulint(
548 win_cmp_and_xchg_dword(
558 # define os_compare_and_swap_ulint(ptr, old_val, new_val) \
559 (win_cmp_and_xchg_ulint(ptr, new_val, old_val) == old_val)
561 # define os_compare_and_swap_lint(ptr, old_val, new_val) \
562 (win_cmp_and_xchg_lint(ptr, new_val, old_val) == old_val)
565 # define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
566 (win_cmp_and_xchg_dword(ptr, new_val, old_val) == old_val)
568 # define INNODB_RW_LOCKS_USE_ATOMICS
569 # define IB_ATOMICS_STARTUP_MSG \
570 "Mutexes and rw_locks use Windows interlocked functions"
576 # define os_atomic_increment_lint(ptr, amount) \
577 (win_xchg_and_add(ptr, amount) + amount)
579 # define os_atomic_increment_ulint(ptr, amount) \
580 ((ulint) (win_xchg_and_add((lint*) ptr, (lint) amount) + amount))
582 # define os_atomic_increment_uint64(ptr, amount) \
583 ((ib_uint64_t) (InterlockedExchangeAdd64( \
585 (ib_int64_t) amount) + amount))
591 # define os_atomic_decrement_lint(ptr, amount) \
592 (win_xchg_and_add(ptr, -(lint) amount) - amount)
594 # define os_atomic_decrement_ulint(ptr, amount) \
595 ((ulint) (win_xchg_and_add((lint*) ptr, -(lint) amount) - amount))
597 # define os_atomic_decrement_uint64(ptr, amount) \
598 ((ib_uint64_t) (InterlockedExchangeAdd64( \
600 -(ib_int64_t) amount) - amount))
607 # define os_atomic_test_and_set_byte(ptr, new_val) \
608 ((byte) InterlockedExchange(ptr, new_val))
610 # define os_atomic_test_and_set_ulong(ptr, new_val) \
611 InterlockedExchange(ptr, new_val)
614 # define IB_ATOMICS_STARTUP_MSG \
615 "Mutexes and rw_locks use InnoDB's own implementation"
617 #ifdef HAVE_ATOMIC_BUILTINS
618 #define os_atomic_inc_ulint(m,v,d) os_atomic_increment_ulint(v, d)
619 #define os_atomic_dec_ulint(m,v,d) os_atomic_decrement_ulint(v, d)
621 #define os_atomic_inc_ulint(m,v,d) os_atomic_inc_ulint_func(m, v, d)
622 #define os_atomic_dec_ulint(m,v,d) os_atomic_dec_ulint_func(m, v, d)
629 #ifdef HAVE_ATOMIC_BUILTINS
630 #define os_increment_counter_by_amount(mutex, counter, amount) \
631 (void) os_atomic_increment_ulint(&counter, amount)
633 #define os_decrement_counter_by_amount(mutex, counter, amount) \
634 (void) os_atomic_increment_ulint(&counter, (-((lint) amount)))
636 #define os_increment_counter_by_amount(mutex, counter, amount) \
638 mutex_enter(&(mutex)); \
639 (counter) += (amount); \
640 mutex_exit(&(mutex)); \
643 #define os_decrement_counter_by_amount(mutex, counter, amount) \
645 ut_a(counter >= amount); \
646 mutex_enter(&(mutex)); \
647 (counter) -= (amount); \
648 mutex_exit(&(mutex)); \
652 #define os_inc_counter(mutex, counter) \
653 os_increment_counter_by_amount(mutex, counter, 1)
655 #define os_dec_counter(mutex, counter) \
657 os_decrement_counter_by_amount(mutex, counter, 1);\
661 #include "os0sync.ic"