aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/process.h
blob: b47e122756abe828e67ee1da4636babd3e36aef5 (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
45
46
47
48
49
50

#pragma once

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

#include "kpl/queue.h"

typedef enum : int8_t {
    KPL_CONFIG_THREAD_COUNT_AFFINITY    = -1,
    KPL_CONFIG_THREAD_COUNT_MAX         = 127
} kpl_config_thread_count;

typedef enum : uint8_t {
    KPL_CONFIG_THREAD_RING_POOL_COUNT                   = 28,
    KPL_CONFIG_THREAD_RING_POOL_MIN_OBJECT_SIZE_POW2    = 5,
    KPL_CONFIG_THREAD_RING_POOL_MAX_OBJECT_SIZE_POW2    = 27,
    KPL_CONFIG_THREAD_RING_POOL_MIN_RING_SIZE_POW2      = 6,
    KPL_CONFIG_THREAD_RING_POOL_MAX_RING_SIZE_POW2      = 20
} kpl_config_thread_ring_pool;

typedef struct {
    int8_t count, ring_pool_entries_pow2[KPL_CONFIG_THREAD_RING_POOL_COUNT];
} kpl_config_thread;

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_queue task_queue;
    _Atomic ssize_t priority;
    // TODO
    sem_t sem;
    pthread_t pthread;
} kpl_thread;

typedef struct {
    kpl_config_thread *config_thread;
    _Atomic ssize_t total_priority;
    kpl_thread *threads;
    kpl_ring_queue memory_pool[KPL_CONFIG_THREAD_RING_POOL_COUNT];
} kpl_process;