ladybird/Kernel/ProcessGroup.h
Andreas Kling 11eee67b85 Kernel: Make self-contained locking smart pointers their own classes
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.
2022-08-20 17:20:43 +02:00

48 lines
1.1 KiB
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/IntrusiveList.h>
#include <Kernel/Library/LockWeakable.h>
#include <Kernel/Locking/SpinlockProtected.h>
#include <Kernel/UnixTypes.h>
namespace Kernel {
class ProcessGroup
: public AtomicRefCounted<ProcessGroup>
, public LockWeakable<ProcessGroup> {
AK_MAKE_NONMOVABLE(ProcessGroup);
AK_MAKE_NONCOPYABLE(ProcessGroup);
public:
~ProcessGroup();
static ErrorOr<NonnullLockRefPtr<ProcessGroup>> try_create(ProcessGroupID);
static ErrorOr<NonnullLockRefPtr<ProcessGroup>> try_find_or_create(ProcessGroupID);
static LockRefPtr<ProcessGroup> from_pgid(ProcessGroupID);
ProcessGroupID const& pgid() const { return m_pgid; }
private:
ProcessGroup(ProcessGroupID pgid)
: m_pgid(pgid)
{
}
IntrusiveListNode<ProcessGroup> m_list_node;
ProcessGroupID m_pgid;
public:
using List = IntrusiveList<&ProcessGroup::m_list_node>;
};
SpinlockProtected<ProcessGroup::List>& process_groups();
}