Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 1 | /* |
David Brazdil | c4dfdb7 | 2019-09-23 07:39:24 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Scull | fbc938a | 2018-08-20 14:09:28 +0100 | [diff] [blame] | 9 | #pragma once |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 10 | |
David Brazdil | f8305e7 | 2019-09-27 13:17:52 +0000 | [diff] [blame] | 11 | /* |
| 12 | * Includes the arch-specific definition of 'struct spinlock' and |
| 13 | * implementations of: |
| 14 | * - SPINLOCK_INIT |
| 15 | * - sl_lock() |
| 16 | * - sl_unlock() |
| 17 | */ |
| 18 | #include "hf/arch/spinlock.h" |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 19 | |
Andrew Scull | 6386f25 | 2018-12-06 13:29:10 +0000 | [diff] [blame] | 20 | /** |
| 21 | * Locks both locks, enforcing the lowest address first ordering for locks of |
| 22 | * the same kind. |
| 23 | */ |
| 24 | static inline void sl_lock_both(struct spinlock *a, struct spinlock *b) |
| 25 | { |
| 26 | if (a < b) { |
| 27 | sl_lock(a); |
| 28 | sl_lock(b); |
| 29 | } else { |
| 30 | sl_lock(b); |
| 31 | sl_lock(a); |
| 32 | } |
| 33 | } |