summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/src/SoftwareTimer.cc
blob: 167fc63084c199c83636fa6fabbe428184d7c973 (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
/* ========================================

  Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.

======================================== */

#include <KernelKit/Timer.h>

/// @brief SoftwareTimer class, meant to be generic.
///! @author Amlal El Mahrouss (amlal@nekernel.org)

using namespace Kernel;

SoftwareTimer::SoftwareTimer(Int64 seconds) : fWaitFor(seconds) {
  fDigitalTimer = new UIntPtr();
  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;
}