From 6bd5da92c5119fb5daf2ad1b384cb424d92efaf5 Mon Sep 17 00:00:00 2001 From: JJ Roberts-White Date: Fri, 22 Oct 2021 16:45:09 +1100 Subject: [PATCH] Kernel: SIGALARM --- Kernel/include/Objects/Process.h | 22 ++++++++++++++++++++++ Kernel/include/TimerEvent.h | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Kernel/include/Objects/Process.h b/Kernel/include/Objects/Process.h index c8a55aff..f3da069e 100644 --- a/Kernel/include/Objects/Process.h +++ b/Kernel/include/Objects/Process.h @@ -15,6 +15,7 @@ #include #include #include +#include #include class Process : public KernelObject { @@ -352,6 +353,24 @@ class Process : public KernelObject { goto retry; // Keep waiting } + ALWAYS_INLINE void SetAlarm(unsigned int seconds) { + ScopedSpinLock lockProcess(m_processLock); + + if (seconds == 0) { + m_alarmEvent = nullptr; + return; + } + + m_alarmEvent = new Timer::TimerEvent( + seconds * 1000000, + [](void* thread) { + Thread* t = reinterpret_cast(thread); + + t->Signal(SIGALRM); + }, + m_mainThread.get()); + } + char name[NAME_MAX + 1]; char workingDir[PATH_MAX + 1]; @@ -426,5 +445,8 @@ class Process : public KernelObject { // Watcher objects watching the process List m_watching; + // Used for SIGALARM + FancyRefPtr m_alarmEvent = nullptr; + Process* m_parent = nullptr; }; diff --git a/Kernel/include/TimerEvent.h b/Kernel/include/TimerEvent.h index 137b3243..7b01b62d 100644 --- a/Kernel/include/TimerEvent.h +++ b/Kernel/include/TimerEvent.h @@ -34,4 +34,4 @@ namespace Timer{ __attribute__((always_inline)) inline void Lock() { acquireLock(&lock); } __attribute__((always_inline)) inline void Unlock() { releaseLock(&lock); } }; -} \ No newline at end of file +}