PatchworkOS  966e257
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>
7#include <kernel/sync/lock.h>
9
13
14static void reaper_thread(void* arg)
15{
16 (void)arg;
17
18 while (1)
19 {
21
25 {
27 continue;
28 }
30
31 list_t localZombies = LIST_CREATE(localZombies);
32
33 while (!list_is_empty(&zombies))
34 {
35 process_t* process = CONTAINER_OF(list_pop_first(&zombies), process_t, zombieEntry);
36
37 lock_acquire(&process->threads.lock);
38 if (!list_is_empty(&process->threads.list))
39 {
40 lock_release(&process->threads.lock);
42 continue;
43 }
44 lock_release(&process->threads.lock);
45
46 list_push_back(&localZombies, &process->zombieEntry);
47 }
49
50 while (!list_is_empty(&localZombies))
51 {
52 process_t* process = CONTAINER_OF(list_pop_first(&localZombies), process_t, zombieEntry);
53 process_dir_deinit(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:16
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
Definition panic.c:266
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
void process_dir_deinit(process_t *process)
Deinitializes the /proc/[pid] directory of a process.
Definition process.c:867
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:94
uint64_t sched_nanosleep(clock_t timeout)
Sleeps the current thread for a specified duration in nanoseconds.
Definition sched.c:638
#define LOCK_CREATE()
Create a lock initializer.
Definition lock.h:68
static void lock_release(lock_t *lock)
Releases a lock.
Definition lock.h:146
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
Definition lock.h:103
#define CONFIG_PROCESS_REAPER_INTERVAL
Process reaper interval configuration.
Definition config.h:152
static list_entry_t * list_pop_first(list_t *list)
Pops the first entry from the list.
Definition list.h:375
static void list_push_back(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
Definition list.h:343
#define LIST_CREATE(name)
Creates a list initializer.
Definition list.h:174
static bool list_is_empty(list_t *list)
Checks if a list is empty.
Definition list.h:227
clock_t uptime(void)
System call for retreving the time since boot.
Definition uptime.c:6
#define NULL
Pointer error value.
Definition NULL.h:23
#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:11
static list_t zombies
Definition reaper.c:10
static lock_t reaperLock
Definition reaper.c:12
static void reaper_thread(void *arg)
Definition reaper.c:14
A doubly linked list.
Definition list.h:49
A simple ticket lock implementation.
Definition lock.h:43
Process structure.
Definition process.h:205
list_entry_t zombieEntry
Definition process.h:221
process_threads_t threads
Definition process.h:220