PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
reaper.c
Go to the documentation of this file.
2
3#include <kernel/log/panic.h>
8#include <kernel/sync/lock.h>
9#include <kernel/sync/rcu.h>
10
14
15static void reaper_thread(void* arg)
16{
17 UNUSED(arg);
18
19 while (1)
20 {
22
26 {
28 continue;
29 }
31
32 list_t localZombies = LIST_CREATE(localZombies);
33
34 while (!list_is_empty(&zombies))
35 {
36 process_t* process = CONTAINER_OF(list_pop_front(&zombies), process_t, zombieEntry);
37
39 if (process_rcu_thread_count(process) > 0)
40 {
42 continue;
43 }
44
45 list_push_back(&localZombies, &process->zombieEntry);
46 }
48
49 while (!list_is_empty(&localZombies))
50 {
51 process_t* process = CONTAINER_OF(list_pop_front(&localZombies), process_t, zombieEntry);
52 process_remove(process);
53 UNREF(process);
54 }
55 }
56}
57
58void reaper_init(void)
59{
61 {
62 panic(NULL, "Failed to create process reaper thread");
63 }
64}
65
#define CLOCKS_NEVER
Definition clock_t.h:18
#define CONFIG_PROCESS_REAPER_INTERVAL
Process reaper interval configuration.
Definition config.h:146
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
Definition panic.c:292
void reaper_push(process_t *process)
Pushes a process to be reaped later.
Definition reaper.c:66
void reaper_init(void)
Initializes the process reaper.
Definition reaper.c:58
static uint64_t process_rcu_thread_count(process_t *process)
Gets the amount of threads in a process.
Definition process.h:219
void process_remove(process_t *process)
Removes a process from the system.
Definition process.c:284
clock_t clock_uptime(void)
Retrieve the time in nanoseconds since boot.
Definition clock.c:99
tid_t thread_kernel_create(thread_kernel_entry_t entry, void *arg)
Creates a new thread that runs in kernel mode and submits it to the scheduler.
Definition thread.c:126
uint64_t sched_nanosleep(clock_t timeout)
Sleeps the current thread for a specified duration in nanoseconds.
Definition sched.c:628
#define LOCK_CREATE()
Create a lock initializer.
Definition lock.h:69
static void lock_release(lock_t *lock)
Releases a lock.
Definition lock.h:175
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
Definition lock.h:96
#define RCU_READ_SCOPE()
RCU read-side critical section for the current scope.
Definition rcu.h:94
#define REF(ptr)
Increment reference count.
Definition ref.h:82
#define UNREF(ptr)
Decrement reference count.
Definition ref.h:109
#define UNUSED(x)
Mark a variable as unused.
Definition defs.h:96
static void list_push_back(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
Definition list.h:322
#define LIST_CREATE(name)
Creates a list initializer.
Definition list.h:163
static bool list_is_empty(list_t *list)
Checks if a list is empty.
Definition list.h:210
static list_entry_t * list_pop_front(list_t *list)
Pops the first entry from the list.
Definition list.h:366
clock_t uptime(void)
System call for retreving the time since boot.
Definition uptime.c:6
#define NULL
Pointer error value.
Definition NULL.h:25
#define ERR
Integer error value.
Definition ERR.h:17
#define CONTAINER_OF(ptr, type, member)
Container of macro.
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
static clock_t nextReaperTime
Definition reaper.c:12
static list_t zombies
Definition reaper.c:11
static lock_t reaperLock
Definition reaper.c:13
static void reaper_thread(void *arg)
Definition reaper.c:15
A doubly linked list.
Definition list.h:46
A simple ticket lock implementation.
Definition lock.h:44
Process structure.
Definition process.h:76
list_entry_t zombieEntry
Definition process.h:80