diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-04-30 17:06:02 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-04-30 17:06:02 +0300 |
| commit | ea5ebe0809fb31b9f125ac0689f706cc5f3f078f (patch) | |
| tree | 17081bd689709a9bfe48467c458425dea876bddd /include/apos/lock.h | |
| parent | 8a5e4cf53d981e793fca90d9b51bd395265cf4db (diff) | |
| download | kmi-ea5ebe0809fb31b9f125ac0689f706cc5f3f078f.tar.gz kmi-ea5ebe0809fb31b9f125ac0689f706cc5f3f078f.zip | |
rename to kmi
Diffstat (limited to 'include/apos/lock.h')
| -rw-r--r-- | include/apos/lock.h | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/include/apos/lock.h b/include/apos/lock.h deleted file mode 100644 index a841d4b..0000000 --- a/include/apos/lock.h +++ /dev/null @@ -1,55 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* Copyright 2021 - 2022, Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ - -#ifndef APOS_LOCK_H -#define APOS_LOCK_H - -/** - * @file lock.h - * Atomic locks, currently only \ref spin_lock() and \ref spin_unlock(). Mutex is - * probably overkill for this project. - */ - -#include <apos/atomic.h> -#include <apos/irq.h> - -/** - * Typedef for atomic_int. - * - * In apos, spinlocks are implemented with compiler-intrinsic atomic integers, - * that essentially just contain some flags. Currently all spinlocks - * enable/disable irqs. - * - * \todo irq contexts? - */ -typedef atomic_int spinlock_t; - -#include <arch/lock.h> - -/** - * Lock a spinlock. - * - * @param lck Pointer to lock. - */ -static inline void spin_lock(spinlock_t *lck) -{ - disable_irq(); - do { - while (atomic_load_explicit(lck, memory_order_acquire)) - optional_pause(); - - } while (atomic_exchange_explicit(lck, 1, memory_order_acq_rel)); -} - -/** - * Unlock a spinlock. - * - * @param lck Pointer to lock. - */ -static inline void spin_unlock(spinlock_t *lck) -{ - atomic_store_explicit(lck, 0, memory_order_release); - enable_irq(); -} - -#endif /* APOS_LOCK_H */ |
