InnoDB Plugin  1.0
Data Structures | Macros | Typedefs | Functions | Variables
os0sync.h File Reference
#include "univ.i"
#include "ut0lst.h"
#include "sync0types.h"
#include "os0sync.ic"
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.

Data Structures

struct  os_fast_mutex_t
struct  os_event

Macros

#define OS_SYNC_INFINITE_TIME   ULINT_UNDEFINED
#define OS_SYNC_TIME_EXCEEDED   1
#define os_event_wait(event)   os_event_wait_low(event, 0)
#define os_event_wait_time(event, t)   os_event_wait_time_low(event, t, 0)
#define os_fast_mutex_init(K, M)   os_fast_mutex_init_func(&((os_fast_mutex_t*)(M))->mutex)
#define os_fast_mutex_lock(M)   os_fast_mutex_lock_func(&((os_fast_mutex_t*)(M))->mutex)
#define os_fast_mutex_unlock(M)   os_fast_mutex_unlock_func(&((os_fast_mutex_t*)(M))->mutex)
#define os_fast_mutex_free(M)   os_fast_mutex_free_func(&((os_fast_mutex_t*)(M))->mutex)
#define IB_ATOMICS_STARTUP_MSG   "Mutexes and rw_locks use InnoDB's own implementation"
#define os_atomic_inc_ulint(m, v, d)   os_atomic_inc_ulint_func(m, v, d)
#define os_atomic_dec_ulint(m, v, d)   os_atomic_dec_ulint_func(m, v, d)
#define os_increment_counter_by_amount(mutex, counter, amount)
#define os_decrement_counter_by_amount(mutex, counter, amount)
#define os_inc_counter(mutex, counter)   os_increment_counter_by_amount(mutex, counter, 1)
#define os_dec_counter(mutex, counter)
#define os_rmb
#define os_wmb
#define IB_MEMORY_BARRIER_STARTUP_MSG   "Memory barrier is not used"

Typedefs

typedef pthread_mutex_t fast_mutex_t
typedef pthread_cond_t os_cond_t
typedef struct os_eventos_event_t
typedef struct os_mutex_t * os_ib_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 (void)
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_ib_mutex_t os_mutex_create (void)
UNIV_INTERN void os_mutex_enter (os_ib_mutex_t mutex)
UNIV_INTERN void os_mutex_exit (os_ib_mutex_t mutex)
UNIV_INTERN void os_mutex_free (os_ib_mutex_t mutex)
UNIV_INLINE ulint os_fast_mutex_trylock (os_fast_mutex_t *fast_mutex)
UNIV_INTERN void os_fast_mutex_unlock_func (fast_mutex_t *fast_mutex)
UNIV_INTERN void os_fast_mutex_init_func (fast_mutex_t *fast_mutex)
UNIV_INTERN void os_fast_mutex_lock_func (fast_mutex_t *fast_mutex)
UNIV_INTERN void os_fast_mutex_free_func (fast_mutex_t *fast_mutex)

Variables

os_ib_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

Macro Definition Documentation

#define IB_ATOMICS_STARTUP_MSG   "Mutexes and rw_locks use InnoDB's own implementation"

Atomic compare-and-swap and increment for InnoDB.

#define os_dec_counter (   mutex,
  counter 
)
Value:
do { \
os_decrement_counter_by_amount(mutex, counter, 1);\
} while (0);
#define os_decrement_counter_by_amount (   mutex,
  counter,
  amount 
)
Value:
do { \
ut_a(counter >= amount); \
mutex_enter(&(mutex)); \
(counter) -= (amount); \
mutex_exit(&(mutex)); \
} while (0)
#define os_increment_counter_by_amount (   mutex,
  counter,
  amount 
)
Value:
do { \
mutex_enter(&(mutex)); \
(counter) += (amount); \
mutex_exit(&(mutex)); \
} while (0)

Following macros are used to update specified counter atomically if HAVE_ATOMIC_BUILTINS defined. Otherwise, use mutex passed in for synchronization

#define os_rmb

barrier definitions for memory ordering

#define OS_SYNC_INFINITE_TIME   ULINT_UNDEFINED

Denotes an infinite delay for os_event_wait_time()

#define OS_SYNC_TIME_EXCEEDED   1

Return value of os_event_wait_time() when the time is exceeded

Typedef Documentation

typedef pthread_mutex_t fast_mutex_t

Native mutex

typedef pthread_cond_t os_cond_t

Native condition variable

typedef struct os_event* os_event_t

Operating system event handle

typedef struct os_mutex_t* os_ib_mutex_t

Operating system mutex handle

Function Documentation

UNIV_INTERN os_event_t os_event_create ( void  )

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
UNIV_INTERN void os_event_free ( os_event_t  event)

Frees an event object. in: event to free

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

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

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.

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().

Parameters
eventin: event to wait
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().
Parameters
eventin: event to wait
time_in_usecin: timeout in microseconds, or OS_SYNC_INFINITE_TIME
UNIV_INTERN void os_fast_mutex_free_func ( fast_mutex_t fast_mutex)

Frees an mutex object. in: mutex to free

UNIV_INTERN void os_fast_mutex_init_func ( fast_mutex_t fast_mutex)

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

UNIV_INTERN void os_fast_mutex_lock_func ( fast_mutex_t fast_mutex)

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

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

Acquires ownership of a fast mutex.

Returns
0 if success, != 0 if was reserved by another thread
Parameters
fast_mutexin: mutex to acquire
UNIV_INTERN void os_fast_mutex_unlock_func ( fast_mutex_t fast_mutex)

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

UNIV_INTERN os_ib_mutex_t os_mutex_create ( void  )

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

Returns
the mutex handle
UNIV_INTERN void os_mutex_enter ( os_ib_mutex_t  mutex)

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

UNIV_INTERN void os_mutex_exit ( os_ib_mutex_t  mutex)

Releases ownership of a mutex. in: mutex to release

UNIV_INTERN void os_mutex_free ( os_ib_mutex_t  mutex)

Frees an mutex object. in: mutex to free

UNIV_INTERN void os_sync_free ( void  )

Frees created events and OS 'slow' mutexes.

UNIV_INTERN void os_sync_init ( void  )

Initializes global event and OS 'slow' mutex lists.

Variable Documentation

os_ib_mutex_t os_sync_mutex

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

ulint os_thread_count
This is incremented by 1 in os_thread_create and decremented by 1 in

os_thread_exit