drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
os0sync.h File Reference
#include "univ.i"
#include "ut0lst.h"
Include dependency graph for os0sync.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  os_event_struct

Macros

#define os0sync_h
#define OS_SYNC_INFINITE_TIME   ULINT_UNDEFINED
#define OS_SYNC_TIME_EXCEEDED   1
#define os_event_wait(event)
#define os_event_wait_time(e, t)
#define HAVE_ATOMIC_BUILTINS
#define os_compare_and_swap(ptr, old_val, new_val)
#define os_compare_and_swap_ulint(ptr, old_val, new_val)
#define os_compare_and_swap_lint(ptr, old_val, new_val)
#define IB_ATOMICS_STARTUP_MSG    "Mutexes use GCC atomic builtins, rw_locks do not"
#define os_atomic_increment(ptr, amount)
#define os_atomic_increment_lint(ptr, amount)
#define os_atomic_increment_ulint(ptr, amount)
#define os_atomic_test_and_set_byte(ptr, new_val)

Typedefs

typedef pthread_mutex_t os_fast_mutex_t
typedef pthread_cond_t os_cond_t
typedef struct os_event_struct os_event_struct_t
typedef os_event_struct_t * os_event_t
typedef struct os_mutex_struct os_mutex_str_t
typedef os_mutex_str_t * os_mutex_t

Functions

UNIV_INTERN void os_sync_init (void)
UNIV_INTERN void os_sync_free (void)
UNIV_INTERN os_event_t os_event_create (const char *name)
UNIV_INTERN void os_event_set (os_event_t event)
UNIV_INTERN ib_int64_t os_event_reset (os_event_t event)
UNIV_INTERN void os_event_free (os_event_t event)
UNIV_INTERN void os_event_wait_low (os_event_t event, ib_int64_t reset_sig_count)
UNIV_INTERN ulint os_event_wait_time_low (os_event_t event, ulint time_in_usec, ib_int64_t reset_sig_count)
UNIV_INTERN os_mutex_t os_mutex_create (void)
UNIV_INTERN void os_mutex_enter (os_mutex_t mutex)
UNIV_INTERN void os_mutex_exit (os_mutex_t mutex)
UNIV_INTERN void os_mutex_free (os_mutex_t mutex)
UNIV_INLINE ulint os_fast_mutex_trylock (os_fast_mutex_t *fast_mutex)
UNIV_INTERN void os_fast_mutex_unlock (os_fast_mutex_t *fast_mutex)
UNIV_INTERN void os_fast_mutex_init (os_fast_mutex_t *fast_mutex)
UNIV_INTERN void os_fast_mutex_lock (os_fast_mutex_t *fast_mutex)
UNIV_INTERN void os_fast_mutex_free (os_fast_mutex_t *fast_mutex)

Variables

os_mutex_t os_sync_mutex
ulint os_thread_count
ulint os_event_count
ulint os_mutex_count
ulint os_fast_mutex_count

Detailed Description

The interface to the operating system synchronization primitives.

Created 9/6/1995 Heikki Tuuri

Definition in file os0sync.h.

Macro Definition Documentation

◆ HAVE_ATOMIC_BUILTINS

#define HAVE_ATOMIC_BUILTINS

Atomic compare-and-swap and increment for InnoDB.

Definition at line 272 of file os0sync.h.

◆ IB_ATOMICS_STARTUP_MSG

#define IB_ATOMICS_STARTUP_MSG    "Mutexes use GCC atomic builtins, rw_locks do not"

Definition at line 294 of file os0sync.h.

◆ os0sync_h

#define os0sync_h

Definition at line 36 of file os0sync.h.

◆ os_atomic_increment

#define os_atomic_increment ( ptr,
amount )
Value:
__sync_add_and_fetch(ptr, amount)

Returns the resulting value, ptr is pointer to target, amount is the amount of increment.

Definition at line 302 of file os0sync.h.

