mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
11eee67b85
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Singleton.h>
|
|
#include <Kernel/ProcessGroup.h>
|
|
|
|
namespace Kernel {
|
|
|
|
static Singleton<SpinlockProtected<ProcessGroup::List>> s_process_groups;
|
|
|
|
SpinlockProtected<ProcessGroup::List>& process_groups()
|
|
{
|
|
return *s_process_groups;
|
|
}
|
|
|
|
ProcessGroup::~ProcessGroup()
|
|
{
|
|
process_groups().with([&](auto& groups) {
|
|
groups.remove(*this);
|
|
});
|
|
}
|
|
|
|
ErrorOr<NonnullLockRefPtr<ProcessGroup>> ProcessGroup::try_create(ProcessGroupID pgid)
|
|
{
|
|
auto process_group = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) ProcessGroup(pgid)));
|
|
process_groups().with([&](auto& groups) {
|
|
groups.prepend(*process_group);
|
|
});
|
|
return process_group;
|
|
}
|
|
|
|
ErrorOr<NonnullLockRefPtr<ProcessGroup>> ProcessGroup::try_find_or_create(ProcessGroupID pgid)
|
|
{
|
|
return process_groups().with([&](auto& groups) -> ErrorOr<NonnullLockRefPtr<ProcessGroup>> {
|
|
for (auto& group : groups) {
|
|
if (group.pgid() == pgid)
|
|
return group;
|
|
}
|
|
auto process_group = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) ProcessGroup(pgid)));
|
|
groups.prepend(*process_group);
|
|
return process_group;
|
|
});
|
|
}
|
|
|
|
LockRefPtr<ProcessGroup> ProcessGroup::from_pgid(ProcessGroupID pgid)
|
|
{
|
|
return process_groups().with([&](auto& groups) -> LockRefPtr<ProcessGroup> {
|
|
for (auto& group : groups) {
|
|
if (group.pgid() == pgid)
|
|
return &group;
|
|
}
|
|
return nullptr;
|
|
});
|
|
}
|
|
|
|
}
|