blob: 3a92151e518fc3f5656ba2d4f4ee61393e1b5a0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/*
* 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);
}
RefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid)
{
auto process_group = adopt_ref_if_nonnull(new ProcessGroup(pgid));
if (process_group) {
ScopedSpinLock lock(g_process_groups_lock);
g_process_groups->prepend(process_group);
}
return process_group;
}
RefPtr<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;
}
}
|