summaryrefslogtreecommitdiff
path: root/Kernel/ProcessGroup.h
blob: fac329f1ec46fc4c4102c1b0cf08cf101976dd9c (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
53
54
/*
 * Copyright (c) 2020, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/InlineLinkedList.h>
#include <AK/RefCounted.h>
#include <AK/Weakable.h>
#include <Kernel/Lock.h>
#include <Kernel/SpinLock.h>
#include <Kernel/UnixTypes.h>

namespace Kernel {

class ProcessGroup
    : public RefCounted<ProcessGroup>
    , public Weakable<ProcessGroup>
    , public InlineLinkedListNode<ProcessGroup> {

    AK_MAKE_NONMOVABLE(ProcessGroup);
    AK_MAKE_NONCOPYABLE(ProcessGroup);

    friend InlineLinkedListNode<ProcessGroup>;

public:
    ~ProcessGroup();

    static RefPtr<ProcessGroup> create(ProcessGroupID);
    static RefPtr<ProcessGroup> find_or_create(ProcessGroupID);
    static RefPtr<ProcessGroup> from_pgid(ProcessGroupID);

    const ProcessGroupID& pgid() const { return m_pgid; }

private:
    ProcessGroup(ProcessGroupID pgid)
        : m_pgid(pgid)
    {
    }

    static RefPtr<ProcessGroup> from_pgid_nolock(ProcessGroupID);

    ProcessGroup* m_prev { nullptr };
    ProcessGroup* m_next { nullptr };

    ProcessGroupID m_pgid;
};

extern InlineLinkedList<ProcessGroup>* g_process_groups;
extern RecursiveSpinLock g_process_groups_lock;

}