Trying to improve threading, thread queue
This commit is contained in:
30
src/basic/thread_queue.h
Normal file
30
src/basic/thread_queue.h
Normal 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);
|
||||
Reference in New Issue
Block a user