summaryrefslogtreecommitdiffhomepage
path: root/KernelKit/Semaphore.hpp
blob: 03a724c8ccaa8f8a8636f835c5fc56122a0f8f50 (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
/*
 *	========================================================
 *
 *	hCore
 * 	Copyright Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

#pragma once

#include <NewKit/Defines.hpp>
#include <CompilerKit/Compiler.hpp>

namespace hCore
{
	class Process;

    typedef Process* ProcessPtr;
	
    /// @brief Access control class, which locks a task until one is done.
    class Semaphore final
    {
    public:
        explicit Semaphore() = default;
        ~Semaphore() = default;

    public:
        bool IsLocked() const;
        bool Unlock() noexcept;

    public:
        void Sync() noexcept;

    public:
        bool Lock(Process* process);
        bool LockOrWait(Process* process, const Int64& seconds);

    public:
        HCORE_COPY_DEFAULT(Semaphore);

    private:
        ProcessPtr fLockingProcess{ nullptr };

    };
}