hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/include/asm-generic/qrwlock.h
....@@ -1,15 +1,6 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Queue read/write lock
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
134 *
145 * (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P.
156 *
....@@ -71,8 +62,8 @@
7162 if (unlikely(cnts))
7263 return 0;
7364
74
- return likely(atomic_cmpxchg_acquire(&lock->cnts,
75
- cnts, cnts | _QW_LOCKED) == cnts);
65
+ return likely(atomic_try_cmpxchg_acquire(&lock->cnts, &cnts,
66
+ _QW_LOCKED));
7667 }
7768 /**
7869 * queued_read_lock - acquire read lock of a queue rwlock
....@@ -96,8 +87,9 @@
9687 */
9788 static inline void queued_write_lock(struct qrwlock *lock)
9889 {
90
+ u32 cnts = 0;
9991 /* Optimize for the unfair lock case where the fair flag is 0. */
100
- if (atomic_cmpxchg_acquire(&lock->cnts, 0, _QW_LOCKED) == 0)
92
+ if (likely(atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)))
10193 return;
10294
10395 queued_write_lock_slowpath(lock);