Drizzled Public API Documentation

sync0arr.h File Reference

#include "univ.i"
#include "ut0lst.h"
#include "ut0mem.h"
#include "os0thread.h"
#include "sync0arr.ic"

Go to the source code of this file.

Defines

#define SYNC_ARRAY_OS_MUTEX   1
#define SYNC_ARRAY_MUTEX   2

Typedefs

typedef struct sync_cell_struct sync_cell_t
typedef struct sync_array_struct sync_array_t

Functions

UNIV_INTERN sync_array_tsync_array_create (ulint n_cells, ulint protection)
UNIV_INTERN void sync_array_free (sync_array_t *arr)
UNIV_INTERN void sync_array_reserve_cell (sync_array_t *arr, void *object, ulint type, const char *file, ulint line, ulint *index)
UNIV_INTERN void sync_array_wait_event (sync_array_t *arr, ulint index)
UNIV_INTERN void sync_array_free_cell (sync_array_t *arr, ulint index)
UNIV_INTERN void sync_array_object_signalled (sync_array_t *arr)
UNIV_INTERN void sync_arr_wake_threads_if_sema_free (void)
UNIV_INTERN ibool sync_array_print_long_waits (void)
UNIV_INTERN void sync_array_validate (sync_array_t *arr)
UNIV_INTERN void sync_array_print_info (FILE *file, sync_array_t *arr)

Detailed Description

The wait array used in synchronization primitives

Created 9/5/1995 Heikki Tuuri

Definition in file sync0arr.h.


Define Documentation

#define SYNC_ARRAY_MUTEX   2

protected by mutex_t

Definition at line 42 of file sync0arr.h.

Referenced by sync_array_create(), and sync_array_free().

#define SYNC_ARRAY_OS_MUTEX   1

Parameters for sync_array_create() protected by os_mutex_t

Definition at line 41 of file sync0arr.h.

Referenced by sync_array_create(), sync_array_free(), and sync_init().


Typedef Documentation

Synchronization wait array

Definition at line 38 of file sync0arr.h.

typedef struct sync_cell_struct sync_cell_t

Synchronization wait array cell

Definition at line 36 of file sync0arr.h.


Function Documentation

UNIV_INTERN void sync_arr_wake_threads_if_sema_free ( void  )

If the wakeup algorithm does not work perfectly at semaphore relases, this function will do the waking (see the comment in mutex_exit). This function should be called about every 1 second in the server.

If the wakeup algorithm does not work perfectly at semaphore relases, this function will do the waking (see the comment in mutex_exit). This function should be called about every 1 second in the server.

Note that there's a race condition between this thread and mutex_exit changing the lock_word and calling signal_object, so sometimes this finds threads to wake up even when nothing has gone wrong.

Definition at line 882 of file sync0arr.cc.

References os_event_set(), sync_arr_wake_threads_if_sema_free(), sync_primary_wait_array, and sync_cell_struct::wait_object.

Referenced by srv_error_monitor_thread(), and sync_arr_wake_threads_if_sema_free().

UNIV_INTERN sync_array_t* sync_array_create ( ulint  n_cells,
ulint  protection 
)

Creates a synchronization wait array. It is protected by a mutex which is automatically reserved when the functions operating on it are called.

Returns:
own: created wait array in: either SYNC_ARRAY_OS_MUTEX or SYNC_ARRAY_MUTEX: determines the type of mutex protecting the data structure

Creates a synchronization wait array. It is protected by a mutex which is automatically reserved when the functions operating on it are called.

Returns:
own: created wait array
Parameters:
n_cellsin: number of cells in the array to create
protectionin: either SYNC_ARRAY_OS_MUTEX or SYNC_ARRAY_MUTEX: determines the type of mutex protecting the data structure

Definition at line 227 of file sync0arr.cc.

References sync_array_struct::array, sync_array_struct::mutex, sync_array_struct::n_cells, sync_array_struct::os_mutex, os_mutex_create(), sync_array_struct::protection, sync_array_create(), SYNC_ARRAY_MUTEX, SYNC_ARRAY_OS_MUTEX, ut_a, ut_error, and ut_malloc().

Referenced by sync_array_create(), and sync_init().

UNIV_INTERN void sync_array_free ( sync_array_t arr)

Frees the resources in a wait array. in, own: sync wait array

Frees the resources in a wait array.

Parameters:
arrin, own: sync wait array

Definition at line 268 of file sync0arr.cc.

