aboutsummaryrefslogtreecommitdiff
path: root/include/kpl/process.h
blob: 528365a03febd993aa6252c03ac8ebc5b8b2b078 (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

#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 {
    int32_t thread_id;
    _Atomic ssize_t priority;
    kpl_env *env;
    kpl_task_queue task_queue;
    // TODO
    sem_t sem;
    pthread_t pthread;
} kpl_thread;

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