◆ os_atomic_increment_lint

#define os_atomic_increment_lint ( ptr,
amount )
Value:
os_atomic_increment(ptr, amount)
#define os_atomic_increment(ptr, amount)
Definition os0sync.h:302

Definition at line 305 of file os0sync.h.

◆ os_atomic_increment_ulint

#define os_atomic_increment_ulint ( ptr,
amount )
Value:
os_atomic_increment(ptr, amount)

Definition at line 308 of file os0sync.h.

◆ os_atomic_test_and_set_byte

#define os_atomic_test_and_set_byte ( ptr,
new_val )
Value:
__sync_lock_test_and_set(ptr, (byte) new_val)

Returns the old value of *ptr, atomically sets *ptr to new_val

Definition at line 314 of file os0sync.h.

◆ os_compare_and_swap

#define os_compare_and_swap ( ptr,
old_val,
new_val )
Value:
__sync_bool_compare_and_swap(ptr, old_val, new_val)

Returns true if swapped, ptr is pointer to target, old_val is value to compare to, new_val is the value to swap in.

Definition at line 278 of file os0sync.h.

◆ os_compare_and_swap_lint

#define os_compare_and_swap_lint ( ptr,
old_val,
new_val )
Value:
os_compare_and_swap(ptr, old_val, new_val)
#define os_compare_and_swap(ptr, old_val, new_val)
Definition os0sync.h:278

Definition at line 284 of file os0sync.h.

◆ os_compare_and_swap_ulint

#define os_compare_and_swap_ulint ( ptr,
old_val,
new_val )
Value:
os_compare_and_swap(ptr, old_val, new_val)

Definition at line 281 of file os0sync.h.

◆ os_event_wait

#define os_event_wait ( event)
Value:
UNIV_INTERN void os_event_wait_low(os_event_t event, ib_int64_t reset_sig_count)
Definition os0sync.cc:586

Definition at line 182 of file os0sync.h.

◆ os_event_wait_time

#define os_event_wait_time ( e,
t )
Value:
UNIV_INTERN ulint os_event_wait_time_low(os_event_t event, ulint time_in_usec, ib_int64_t reset_sig_count)
Definition os0sync.cc:652

Definition at line 183 of file os0sync.h.

◆ OS_SYNC_INFINITE_TIME

#define OS_SYNC_INFINITE_TIME   ULINT_UNDEFINED

Denotes an infinite delay for os_event_wait_time()

Definition at line 81 of file os0sync.h.

◆ OS_SYNC_TIME_EXCEEDED

#define OS_SYNC_TIME_EXCEEDED   1

Return value of os_event_wait_time() when the time is exceeded

Definition at line 84 of file os0sync.h.

Typedef Documentation

◆ os_cond_t

typedef pthread_cond_t os_cond_t

Native condition variable

Definition at line 52 of file os0sync.h.

◆ os_event_struct_t

Operating system event

Definition at line 56 of file os0sync.h.

◆ os_event_t

Operating system event handle

Definition at line 58 of file os0sync.h.

◆ os_fast_mutex_t

typedef pthread_mutex_t os_fast_mutex_t

Native mutex

Definition at line 50 of file os0sync.h.

◆ os_mutex_str_t

Operating system mutex

Definition at line 87 of file os0sync.h.

◆ os_mutex_t

Operating system mutex handle

Definition at line 89 of file os0sync.h.

Function Documentation

◆ os_event_create()

UNIV_INTERN 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 nonsignaled. The created event is manual reset: it must be reset explicitly by calling sync_os_reset_event.

Returns
the event handle in: the name of the event, if NULL the event is created without a name

Creates an event semaphore, i.e., a semaphore which may just have two states: signaled and nonsignaled. The created event is manual reset: it must be reset explicitly by calling sync_os_reset_event.

Returns
the event handle
Parameters
namein: the name of the event, if NULL the event is created without a name

Definition at line 365 of file os0sync.cc.

