summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/KernelKit/Semaphore.h
blob: 11e04b900d4ca59f4c81ff415fcb75cbe15322ea (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
/* -------------------------------------------

	Copyright (C) 2024, t& Corporation, all rights reserved.

------------------------------------------- */

#pragma once

#include <NewKit/Defines.h>
#include <KernelKit/Timer.h>
#include <CompilerKit/CompilerKit.h>

namespace Kernel
{
	class UserThread;

	typedef UserThread& UserProcessRef;

	/// @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 WaitForProcess() noexcept;

	public:
		bool Lock(UserThread& process);
		bool LockOrWait(UserThread& process, TimerInterface* timer);

	public:
		ZKA_COPY_DEFAULT(Semaphore);

	private:
		UserProcessRef fLockingProcess;
	};
} // namespace Kernel