summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKAKit/src/Timer.cc
blob: 8795dd66ba9a58c04d19e14dc3c7651f1ebbb396 (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
47
/* -------------------------------------------

	Copyright (C) 2024, Theater Quality Inc, all rights reserved.

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

#include <KernelKit/Timer.h>

///! BUGS: 0
///! @file Timer.cc
///! @brief Software Timer implementation

using namespace Kernel;

/// @brief Unimplemented as it is an interface.
Int32 TimerInterface::Wait() noexcept
{
	return kErrorUnimplemented;
}

/// @brief SoftwareTimer class, meant to be generic.

SoftwareTimer::SoftwareTimer(Int64 seconds)
	: fWaitFor(seconds)
{
	fDigitalTimer = new IntPtr();
	MUST_PASS(fDigitalTimer);
}

SoftwareTimer::~SoftwareTimer()
{
	delete fDigitalTimer;
	fWaitFor = 0;
}

Int32 SoftwareTimer::Wait() noexcept
{
	if (fWaitFor < 1)
		return 1;

	while (*fDigitalTimer < (*fDigitalTimer + fWaitFor))
	{
		++(*fDigitalTimer);
	}

	return 0;
}