blob: eb3b4355cb4c936d9d84504972713a2bcf981650 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
David Brazdilc4dfdb72019-09-23 07:39:24 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01003 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * 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 Scull18834872018-10-12 11:48:09 +01007 */
8
Andrew Scullfbc938a2018-08-20 14:09:28 +01009#pragma once
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010010
David Brazdilf8305e72019-09-27 13:17:52 +000011/*
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 Filho987c0ff2018-06-20 16:34:38 +010019
Andrew Scull6386f252018-12-06 13:29:10 +000020/**
21 * Locks both locks, enforcing the lowest address first ordering for locks of
22 * the same kind.
23 */
24static 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}