From 6c18b4e5582b390e346e58be4faaf7612da48690 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sat, 7 Aug 2021 04:17:03 -0700 Subject: [PATCH] Kernel: Introduce LockLocation abstraction from SourceLocation Introduce a zero sized type to represent a SourceLocation, when we don't want to compile with SourceLocation support. --- Kernel/Locking/LockLocation.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Kernel/Locking/LockLocation.h diff --git a/Kernel/Locking/LockLocation.h b/Kernel/Locking/LockLocation.h new file mode 100644 index 0000000000..a0fcf7d9a1 --- /dev/null +++ b/Kernel/Locking/LockLocation.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021, Brian Gianforcaro + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#if LOCK_DEBUG +# include +#endif + +// Abstract SourceLocation away from the kernel's locking API to avoid a +// significant amount of #ifdefs in Mutex / MutexLocker / etc. +// +// To do this we declare LockLocation to be a zero sized struct which will +// get optimized out during normal compilation. When LOCK_DEBUG is enabled, +// we forward the implementation to AK::SourceLocation and get rich debugging +// information for every caller. + +namespace Kernel { + +#if LOCK_DEBUG +using LockLocation = SourceLocation; +#else +struct LockLocation { + static constexpr LockLocation current() { return {}; } +}; +#endif + +}