From c64ccd86eecaab00d784f4a10408b2c0c237a613 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Tue, 21 Jan 2020 00:05:01 +0000 Subject: [PATCH] thermosphere: uninline recursive lock funcs --- thermosphere/src/breakpoints.c | 2 +- thermosphere/src/spinlock.c | 37 +++++++++++++++++++ thermosphere/src/spinlock.h | 22 +---------- .../src/{spinlock.s => spinlock_impl.s} | 0 thermosphere/src/watchpoints.c | 3 +- 5 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 thermosphere/src/spinlock.c rename thermosphere/src/{spinlock.s => spinlock_impl.s} (100%) diff --git a/thermosphere/src/breakpoints.c b/thermosphere/src/breakpoints.c index ff8ac5f09..5dd8a8b9d 100644 --- a/thermosphere/src/breakpoints.c +++ b/thermosphere/src/breakpoints.c @@ -18,7 +18,7 @@ #include "breakpoints.h" #include "breakpoints_watchpoints_load.h" #include "utils.h" -#include "sysreg.h" +#include "core_ctx.h" BreakpointManager g_breakpointManager = {0}; diff --git a/thermosphere/src/spinlock.c b/thermosphere/src/spinlock.c new file mode 100644 index 000000000..a5d34d1b3 --- /dev/null +++ b/thermosphere/src/spinlock.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "spinlock.h" +#include "core_ctx.h" + +void recursiveSpinlockLock(RecursiveSpinlock *lock) +{ + if (lock->tag != currentCoreCtx->coreId + 1) { + spinlockLock(&lock->lock); + lock->tag = currentCoreCtx->coreId + 1; + lock->count = 1; + } else { + ++lock->count; + } +} + +void recursiveSpinlockUnlock(RecursiveSpinlock *lock) +{ + if (--lock->count == 0) { + lock->tag = 0; + spinlockUnlock(&lock->lock); + } +} diff --git a/thermosphere/src/spinlock.h b/thermosphere/src/spinlock.h index 1f71cc52f..4afb2d228 100644 --- a/thermosphere/src/spinlock.h +++ b/thermosphere/src/spinlock.h @@ -16,7 +16,6 @@ #pragma once -#include "core_ctx.h" #include "utils.h" #include "sysreg.h" @@ -51,6 +50,8 @@ static inline void restoreInterruptFlags(u64 flags) void spinlockLock(Spinlock *lock); void spinlockUnlock(Spinlock *lock); +void recursiveSpinlockLock(RecursiveSpinlock *lock); +void recursiveSpinlockUnlock(RecursiveSpinlock *lock); static inline u64 spinlockLockMaskIrq(Spinlock *lock) { @@ -65,25 +66,6 @@ static inline void spinlockUnlockRestoreIrq(Spinlock *lock, u64 flags) restoreInterruptFlags(flags); } -static inline void recursiveSpinlockLock(RecursiveSpinlock *lock) -{ - if (lock->tag != currentCoreCtx->coreId + 1) { - spinlockLock(&lock->lock); - lock->tag = currentCoreCtx->coreId + 1; - lock->count = 1; - } else { - ++lock->count; - } -} - -static inline void recursiveSpinlockUnlock(RecursiveSpinlock *lock) -{ - if (--lock->count == 0) { - lock->tag = 0; - spinlockUnlock(&lock->lock); - } -} - static inline u64 recursiveSpinlockLockMaskIrq(RecursiveSpinlock *lock) { u64 ret = maskIrq(); diff --git a/thermosphere/src/spinlock.s b/thermosphere/src/spinlock_impl.s similarity index 100% rename from thermosphere/src/spinlock.s rename to thermosphere/src/spinlock_impl.s diff --git a/thermosphere/src/watchpoints.c b/thermosphere/src/watchpoints.c index 0c13b750c..6fb792376 100644 --- a/thermosphere/src/watchpoints.c +++ b/thermosphere/src/watchpoints.c @@ -18,7 +18,8 @@ #include "watchpoints.h" #include "breakpoints_watchpoints_load.h" #include "utils.h" -#include "sysreg.h" +#include "core_ctx.h" +#include "execute_function.h" #include "debug_log.h" WatchpointManager g_watchpointManager = {0};