power_play/src/work.h
2024-02-29 16:01:51 -06:00

55 lines
1.3 KiB
C

#ifndef WORK_H
#define WORK_H
enum work_status {
WORK_STATUS_DONE,
WORK_STATUS_SCHEDULED,
WORK_STATUS_IN_PROGRESS
};
enum work_priority {
WORK_PRIORITY_HIGH,
WORK_PRIORITY_NORMAL,
NUM_WORK_PRIORITIES
};
typedef void (work_task_func)(void *data);
struct work;
struct work_task;
struct work_handle {
struct work *work;
u64 gen;
};
struct work_slate {
struct work_task *task_head;
struct work_task *task_tail;
u32 num_tasks;
};
struct worker_context {
b32 is_worker;
};
void work_startup(u32 num_worker_threads);
void work_shutdown(void);
struct work_slate work_slate_begin(void);
struct work_handle work_slate_end(struct work_slate *ws, enum work_priority priority);
struct work_handle work_slate_end_and_help(struct work_slate *ws, enum work_priority priority);
struct work_handle work_push_task(work_task_func *func, void *data, enum work_priority priority);
struct work_handle work_push_task_and_help(work_task_func *func, void *data, enum work_priority priority);
void work_slate_push_task(struct work_slate *ws, work_task_func *func, void *data);
void work_wait(struct work_handle handle);
void work_help(struct work_handle handle);
struct worker_context worker_context_alloc(void);
void worker_context_release(struct worker_context *ctx);
#endif