summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_shared_memory_info.h
blob: bf97a018418e37b6fe80c1ef1fcfc57496779336 (plain) (blame)
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
// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <memory>
#include <string>

#include <boost/intrusive/list.hpp>

#include "common/assert.h"
#include "core/hle/kernel/slab_helpers.h"

namespace Kernel {

class KSharedMemory;

class KSharedMemoryInfo final : public KSlabAllocated<KSharedMemoryInfo>,
                                public boost::intrusive::list_base_hook<> {

public:
    explicit KSharedMemoryInfo() = default;

    constexpr void Initialize(KSharedMemory* shmem) {
        shared_memory = shmem;
    }

    constexpr KSharedMemory* GetSharedMemory() const {
        return shared_memory;
    }

    constexpr void Open() {
        ++reference_count;
    }

    constexpr bool Close() {
        return (--reference_count) == 0;
    }

private:
    KSharedMemory* shared_memory{};
    size_t reference_count{};
};

} // namespace Kernel