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