summaryrefslogtreecommitdiff
path: root/Kernel/Locking
AgeCommit message (Collapse)Author
2021-09-05Kernel: Declare type aliases with "using" instead of "typedef"Brian Gianforcaro
This is the idiomatic way to declare type aliases in modern C++. Flagged by Sonar Cloud as a "Code Smell", but I happen to agree with this particular one. :^)
2021-08-29Kernel: Rename Spinlock::is_owned_by_current_thread()Andreas Kling
...to is_owned_by_current_processor(). As Tom pointed out, this is much more accurate. :^)
2021-08-29Kernel: {Mutex,Spinlock}::own_lock() => is_locked_by_current_thread()Andreas Kling
Rename these API's to make it more clear what they are checking.
2021-08-29Kernel: Use StringView instead of C strings in MutexAndreas Kling
2021-08-28Kernel: Verify interrupts are disabled when interacting with MutexesAndrew Kaster
This should help prevent deadlocks where a thread blocks on a Mutex while interrupts are disabled, and makes it impossible for the holder of the Mutex to make forward progress because it cannot be scheduled in. Hide it behind a new debug macro LOCK_IN_CRITICAL_DEBUG for now, because Ext2FS takes a series of Mutexes from the page fault handler, which executes with interrupts disabled.
2021-08-23Kernel: Remove unused ScopedLockRelease classAndreas Kling
2021-08-23Kernel: Convert Processor::in_irq() to static current_in_irq()Andreas Kling
This closes the race window between Processor::current() and a context switch happening before in_irq().
2021-08-22Kernel: Rename ScopedSpinlock => SpinlockLockerAndreas Kling
This matches MutexLocker, and doesn't sound like it's a lock itself.
2021-08-22Kernel: Rename SpinLock => SpinlockAndreas Kling
2021-08-22Kernel: Simplify SpinLockProtected<T>Andreas Kling
Same treatment as MutexProtected<T>: inheritance and helper class is removed, SpinLockProtected now holds a T and a SpinLock.
2021-08-22Kernel: Rename SpinLockProtectedValue<T> => SpinLockProtected<T>Andreas Kling
2021-08-22Kernel: Simplify MutexProtected<T>Andreas Kling
This patch removes the MutexContendedResource<T> helper class, and MutexProtected<T> no longer inherits from T. Instead, MutexProtected<T> simply has a T and a Mutex. The LockedResource<T, LockMode> helper class is made a private nested class in MutexProtected.
2021-08-22Kernel: Rename ProtectedValue<T> => MutexProtected<T>Andreas Kling
Let's make it obvious what we're protecting it with.
2021-08-22Kernel: Remove some unused classes from Kernel/Locking/Andreas Kling
2021-08-13Kernel: Convert lock debug APIs to east constBrian Gianforcaro
2021-08-13Kernel: Add lock debugging to ProtectedValue / RefCountedContendedBrian Gianforcaro
Enable the LOCK_DEBUG functionality for these new APIs, as it looks like we want to move the whole system to use this in the not so distant future. :^)
2021-08-13Kernel: Reduce LOCK_DEBUG ifdefs by utilizing Kernel::LockLocationBrian Gianforcaro
The LOCK_DEBUG conditional code is pretty ugly for a feature that we only use rarely. We can remove a significant amount of this code by utilizing a zero sized fake type when not building in LOCK_DEBUG mode. This lets us keep the same API, but just let the compiler optimize it away when don't actually care about the location the caller came from.
2021-08-13Kernel: Introduce LockLocation abstraction from SourceLocationBrian Gianforcaro
Introduce a zero sized type to represent a SourceLocation, when we don't want to compile with SourceLocation support.
2021-08-11Kernel/SMP: Fix RecursiveSpinLock remembering the wrong CPU when lockingAndreas Kling
We have to disable interrupts before capturing the current Processor*, or we risk storing the wrong one if we get preempted and resume on a different CPU. Caught by the VERIFY in RecursiveSpinLock::unlock()
2021-08-10Kernel/SMP: Change critical sections to not disable interruptsAndreas Kling
Leave interrupts enabled so that we can still process IRQs. Critical sections should only prevent preemption by another thread. Co-authored-by: Tom <tomut@yahoo.com>
2021-08-10Kernel/SMP: Make entering/leaving critical sections multi-processor safeAndreas Kling
By making these functions static we close a window where we could get preempted after calling Processor::current() and move to another processor. Co-authored-by: Tom <tomut@yahoo.com>
2021-08-07Kernel: Introduce ProtectedValueJean-Baptiste Boric
A protected value is a variable with enforced locking semantics. The value is protected with a Mutex and can only be accessed through a Locked object that holds a MutexLocker to said Mutex. Therefore, the value itself cannot be accessed except through the proper locking mechanism, which enforces correct locking semantics. The Locked object has knowledge of shared and exclusive lock types and will only return const-correct references and pointers. This should help catch incorrect locking usage where a shared lock is acquired but the user then modifies the locked value. This is not a perfect solution because dereferencing the Locked object returns the value, so the caller could defeat the protected value semantics once it acquires a lock by keeping a pointer or a reference to the value around. Then again, this is C++ and we can't protect against malicious users from within the kernel anyways, but we can raise the threshold above "didn't pay attention".
2021-08-07Kernel: Implement contended, ref-counted resource frameworkJean-Baptiste Boric
This is some syntaxic sugar to use a ContendedResource object with reference counting. This effectively dissociates merely holding a reference to an object and actually using the object in a way that requires locking it against concurrent use.
2021-08-07Kernel: Introduce spin-locked contended and locked resource conceptsJean-Baptiste Boric
2021-08-07Kernel: Introduce contended and locked resource conceptsJean-Baptiste Boric
2021-08-07Kernel: Move Lockable into its own headerJean-Baptiste Boric
2021-08-07Kernel: Move SpinLock.h into Locking/Jean-Baptiste Boric
2021-08-07Kernel: Move Mutex into Locking/Jean-Baptiste Boric
2021-08-07Kernel: Move LockMode into Locking/Jean-Baptiste Boric