aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/process.h
blob: d46fd2f5eae25092411e3ba6cc913be691c98cb3 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44

#pragma once

// Kpl threads, allocators, atomic queues and garbage collection

#include "kpl/macro.h"

typedef struct {
    int32_t count;
} kpl_config_thread;

typedef struct _kpl_task kpl_task;

typedef struct _kpl_env kpl_env;

typedef void kpl_task_fn(kpl_task *task, kpl_env *env);

typedef struct _kpl_task {
    struct _kpl_task *_Atomic next, *join;
    // TODO
    kpl_result result;
    int32_t thread_id;
    _Atomic bool join_ready;
} kpl_task;

typedef struct {
    kpl_task *_Atomic head, *_Atomic tail;
    struct {
       kpl_task *_Atomic next;
    } dummy;
} kpl_task_queue;

typedef struct {
    kpl_task_queue task_queue;
    _Atomic ssize_t priority;
    // TODO
    sem_t spin_counter;
    pthread_t thread;
} kpl_thread;

typedef struct {
    _Atomic ssize_t total_priority;
    kpl_thread *threads;
} kpl_process;