| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1995, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/sync0arr.ic |
| 29 |
The wait array for synchronization primitives |
| 30 |
|
| 31 |
Inline code |
| 32 |
|
| 33 |
Created 9/5/1995 Heikki Tuuri |
| 34 |
*******************************************************/ |
| 35 |
|
| 36 |
extern ulint sync_array_size; |
| 37 |
extern sync_array_t **sync_wait_array; |
| 38 |
|
| 39 |
#include "ut0counter.h" |
| 40 |
|
| 41 |
/** Get an instance of the sync wait array. |
| 42 |
@return an instance of the sync wait array. */ |
| 43 |
|
| 44 |
static inline sync_array_t *sync_array_get() { |
| 45 |
if (sync_array_size <= 1) { |
| 46 |
return (sync_wait_array[0]); |
| 47 |
} |
| 48 |
|
| 49 |
return ( |
| 50 |
sync_wait_array[default_indexer_t<>::get_rnd_index() % sync_array_size]); |
| 51 |
} |
| 52 |
|
| 53 |
static inline sync_array_t *sync_array_get_and_reserve_cell( |
| 54 |
void *object, ulint type, ut::Location location, sync_cell_t **cell) { |
| 55 |
sync_array_t *sync_arr = nullptr; |
| 56 |
|
| 57 |
*cell = nullptr; |
| 58 |
for (ulint i = 0; i < sync_array_size && *cell == nullptr; ++i) { |
| 59 |
/* Although the sync_array is get in a random way currently, |
| 60 |
we still try at most sync_array_size times, in case any |
| 61 |
of the sync_array we get is full */ |
| 62 |
sync_arr = sync_array_get(); |
| 63 |
*cell = sync_array_reserve_cell(sync_arr, object, type, location); |
| 64 |
} |
| 65 |
|
| 66 |
/* This won't be true every time, for the loop above may execute |
| 67 |
more than srv_sync_array_size times to reserve a cell. |
| 68 |
But an assertion here makes the code more solid. */ |
| 69 |
ut_a(*cell != nullptr); |
| 70 |
|
| 71 |
return (sync_arr); |
| 72 |
} |