mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-30 03:20:28 +00:00
066b0590ec
This change adds a static lock hierarchy / ranking to the Kernel with the goal of reducing / finding deadlocks when running with SMP enabled. We have seen quite a few lock ordering deadlocks (locks taken in a different order, on two different code paths). As we properly annotate locks in the system, then these facilities will find these locking protocol violations automatically The `LockRank` enum documents the various locks in the system and their rank. The implementation guarantees that a thread holding one or more locks of a lower rank cannot acquire an additional lock with rank that is greater or equal to any of the currently held locks.
29 lines
666 B
C++
29 lines
666 B
C++
/*
|
|
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <Kernel/Locking/LockRank.h>
|
|
#include <Kernel/Thread.h>
|
|
|
|
// Note: These stubs can't be in LockRank.h as that would create
|
|
// a cyclic dependency in the header include graph of the Kernel.
|
|
|
|
namespace Kernel {
|
|
|
|
void track_lock_acquire(LockRank rank)
|
|
{
|
|
auto thread = Thread::current();
|
|
if (thread && !thread->is_crashing())
|
|
thread->track_lock_acquire(rank);
|
|
}
|
|
|
|
void track_lock_release(LockRank rank)
|
|
{
|
|
auto thread = Thread::current();
|
|
if (thread && !thread->is_crashing())
|
|
thread->track_lock_release(rank);
|
|
}
|
|
|
|
}
|