summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/Sources/Timer.cxx
blob: 7a5ebd8d4f2839454ca3aff37b184aef4f96bfa4 (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
48
/* -------------------------------------------

	Copyright ZKA Technologies.

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

#include <KernelKit/Timer.hxx>

///! BUGS: 0
///! @file Timer.cxx
///! @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;
}