2019-10-21 02:02:58 +00:00
|
|
|
/*
|
|
|
|
* 4coder_async_tasks.cpp - Types for the custom layer asynchronous task system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
#if !defined(FCODER_ASYNC_TASKS_H)
|
|
|
|
#define FCODER_ASYNC_TASKS_H
|
|
|
|
|
2020-12-31 00:55:11 +00:00
|
|
|
typedef void Async_Task_Function_Type(struct Async_Context *actx, String_Const_u8 data);
|
2019-10-21 02:02:58 +00:00
|
|
|
typedef u64 Async_Task;
|
|
|
|
|
2019-10-22 04:10:29 +00:00
|
|
|
struct Async_Thread{
|
2019-10-22 05:17:24 +00:00
|
|
|
struct Async_System *async_system;
|
2019-10-22 05:53:47 +00:00
|
|
|
System_Thread thread;
|
2019-10-22 04:10:29 +00:00
|
|
|
struct Async_Node *node;
|
|
|
|
Async_Task task;
|
2019-10-22 05:17:24 +00:00
|
|
|
b32 cancel_signal;
|
2019-10-22 04:10:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Async_Node{
|
2019-10-22 05:17:24 +00:00
|
|
|
union{
|
|
|
|
Async_Node *next;
|
|
|
|
Node node;
|
|
|
|
};
|
2019-10-22 04:10:29 +00:00
|
|
|
Async_Task task;
|
|
|
|
Async_Thread *thread;
|
|
|
|
Async_Task_Function_Type *func;
|
2020-12-31 00:55:11 +00:00
|
|
|
String_Const_u8 data;
|
2019-10-22 04:10:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Async_System{
|
|
|
|
void *cmd_context;
|
|
|
|
|
|
|
|
Heap node_heap;
|
|
|
|
Arena node_arena;
|
|
|
|
System_Mutex mutex;
|
|
|
|
System_Condition_Variable cv;
|
2019-10-22 05:17:24 +00:00
|
|
|
System_Condition_Variable join_cv;
|
2019-10-22 04:10:29 +00:00
|
|
|
Async_Task task_id_counter;
|
|
|
|
Async_Node *free_nodes;
|
2019-10-22 05:17:24 +00:00
|
|
|
Node task_sent;
|
2019-10-22 04:10:29 +00:00
|
|
|
i32 task_count;
|
|
|
|
|
|
|
|
Async_Thread thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Async_Context{
|
|
|
|
Application_Links *app;
|
|
|
|
Async_Thread *thread;
|
|
|
|
};
|
|
|
|
|
2019-10-21 02:02:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|