Trying to improve threading, thread queue

This commit is contained in:
Krzosa Karol
2024-07-06 07:55:38 +02:00
parent 30fa22aed5
commit e3a176b2f9
6 changed files with 201 additions and 108 deletions

30
src/basic/thread_queue.h Normal file
View File

@@ -0,0 +1,30 @@
#define WORK_FUNCTION(name) void name(void *data)
typedef WORK_FUNCTION(WorkQueueCallback);
struct WorkQueueEntry {
WorkQueueCallback *callback;
void *data;
};
struct ThreadCtx {
int thread_index;
};
struct WorkQueue {
WorkQueueEntry entries[256];
int64_t volatile index_to_write;
int64_t volatile index_to_read;
int64_t volatile completion_index;
int64_t volatile completion_goal;
void *semaphore;
};
struct ThreadStartupInfo {
uint32_t thread_id;
int32_t thread_index;
WorkQueue *queue;
};
void PushWork(WorkQueue *wq, void *data, WorkQueueCallback *callback);
void InitWorkQueue(WorkQueue *queue, uint32_t thread_count, ThreadStartupInfo *info);
void WaitUntilCompletion(WorkQueue *wq);