forked from laysakura/Lock-free_work-stealing_deque_in_C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsoc_taskqueue.h
31 lines (22 loc) · 1.2 KB
/
gsoc_taskqueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* Implemented after Chapter 16 of "The Art of Multiprocessor Programming"
This is lock-free work stealing deque. */
#ifndef _GSOC_TASKQUEUE_H_
#define _GSOC_TASKQUEUE_H_
#include "gsoc_task_circular_array.h"
/* Constants */
#define GSOC_TASKQUEUE_INIT_SIZE 131072 /* just same as MassiveThreads */
typedef struct _gsoc_taskqueue {
gsoc_task_circular_array* _taskqueue; /* array of gsoc_task* */
volatile size_t _top; /* task is taken from _top of _taskqueue.
_top is only incremented atomically and never decremented.
It is checked by CAS when a task is poped/taken while
there exist few tasks in _taskqueue. */
volatile size_t _bottom; /* task is pushed in _bottom of _taskqueue. */
} gsoc_taskqueue;
/* Methods for gsoc_taskqueue */
gsoc_taskqueue* gsoc_taskqueue_new(); /* constructor, initializer */
void gsoc_taskqueue_delete(gsoc_taskqueue* this); /* destructor */
void gsoc_taskqueue_push(gsoc_taskqueue* this, gsoc_task* task);
gsoc_task* gsoc_taskqueue_pop(gsoc_taskqueue* this);
gsoc_task* gsoc_taskqueue_take(gsoc_taskqueue* this);
#endif /* _GSOC_TASKQUEUE_H_ */