◆ os_event_free()

UNIV_INTERN void os_event_free ( os_event_t event)

Frees an event object. in: event to free

Frees an event object.

Parameters
eventin: event to free

Definition at line 535 of file os0sync.cc.

◆ os_event_reset()

UNIV_INTERN ib_int64_t os_event_reset ( os_event_t event)

Resets an event semaphore to the nonsignaled state. Waiting threads will stop to wait for the event. The return value should be passed to os_even_wait_low() if it is desired that this thread should not wait in case of an intervening call to os_event_set() between this os_event_reset() and the os_event_wait_low() call. See comments for os_event_wait_low(). in: event to reset

Resets an event semaphore to the nonsignaled state. Waiting threads will stop to wait for the event. The return value should be passed to os_even_wait_low() if it is desired that this thread should not wait in case of an intervening call to os_event_set() between this os_event_reset() and the os_event_wait_low() call. See comments for os_event_wait_low().

Returns
current signal_count.
Parameters
eventin: event to reset

Definition at line 472 of file os0sync.cc.

◆ os_event_set()

UNIV_INTERN void os_event_set ( os_event_t event)

Sets an event semaphore to the signaled state: lets waiting threads proceed. in: event to set

Sets an event semaphore to the signaled state: lets waiting threads proceed.

Parameters
eventin: event to set

Definition at line 434 of file os0sync.cc.

◆ os_event_wait_low()

UNIV_INTERN void os_event_wait_low ( os_event_t event,
ib_int64_t reset_sig_count )

Waits for an event object until it is in the signaled state. If srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the waiting thread when the event becomes signaled (or immediately if the event is already in the signaled state).

Typically, if the event has been signalled after the os_event_reset() we'll return immediately because event->is_set == TRUE. There are, however, situations (e.g.: sync_array code) where we may lose this information. For example:

thread A calls os_event_reset() thread B calls os_event_set() [event->is_set == TRUE] thread C calls os_event_reset() [event->is_set == FALSE] thread A calls os_event_wait() [infinite wait!] thread C calls os_event_wait() [infinite wait!]

Where such a scenario is possible, to avoid infinite wait, the value returned by os_event_reset() should be passed in as reset_sig_count. in: zero or the value returned by previous call of os_event_reset().

Waits for an event object until it is in the signaled state. If srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the waiting thread when the event becomes signaled (or immediately if the event is already in the signaled state).

Typically, if the event has been signalled after the os_event_reset() we'll return immediately because event->is_set == TRUE. There are, however, situations (e.g.: sync_array code) where we may lose this information. For example:

thread A calls os_event_reset() thread B calls os_event_set() [event->is_set == TRUE] thread C calls os_event_reset() [event->is_set == FALSE] thread A calls os_event_wait() [infinite wait!] thread C calls os_event_wait() [infinite wait!]

Where such a scenario is possible, to avoid infinite wait, the value returned by os_event_reset() should be passed in as reset_sig_count.

Parameters
eventin: event to wait
reset_sig_countin: zero or the value returned by previous call of os_event_reset().

Definition at line 586 of file os0sync.cc.

◆ os_event_wait_time_low()

UNIV_INTERN ulint os_event_wait_time_low ( os_event_t event,
ulint time_in_usec,
ib_int64_t reset_sig_count )

Waits for an event object until it is in the signaled state or a timeout is exceeded. In Unix the timeout is always infinite.

Returns
0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded in: zero or the value returned by previous call of os_event_reset().

Waits for an event object until it is in the signaled state or a timeout is exceeded.

Returns
0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded
Parameters
eventin: event to wait
time_in_usecin: timeout in microseconds, or OS_SYNC_INFINITE_TIME
reset_sig_countin: zero or the value returned by previous call of os_event_reset().

Definition at line 652 of file os0sync.cc.

◆ os_fast_mutex_free()

UNIV_INTERN void os_fast_mutex_free ( os_fast_mutex_t * fast_mutex)

