My Kernel v0.1.0
worker.h
1
46#ifndef KERNEL_WORKER_H
47#define KERNEL_WORKER_H
48
49#include <kernel/error.h>
50#include <kernel/waitqueue.h>
51
53struct worker {
54 struct thread *thread;
56 bool done;
58 void *data;
59};
60
62#define INIT_WORKER(_worker) \
63 _worker = ((struct worker){ \
64 .queue = __WAITQUEUE_INIT((_worker).queue), \
65 .done = true, \
66 .thread = NULL, \
67 })
68
70#define DECLARE_WORKER(_worker) struct worker INIT_WORKER(_worker)
71
73error_t worker_init(struct worker *);
74
76void worker_start(struct worker *, thread_entry_t, void *);
77
79void worker_wait(struct worker *);
80
82void worker_release(struct worker *);
83
85static inline bool worker_running(const struct worker *worker)
86{
87 return !worker->done;
88}
89
90#endif /* KERNEL_WORKER_H */
void(* thread_entry_t)(void *data)
A function used as an entry point when creating a new thread.
Definition: process.h:64
A single thread.
Definition: process.h:121
Waiting Queue.
Definition: waitqueue.h:39
Worker thread.
Definition: worker.h:53
void * data
Worker thread's entrypoint.
Definition: worker.h:58
thread_entry_t function
Whether the thread has finished.
Definition: worker.h:57
struct waitqueue queue
Worker thread.
Definition: worker.h:55
bool done
The processes waiting for this thread to finish.
Definition: worker.h:56