22
33Copyright (c) 1995, 2025, Oracle and/or its affiliates.
44Copyright (c) 2008, Google Inc.
5+ Copyright (c) 2025, buildup-db.
56
67Portions of this file contain modifications contributed and copyrighted by
78Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -95,7 +96,7 @@ static inline void rw_lock_reset_waiter_flag(
9596static inline ulint rw_lock_get_writer(
9697 const rw_lock_t *lock) /*!< in: rw-lock */
9798{
98- lint lock_word = lock->lock_word;
99+ int32_t lock_word = lock->lock_word;
99100
100101 ut_ad(lock_word <= X_LOCK_DECR);
101102 if (lock_word > X_LOCK_HALF_DECR) {
@@ -122,7 +123,7 @@ static inline ulint rw_lock_get_writer(
122123static inline ulint rw_lock_get_reader_count(
123124 const rw_lock_t *lock) /*!< in: rw-lock */
124125{
125- lint lock_word = lock->lock_word;
126+ int32_t lock_word = lock->lock_word;
126127 ut_ad(lock_word <= X_LOCK_DECR);
127128
128129 if (lock_word > X_LOCK_HALF_DECR) {
@@ -154,7 +155,7 @@ static inline ulint rw_lock_get_reader_count(
154155static inline ulint rw_lock_get_x_lock_count(
155156 const rw_lock_t *lock) /*!< in: rw-lock */
156157{
157- lint lock_copy = lock->lock_word;
158+ int32_t lock_copy = lock->lock_word;
158159 ut_ad(lock_copy <= X_LOCK_DECR);
159160
160161 if (lock_copy == 0 || lock_copy == -X_LOCK_HALF_DECR) {
@@ -183,7 +184,7 @@ static inline ulint rw_lock_get_sx_lock_count(
183184 const rw_lock_t *lock) /*!< in: rw-lock */
184185{
185186#ifdef UNIV_DEBUG
186- lint lock_copy = lock->lock_word;
187+ int32_t lock_copy = lock->lock_word;
187188
188189 ut_ad(lock_copy <= X_LOCK_DECR);
189190
@@ -209,13 +210,12 @@ static inline ulint rw_lock_get_sx_lock_count(
209210 @return true if decr occurs */
210211ALWAYS_INLINE
211212bool rw_lock_lock_word_decr(rw_lock_t *lock, /*!< in/out: rw-lock */
212- ulint amount, /*!< in: amount to decrement */
213- lint threshold) /*!< in: threshold of judgement */
213+ int32_t amount, /*!< in: amount to decrement */
214+ int32_t threshold) /*!< in: threshold of judgement */
214215{
215216 int32_t local_lock_word;
216217
217- os_rmb;
218- local_lock_word = lock->lock_word;
218+ local_lock_word = lock->lock_word.load(std::memory_order_acquire);
219219 while (local_lock_word > threshold) {
220220 if (lock->lock_word.compare_exchange_strong(local_lock_word,
221221 local_lock_word - amount)) {
@@ -227,9 +227,9 @@ bool rw_lock_lock_word_decr(rw_lock_t *lock, /*!< in/out: rw-lock */
227227
228228/** Increments lock_word the specified amount and returns new value.
229229 @return lock->lock_word after increment */
230- static inline lint rw_lock_lock_word_incr(
230+ static inline int32_t rw_lock_lock_word_incr(
231231 rw_lock_t *lock, /*!< in/out: rw-lock */
232- ulint amount) /*!< in: amount of increment */
232+ int32_t amount) /*!< in: amount of increment */
233233{
234234 return (lock->lock_word.fetch_add(amount) + amount);
235235}
@@ -315,10 +315,11 @@ static inline bool rw_lock_x_lock_func_nowait(rw_lock_t *lock,
315315 /* Relock: this lock_word modification is safe since no other
316316 threads can modify (lock, unlock, or reserve) lock_word while
317317 there is an exclusive writer and this is the writer thread. */
318- if (lock->lock_word == 0 || lock->lock_word == -X_LOCK_HALF_DECR) {
318+ const int32_t lock_word = lock->lock_word;
319+ if (lock_word == 0 || lock_word == -X_LOCK_HALF_DECR) {
319320 /* There are 1 x-locks */
320321 lock->lock_word -= X_LOCK_DECR;
321- } else if (lock-> lock_word <= -X_LOCK_DECR) {
322+ } else if (lock_word <= -X_LOCK_DECR) {
322323 /* There are 2 or more x-locks */
323324 lock->lock_word--;
324325 } else {
@@ -362,7 +363,7 @@ static inline void rw_lock_s_unlock_func(IF_DEBUG(ulint pass, )
362363 ut_d(rw_lock_remove_debug_info(lock, pass, RW_LOCK_S));
363364
364365 /* Increment lock_word to indicate 1 less reader */
365- lint lock_word = rw_lock_lock_word_incr(lock, 1);
366+ int32_t lock_word = rw_lock_lock_word_incr(lock, 1);
366367 if (lock_word == 0 || lock_word == -X_LOCK_HALF_DECR) {
367368 /* wait_ex waiter exists. It may not be asleep, but we signal
368369 anyway. We do not wake other waiters, because they can't
@@ -396,7 +397,8 @@ static inline void rw_lock_x_unlock_func(IF_DEBUG(ulint pass, )
396397
397398 ut_d(rw_lock_remove_debug_info(lock, pass, RW_LOCK_X));
398399
399- if (lock->lock_word == 0 || lock->lock_word == -X_LOCK_HALF_DECR) {
400+ const int32_t lock_word = lock->lock_word;
401+ if (lock_word == 0 || lock_word == -X_LOCK_HALF_DECR) {
400402 /* There is 1 x-lock */
401403 /* atomic increment is needed, because it is last */
402404 if (rw_lock_lock_word_incr(lock, X_LOCK_DECR) <= 0) {
@@ -413,13 +415,13 @@ static inline void rw_lock_x_unlock_func(IF_DEBUG(ulint pass, )
413415 os_event_set(lock->event);
414416 sync_array_object_signalled();
415417 }
416- } else if (lock-> lock_word == -X_LOCK_DECR ||
417- lock-> lock_word == -(X_LOCK_DECR + X_LOCK_HALF_DECR)) {
418+ } else if (lock_word == -X_LOCK_DECR ||
419+ lock_word == -(X_LOCK_DECR + X_LOCK_HALF_DECR)) {
418420 /* There are 2 x-locks */
419421 lock->lock_word += X_LOCK_DECR;
420422 } else {
421423 /* There are more than 2 x-locks. */
422- ut_ad(lock-> lock_word < -X_LOCK_DECR);
424+ ut_ad(lock_word < -X_LOCK_DECR);
423425 lock->lock_word += 1;
424426 }
425427
0 commit comments