Frees an mutex object. in: mutex to free

Frees a mutex object.

Parameters
fast_mutexin: mutex to free

Definition at line 930 of file os0sync.cc.

◆ os_fast_mutex_init()

UNIV_INTERN void os_fast_mutex_init ( os_fast_mutex_t * fast_mutex)

Initializes an operating system fast mutex semaphore. in: fast mutex

Initializes an operating system fast mutex semaphore.

Parameters
fast_mutexin: fast mutex

Definition at line 871 of file os0sync.cc.

◆ os_fast_mutex_lock()

UNIV_INTERN void os_fast_mutex_lock ( os_fast_mutex_t * fast_mutex)

Acquires ownership of a fast mutex. in: mutex to acquire

Acquires ownership of a fast mutex.

Parameters
fast_mutexin: mutex to acquire

Definition at line 900 of file os0sync.cc.

◆ os_fast_mutex_trylock()

UNIV_INLINE ulint os_fast_mutex_trylock ( os_fast_mutex_t * fast_mutex)

Acquires ownership of a fast mutex. Currently in Windows this is the same as os_fast_mutex_lock!

Returns
0 if success, != 0 if was reserved by another thread in: mutex to acquire

◆ os_fast_mutex_unlock()

UNIV_INTERN void os_fast_mutex_unlock ( os_fast_mutex_t * fast_mutex)

Releases ownership of a fast mutex. in: mutex to release

Releases ownership of a fast mutex.

Parameters
fast_mutexin: mutex to release

Definition at line 915 of file os0sync.cc.

◆ os_mutex_create()

UNIV_INTERN os_mutex_t os_mutex_create ( void )

Creates an operating system mutex semaphore. Because these are slow, the mutex semaphore of InnoDB itself (mutex_t) should be used where possible.

Returns
the mutex handle

Definition at line 774 of file os0sync.cc.

◆ os_mutex_enter()

UNIV_INTERN void os_mutex_enter ( os_mutex_t mutex)

Acquires ownership of a mutex semaphore. in: mutex to acquire

Acquires ownership of a mutex semaphore.

Parameters
mutexin: mutex to acquire

Definition at line 809 of file os0sync.cc.

◆ os_mutex_exit()

UNIV_INTERN void os_mutex_exit ( os_mutex_t mutex)

Releases ownership of a mutex. in: mutex to release

Releases ownership of a mutex.

Parameters
mutexin: mutex to release

Definition at line 824 of file os0sync.cc.

◆ os_mutex_free()

UNIV_INTERN void os_mutex_free ( os_mutex_t mutex)

Frees an mutex object. in: mutex to free

Frees a mutex object.

Parameters
mutexin: mutex to free

Definition at line 840 of file os0sync.cc.

◆ os_sync_free()

UNIV_INTERN void os_sync_free ( void )

Frees created events and OS 'slow' mutexes.

Definition at line 325 of file os0sync.cc.

◆ os_sync_init()

UNIV_INTERN void os_sync_init ( void )

Initializes global event and OS 'slow' mutex lists.

Definition at line 304 of file os0sync.cc.

Variable Documentation

◆ os_event_count

ulint os_event_count
extern

Definition at line 75 of file os0sync.cc.

◆ os_fast_mutex_count

ulint os_fast_mutex_count
extern

Definition at line 77 of file os0sync.cc.

◆ os_mutex_count

ulint os_mutex_count
extern

Definition at line 76 of file os0sync.cc.

◆ os_sync_mutex

os_mutex_t os_sync_mutex
extern

Mutex protecting counts and the event and OS 'slow' mutex lists

Mutex protecting counts and the lists of OS mutexes and events

Definition at line 59 of file os0sync.cc.

◆ os_thread_count

ulint os_thread_count
extern

This is incremented by 1 in os_thread_create and decremented by 1 in os_thread_exit

Definition at line 67 of file os0sync.cc.