References sync_array_struct::array, sync_array_struct::mutex, sync_array_struct::n_reserved, sync_array_struct::os_mutex, os_mutex_free(), sync_array_struct::protection, sync_array_free(), SYNC_ARRAY_MUTEX, SYNC_ARRAY_OS_MUTEX, sync_array_validate(), ut_a, ut_error, and ut_free().

Referenced by sync_array_free(), and sync_close().

UNIV_INTERN void sync_array_free_cell ( sync_array_t arr,
ulint  index 
)

Frees the cell. NOTE! sync_array_wait_event frees the cell automatically! in: index of the cell in array

Frees the cell. NOTE! sync_array_wait_event frees the cell automatically!

Parameters:
arrin: wait array
indexin: index of the cell in array

Definition at line 830 of file sync0arr.cc.

References sync_array_struct::n_reserved, sync_cell_struct::signal_count, sync_array_free_cell(), ut_a, sync_cell_struct::wait_object, and sync_cell_struct::waiting.

Referenced by rw_lock_x_lock_func(), sync_array_free_cell(), and sync_array_wait_event().

UNIV_INTERN void sync_array_object_signalled ( sync_array_t arr)

Note that one of the wait objects was signalled. in: wait array

Increments the signalled count.

Parameters:
arrin: wait array

Definition at line 857 of file sync0arr.cc.

References sync_array_struct::sg_count, and sync_array_object_signalled().

Referenced by sync_array_object_signalled().

UNIV_INTERN void sync_array_print_info ( FILE *  file,
sync_array_t arr 
)

Prints info of the wait array. in: wait array

Prints info of the wait array.

Parameters:
filein: file where to print
arrin: wait array

Definition at line 1020 of file sync0arr.cc.

References sync_array_print_info().

Referenced by sync_array_print_info(), and sync_print().

UNIV_INTERN ibool sync_array_print_long_waits ( void  )
UNIV_INTERN void sync_array_reserve_cell ( sync_array_t arr,
void *  object,
ulint  type,
const char *  file,
ulint  line,
ulint *  index 
)

Reserves a wait array cell for waiting for an object. The event of the cell is reset to nonsignalled state. out: index of the reserved cell

Reserves a wait array cell for waiting for an object. The event of the cell is reset to nonsignalled state.

Parameters:
arrin: wait array
objectin: pointer to the object to wait for
typein: lock request type
filein: file where requested
linein: line where requested
indexout: index of the reserved cell

Definition at line 345 of file sync0arr.cc.

References sync_cell_struct::file, sync_cell_struct::line, sync_array_struct::n_cells, sync_array_struct::n_reserved, sync_cell_struct::old_wait_mutex, sync_cell_struct::old_wait_rw_lock, os_event_reset(), os_thread_get_curr_id(), sync_cell_struct::request_type, sync_array_struct::res_count, sync_cell_struct::reservation_time, sync_cell_struct::signal_count, sync_array_reserve_cell(), sync_cell_struct::thread, ut_a, ut_error, sync_cell_struct::wait_object, and sync_cell_struct::waiting.

Referenced by rw_lock_x_lock_func(), and sync_array_reserve_cell().

UNIV_INTERN void sync_array_validate ( sync_array_t arr)

Validates the integrity of the wait array. Checks that the number of reserved cells equals the count variable. in: sync wait array

Validates the integrity of the wait array. Checks that the number of reserved cells equals the count variable.

Parameters:
arrin: sync wait array

Definition at line 299 of file sync0arr.cc.

References sync_array_struct::n_cells, sync_array_struct::n_reserved, sync_array_validate(), ut_a, and sync_cell_struct::wait_object.

Referenced by sync_array_free(), and sync_array_validate().

UNIV_INTERN void sync_array_wait_event ( sync_array_t arr,
ulint  index 
)

This function should be called when a thread starts to wait on a wait array cell. In the debug version this function checks if the wait for a semaphore will result in a deadlock, in which case prints info and asserts. in: index of the reserved cell

This function should be called when a thread starts to wait on a wait array cell. In the debug version this function checks if the wait for a semaphore will result in a deadlock, in which case prints info and asserts.

Parameters:
arrin: wait array
indexin: index of the reserved cell

Definition at line 417 of file sync0arr.cc.

References os_event_wait_low(), os_thread_get_curr_id(), sync_cell_struct::signal_count, sync_array_free_cell(), sync_array_wait_event(), sync_cell_struct::thread, ut_a, ut_ad, ut_error, sync_cell_struct::wait_object, and sync_cell_struct::waiting.

Referenced by rw_lock_x_lock_func(), and sync_array_wait_event().