ladybird/Kernel/ProcessGroup.cpp
Andreas Kling b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00

52 lines
1.1 KiB
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ProcessGroup.h"
namespace Kernel {
RecursiveSpinLock g_process_groups_lock;
InlineLinkedList<ProcessGroup>* g_process_groups;
ProcessGroup::~ProcessGroup()
{
ScopedSpinLock lock(g_process_groups_lock);
g_process_groups->remove(this);
}
NonnullRefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid)
{
auto process_group = adopt_ref(*new ProcessGroup(pgid));
{
ScopedSpinLock lock(g_process_groups_lock);
g_process_groups->prepend(process_group);
}
return process_group;
}
NonnullRefPtr<ProcessGroup> ProcessGroup::find_or_create(ProcessGroupID pgid)
{
ScopedSpinLock lock(g_process_groups_lock);
if (auto existing = from_pgid(pgid))
return existing.release_nonnull();
return create(pgid);
}
RefPtr<ProcessGroup> ProcessGroup::from_pgid(ProcessGroupID pgid)
{
ScopedSpinLock lock(g_process_groups_lock);
for (auto& group : *g_process_groups) {
if (group.pgid() == pgid)
return &group;
}
return nullptr;
}
}