sync0arr.h
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:4k
源码类别:

MySQL数据库

开发平台:

Visual C++

  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. sync_array_t*
  21. sync_array_create(
  22. /*==============*/
  23. /* out, own: created wait array */
  24. ulint n_cells, /* in: number of cells in the array
  25. to create */
  26. ulint protection); /* in: either SYNC_ARRAY_OS_MUTEX or
  27. SYNC_ARRAY_MUTEX: determines the type
  28. of mutex protecting the data structure */
  29. /**********************************************************************
  30. Frees the resources in a wait array. */
  31. void
  32. sync_array_free(
  33. /*============*/
  34. sync_array_t* arr); /* in, own: sync wait array */
  35. /**********************************************************************
  36. Reserves a wait array cell for waiting for an object.
  37. The event of the cell is reset to nonsignalled state. */
  38. void
  39. sync_array_reserve_cell(
  40. /*====================*/
  41.         sync_array_t* arr, /* in: wait array */
  42.         void*    object, /* in: pointer to the object to wait for */
  43.         ulint type, /* in: lock request type */
  44. const char* file, /* in: file where requested */
  45.         ulint line, /* in: line where requested */
  46.         ulint*    index); /* out: index of the reserved cell */
  47. /**********************************************************************
  48. This function should be called when a thread starts to wait on
  49. a wait array cell. In the debug version this function checks
  50. if the wait for a semaphore will result in a deadlock, in which
  51. case prints info and asserts. */
  52. void
  53. sync_array_wait_event(
  54. /*==================*/
  55.         sync_array_t* arr, /* in: wait array */
  56.         ulint    index);  /* in: index of the reserved cell */
  57. /**********************************************************************
  58. Frees the cell. NOTE! sync_array_wait_event frees the cell
  59. automatically! */
  60. void
  61. sync_array_free_cell(
  62. /*=================*/
  63. sync_array_t* arr, /* in: wait array */
  64.         ulint     index);  /* in: index of the cell in array */
  65. /**************************************************************************
  66. Looks for the cells in the wait array which refer
  67. to the wait object specified,
  68. and sets their corresponding events to the signaled state. In this
  69. way releases the threads waiting for the object to contend for the object.
  70. It is possible that no such cell is found, in which case does nothing. */
  71. void
  72. sync_array_signal_object(
  73. /*=====================*/
  74. sync_array_t* arr, /* in: wait array */
  75. void* object);/* in: wait object */
  76. /**************************************************************************
  77. If the wakeup algorithm does not work perfectly at semaphore relases,
  78. this function will do the waking (see the comment in mutex_exit). This
  79. function should be called about every 1 second in the server. */
  80. void
  81. sync_arr_wake_threads_if_sema_free(void);
  82. /*====================================*/
  83. /**************************************************************************
  84. Prints warnings of long semaphore waits to stderr. */
  85. ibool
  86. sync_array_print_long_waits(void);
  87. /*=============================*/
  88. /* out: TRUE if fatal semaphore wait threshold
  89. was exceeded */
  90. /************************************************************************
  91. Validates the integrity of the wait array. Checks
  92. that the number of reserved cells equals the count variable. */
  93. void
  94. sync_array_validate(
  95. /*================*/
  96. sync_array_t* arr); /* in: sync wait array */
  97. /**************************************************************************
  98. Prints info of the wait array. */
  99. void
  100. sync_array_print_info(
  101. /*==================*/
  102. FILE* file, /* in: file where to print */
  103. sync_array_t* arr); /* in: wait array */
  104. #ifndef UNIV_NONINL
  105. #include "sync0arr.ic"
  106. #endif
  107. #endif