summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/src/SoftwareTimer.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-26 18:15:54 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-26 18:15:54 +0100
commitc0f7f3f300d603d355fc7ec5be317afe1f0ee1b6 (patch)
tree87189340d1b6f36474c52c0cf951310862fe9db7 /dev/Kernel/src/SoftwareTimer.cc
parent4ed658c633ce5d7c5bde4acdbe322e5f51592369 (diff)
IMPL: Improvements and fixes.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/src/SoftwareTimer.cc')
-rw-r--r--dev/Kernel/src/SoftwareTimer.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/dev/Kernel/src/SoftwareTimer.cc b/dev/Kernel/src/SoftwareTimer.cc
new file mode 100644
index 00000000..797722d3
--- /dev/null
+++ b/dev/Kernel/src/SoftwareTimer.cc
@@ -0,0 +1,39 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024, Theater Quality Inc, all rights reserved.
+
+------------------------------------------- */
+
+#include <KernelKit/Timer.h>
+
+/// @brief SoftwareTimer class, meant to be generic.
+
+using namespace Kernel;
+
+SoftwareTimer::SoftwareTimer(Int64 seconds)
+ : fWaitFor(seconds)
+{
+ fDigitalTimer = new IntPtr();
+ MUST_PASS(fDigitalTimer);
+}
+
+SoftwareTimer::~SoftwareTimer()
+{
+ delete fDigitalTimer;
+ fDigitalTimer = nullptr;
+
+ fWaitFor = 0;
+}
+
+BOOL SoftwareTimer::Wait() noexcept
+{
+ if (fWaitFor < 1)
+ return NO;
+
+ while (*fDigitalTimer < (*fDigitalTimer + fWaitFor))
+ {
+ ++(*fDigitalTimer);
+ }
+
+ return YES;
+}