Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 1 | /* |
David Brazdil | 713580c | 2019-09-17 16:16:51 +0100 | [diff] [blame^] | 2 | * Copyright 2019 The Hafnium Authors. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andrew Scull | fbc938a | 2018-08-20 14:09:28 +0100 | [diff] [blame] | 17 | #pragma once |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 18 | |
David Brazdil | 713580c | 2019-09-17 16:16:51 +0100 | [diff] [blame^] | 19 | /* |
| 20 | * Includes the arch-specific definition of 'struct spinlock' and |
| 21 | * implementations of: |
| 22 | * - SPINLOCK_INIT |
| 23 | * - sl_lock() |
| 24 | * - sl_unlock() |
| 25 | */ |
| 26 | #include "hf/arch/spinlock.h" |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 27 | |
| 28 | static inline void sl_init(struct spinlock *l) |
| 29 | { |
David Brazdil | 713580c | 2019-09-17 16:16:51 +0100 | [diff] [blame^] | 30 | *l = SPINLOCK_INIT; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 31 | } |
| 32 | |
Andrew Scull | 6386f25 | 2018-12-06 13:29:10 +0000 | [diff] [blame] | 33 | /** |
| 34 | * Locks both locks, enforcing the lowest address first ordering for locks of |
| 35 | * the same kind. |
| 36 | */ |
| 37 | static inline void sl_lock_both(struct spinlock *a, struct spinlock *b) |
| 38 | { |
| 39 | if (a < b) { |
| 40 | sl_lock(a); |
| 41 | sl_lock(b); |
| 42 | } else { |
| 43 | sl_lock(b); |
| 44 | sl_lock(a); |
| 45 | } |
| 46 | } |