summaryrefslogtreecommitdiff
path: root/docs/application
diff options
context:
space:
mode:
Diffstat (limited to 'docs/application')
-rw-r--r--docs/application/thread.md44
1 files changed, 27 insertions, 17 deletions
diff --git a/docs/application/thread.md b/docs/application/thread.md
index b3f8d21..59654e7 100644
--- a/docs/application/thread.md
+++ b/docs/application/thread.md
@@ -5,18 +5,18 @@
## Object Definitions
```c
-typedef struct _kpl_task kpl_task;
+typedef struct __kpl_task kpl_task;
typedef void kpl_task_fn(kpl_task *t);
typedef struct _kpl_task {
- _Atomic bool join_ready;
- int32_t thread_id;
- kpl_group *state;
- kpl_result ret;
kpl_task *_Atomic next, *join;
- task_fn *fn;
-} kpl_task;
+ kpl_group *state;
+ kpl_result return_value;
+ kpl_task_fn *fn;
+ int32_t thread_id;
+ _Atomic bool join_ready;
+} task;
#define KPL_TASK_SLAB_SIZE 50
@@ -31,7 +31,12 @@ typedef struct _kpl_task_slab {
#define KPL_MAIN_THREAD 0
typedef struct {
- kpl_task *_Atomic head, *_Atomic tail, dummy;
+ kpl_task *_Atomic next;
+} kpl_task_dummy;
+
+typedef struct {
+ kpl_task *_Atomic head, *_Atomic tail;
+ kpl_task_dummy dummy;
} kpl_atomic_queue;
typedef struct {
@@ -96,12 +101,12 @@ typedef void task_fn(task *t);
#define TASK_STATE_SIZE 55
typedef struct _task {
- _Atomic bool join_ready;
- int32_t thread_id;
+ task *_Atomic next, *join;
void *state[TASK_STATE_SIZE];
void *return_value;
- task *_Atomic next, *join;
task_fn *fn;
+ int32_t thread_id;
+ _Atomic bool join_ready;
} task;
#define TASK_SLAB_SIZE 50
@@ -117,7 +122,12 @@ typedef struct _task_slab {
#define MAIN_THREAD 0
typedef struct {
- task *_Atomic head, *_Atomic tail, dummy;
+ task *_Atomic next;
+} task_dummy;
+
+typedef struct {
+ task *_Atomic head, *_Atomic tail;
+ task_dummy dummy;
} atomic_queue;
typedef struct {
@@ -170,8 +180,8 @@ void task_slab_free(int32_t thread_id) {
}
void task_queue_init(int32_t thread_id) {
- threads[thread_id].queue.head = &threads[thread_id].queue.dummy;
- threads[thread_id].queue.tail = &threads[thread_id].queue.dummy;
+ threads[thread_id].queue.head = (task*) &threads[thread_id].queue.dummy;
+ threads[thread_id].queue.tail = (task*) &threads[thread_id].queue.dummy;
threads[thread_id].queue.dummy.next = NULL;
threads[thread_id].priority = 1;
threads[thread_id].pool = NULL;
@@ -181,7 +191,7 @@ void task_queue_add(int32_t thread_id, task *t) {
t->next = NULL;
task *head = __atomic_exchange_n(&threads[thread_id].queue.head, t, __ATOMIC_SEQ_CST);
head->next = t;
- if (t != &threads[thread_id].queue.dummy)
+ if (t != (task*) &threads[thread_id].queue.dummy)
priority_increment(thread_id);
}
@@ -189,7 +199,7 @@ task *task_queue_next(int32_t thread_id) {
task *t = NULL;
for (;;) {
task *tail = threads[thread_id].queue.tail, *next = tail->next;
- if (tail == &threads[thread_id].queue.dummy) {
+ if (tail == (task*) &threads[thread_id].queue.dummy) {
if (!next)
break;
threads[thread_id].queue.tail = next;
@@ -204,7 +214,7 @@ task *task_queue_next(int32_t thread_id) {
task *head = threads[thread_id].queue.head;
if (tail != head)
continue;
- task_queue_add(thread_id, &threads[thread_id].queue.dummy);
+ task_queue_add(thread_id, (task*) &threads[thread_id].queue.dummy);
next = tail->next;
if (next) {
threads[thread_id].queue.tail = next;