2020-08-15 23:43:19 +04:30
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-15 23:43:19 +04:30
|
|
|
*/
|
|
|
|
|
|
|
|
#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(*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)
|
|
|
|
{
|
2020-11-29 16:05:27 -07:00
|
|
|
ScopedSpinLock lock(g_process_groups_lock);
|
|
|
|
|
2020-08-15 23:43:19 +04:30
|
|
|
if (auto existing = from_pgid(pgid))
|
2020-11-29 16:05:27 -07:00
|
|
|
return existing.release_nonnull();
|
2020-08-15 23:43:19 +04:30
|
|
|
|
|
|
|
return create(pgid);
|
|
|
|
}
|
|
|
|
|
2020-11-29 16:05:27 -07:00
|
|
|
RefPtr<ProcessGroup> ProcessGroup::from_pgid(ProcessGroupID pgid)
|
2020-08-15 23:43:19 +04:30
|
|
|
{
|
|
|
|
ScopedSpinLock lock(g_process_groups_lock);
|
|
|
|
|
|
|
|
for (auto& group : *g_process_groups) {
|
|
|
|
if (group.pgid() == pgid)
|
|
|
|
return &group;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|