Skip to content

Commit

Permalink
Kernel: SIGALARM
Browse files Browse the repository at this point in the history
  • Loading branch information
fido2020 committed Oct 22, 2021
1 parent 09ade0d commit 6bd5da9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Kernel/include/Objects/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <RefPtr.h>
#include <System.h>
#include <Thread.h>
#include <TimerEvent.h>
#include <Vector.h>

class Process : public KernelObject {
Expand Down Expand Up @@ -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*>(thread);

t->Signal(SIGALRM);
},
m_mainThread.get());
}

char name[NAME_MAX + 1];
char workingDir[PATH_MAX + 1];

Expand Down Expand Up @@ -426,5 +445,8 @@ class Process : public KernelObject {
// Watcher objects watching the process
List<KernelObjectWatcher*> m_watching;

// Used for SIGALARM
FancyRefPtr<Timer::TimerEvent> m_alarmEvent = nullptr;

Process* m_parent = nullptr;
};
2 changes: 1 addition & 1 deletion Kernel/include/TimerEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ namespace Timer{
__attribute__((always_inline)) inline void Lock() { acquireLock(&lock); }
__attribute__((always_inline)) inline void Unlock() { releaseLock(&lock); }
};
}
}

0 comments on commit 6bd5da9

Please sign in to comment.