mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
e95eb7a51d
Avoid allocating while holding the g_process_groups_lock spinlock, it's a pattern that has a negative effect on performance and scalability, especially given that it is a global lock, reachable by all processes.
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
/*
|
|
* 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;
|
|
|
|
}
|