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.

64 lines
2.3 KiB

12 years ago
12 years ago
  1. /*****************************************************************************
  2. Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  12. *****************************************************************************/
  13. /**************************************************//**
  14. @file include/sync0arr.ic
  15. The wait array for synchronization primitives
  16. Inline code
  17. Created 9/5/1995 Heikki Tuuri
  18. *******************************************************/
  19. /** User configured sync array size */
  20. extern ulong srv_sync_array_size;
  21. /******************************************************************//**
  22. Get an instance of the sync wait array and reserve a wait array cell
  23. in the instance for waiting for an object. The event of the cell is
  24. reset to nonsignalled state.
  25. If reserving cell of the instance fails, try to get another new
  26. instance until we can reserve an empty cell of it.
  27. @return the instance found, never NULL. */
  28. UNIV_INLINE
  29. sync_array_t*
  30. sync_array_get_and_reserve_cell(
  31. /*============================*/
  32. void* object, /*!< in: pointer to the object to wait for */
  33. ulint type, /*!< in: lock request type */
  34. const char* file, /*!< in: file where requested */
  35. ulint line, /*!< in: line where requested */
  36. ulint* index) /*!< out: index of the reserved cell */
  37. {
  38. sync_array_t* sync_arr;
  39. bool reserved = false;
  40. for (ulint i = 0; i < srv_sync_array_size && !reserved; ++i) {
  41. sync_arr = sync_array_get();
  42. reserved = sync_array_reserve_cell(sync_arr, object, type,
  43. file, line, index);
  44. }
  45. /* This won't be true every time, for the loop above may execute
  46. more than srv_sync_array_size times to reserve a cell.
  47. But an assertion here makes the code more solid. */
  48. ut_a(reserved);
  49. return sync_arr;
  50. }