You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.0 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /******************************************************
  2. The wait array used in synchronization primitives
  3. (c) 1995 Innobase Oy
  4. Created 9/5/1995 Heikki Tuuri
  5. *******************************************************/
  6. #ifndef sync0arr_h
  7. #define sync0arr_h
  8. #include "univ.i"
  9. #include "ut0lst.h"
  10. #include "ut0mem.h"
  11. #include "os0thread.h"
  12. typedef struct sync_cell_struct sync_cell_t;
  13. typedef struct sync_array_struct sync_array_t;
  14. #define SYNC_ARRAY_OS_MUTEX 1
  15. #define SYNC_ARRAY_MUTEX 2
  16. /***********************************************************************
  17. Creates a synchronization wait array. It is protected by a mutex
  18. which is automatically reserved when the functions operating on it
  19. are called. */
  20. UNIV_INTERN
  21. sync_array_t*
  22. sync_array_create(
  23. /*==============*/
  24. /* out, own: created wait array */
  25. ulint n_cells, /* in: number of cells in the array
  26. to create */
  27. ulint protection); /* in: either SYNC_ARRAY_OS_MUTEX or
  28. SYNC_ARRAY_MUTEX: determines the type
  29. of mutex protecting the data structure */
  30. /**********************************************************************
  31. Frees the resources in a wait array. */
  32. UNIV_INTERN
  33. void
  34. sync_array_free(
  35. /*============*/
  36. sync_array_t* arr); /* in, own: sync wait array */
  37. /**********************************************************************
  38. Reserves a wait array cell for waiting for an object.
  39. The event of the cell is reset to nonsignalled state. */
  40. UNIV_INTERN
  41. void
  42. sync_array_reserve_cell(
  43. /*====================*/
  44. sync_array_t* arr, /* in: wait array */
  45. void* object, /* in: pointer to the object to wait for */
  46. ulint type, /* in: lock request type */
  47. const char* file, /* in: file where requested */
  48. ulint line, /* in: line where requested */
  49. ulint* index); /* out: index of the reserved cell */
  50. /**********************************************************************
  51. This function should be called when a thread starts to wait on
  52. a wait array cell. In the debug version this function checks
  53. if the wait for a semaphore will result in a deadlock, in which
  54. case prints info and asserts. */
  55. UNIV_INTERN
  56. void
  57. sync_array_wait_event(
  58. /*==================*/
  59. sync_array_t* arr, /* in: wait array */
  60. ulint index); /* in: index of the reserved cell */
  61. /**********************************************************************
  62. Frees the cell. NOTE! sync_array_wait_event frees the cell
  63. automatically! */
  64. UNIV_INTERN
  65. void
  66. sync_array_free_cell(
  67. /*=================*/
  68. sync_array_t* arr, /* in: wait array */
  69. ulint index); /* in: index of the cell in array */
  70. /**************************************************************************
  71. Note that one of the wait objects was signalled. */
  72. UNIV_INTERN
  73. void
  74. sync_array_object_signalled(
  75. /*========================*/
  76. sync_array_t* arr); /* in: wait array */
  77. /**************************************************************************
  78. If the wakeup algorithm does not work perfectly at semaphore relases,
  79. this function will do the waking (see the comment in mutex_exit). This
  80. function should be called about every 1 second in the server. */
  81. UNIV_INTERN
  82. void
  83. sync_arr_wake_threads_if_sema_free(void);
  84. /*====================================*/
  85. /**************************************************************************
  86. Prints warnings of long semaphore waits to stderr. */
  87. UNIV_INTERN
  88. ibool
  89. sync_array_print_long_waits(void);
  90. /*=============================*/
  91. /* out: TRUE if fatal semaphore wait threshold
  92. was exceeded */
  93. /************************************************************************
  94. Validates the integrity of the wait array. Checks
  95. that the number of reserved cells equals the count variable. */
  96. UNIV_INTERN
  97. void
  98. sync_array_validate(
  99. /*================*/
  100. sync_array_t* arr); /* in: sync wait array */
  101. /**************************************************************************
  102. Prints info of the wait array. */
  103. UNIV_INTERN
  104. void
  105. sync_array_print_info(
  106. /*==================*/
  107. FILE* file, /* in: file where to print */
  108. sync_array_t* arr); /* in: wait array */
  109. #ifndef UNIV_NONINL
  110. #include "sync0arr.ic"
  111. #endif
  112. #endif