| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * 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. |
|---|
| 13 | 4 | * |
|---|
| 14 | 5 | * (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P. |
|---|
| 15 | 6 | * |
|---|
| .. | .. |
|---|
| 71 | 62 | if (unlikely(cnts)) |
|---|
| 72 | 63 | return 0; |
|---|
| 73 | 64 | |
|---|
| 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)); |
|---|
| 76 | 67 | } |
|---|
| 77 | 68 | /** |
|---|
| 78 | 69 | * queued_read_lock - acquire read lock of a queue rwlock |
|---|
| .. | .. |
|---|
| 96 | 87 | */ |
|---|
| 97 | 88 | static inline void queued_write_lock(struct qrwlock *lock) |
|---|
| 98 | 89 | { |
|---|
| 90 | + u32 cnts = 0; |
|---|
| 99 | 91 | /* 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))) |
|---|
| 101 | 93 | return; |
|---|
| 102 | 94 | |
|---|
| 103 | 95 | queued_write_lock_slowpath(lock); |
|---|