Voxia OS
v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1
#ifndef __PROCC__THREAD_H__
2
#define __PROCC__THREAD_H__
3
4
#include "autoconf.h"
5
#include <
register.h
>
6
#include <
spinlock.h
>
7
8
#ifdef __cplusplus
9
extern
"C"
{
10
#endif
11
12
typedef
uint64_t
thread_id
;
13
14
enum
{
15
THREAD_USER
= (1 << 0),
16
THREAD_KERNEL
= ~(1 << 0),
17
THREAD_PREEMPT_ENABLE
= (1 << 1),
18
THREAD_PREEMPT_DISABLE
= ~(1 << 1)
19
};
20
21
enum
{
22
THREAD_STATE_CREATE
= 0,
23
THREAD_STATE_READY
= 1,
24
THREAD_STATE_RUNNING
= 2,
25
THREAD_STATE_HAL
= 3,
26
THREAD_STATE_TERMINATED
= 3,
27
};
28
29
typedef
struct
thread
thread_t
;
30
struct
thread
{
31
// --- Cache line 1 (scheduler hot path) ---
32
thread_id
id
;
// 4B
33
uint16_t
core_affinity
;
// 2B
34
uint8_t
state
;
// 1B
35
uint8_t
priority
;
// 1B
36
uint16_t
flags
;
// 2B
37
uint64_t
last_run_time
;
// 8B profiling
38
uint32_t
uuid
;
39
boolean_t
has_update_run_time
;
40
uint8_t
_pad1
[64 - 29];
// align ke 64B (cache line 1 penuh)
41
42
// --- Cache line 2–4 (context, jarang diakses) ---
43
uintptr_t
entry_addr
;
// 8B
44
uint64_t
stack
;
// 8B
45
cpu_register_t
reg
;
// 128–160B
46
}
__attribute__
((aligned(64)));
47
48
typedef
struct
{
49
thread_t
*
thread
;
50
uint32_t
gen
;
51
boolean_t
used
;
52
}
thread_slot_t
;
53
54
typedef
struct
thread_bucket
{
55
thread_slot_t
slot
[VOXIA_MAX_NUMBER_THREAD];
56
spinlock_t
lock
;
57
uint32_t
top_free
;
58
}
thread_bucket_t
;
59
60
#define THREAD_MAKE_ID(id, gen) ((uint64_t) (gen) << 32 | ((uint64_t) (id) + 1))
61
#define THREAD_GET_ID(thread_id) ((uint32_t) ((thread_id) & 0xFFFFFFFFULL) - 1)
62
#define THREAD_GET_GEN(thread_id) ((uint32_t) ((thread_id) >> 32))
63
64
thread_id
vxCreateThread
(
const
uintptr_t
entry,
uint16_t
core_affinity
,
65
uint8_t
priority
,
uint16_t
flags
);
66
void
vxThreadExit
();
67
68
#ifdef __cplusplus
69
}
70
#endif
71
72
#endif
// __PROCC__THREAD_H__
vxThreadExit
void vxThreadExit()
Definition
thread.c:70
THREAD_PREEMPT_ENABLE
@ THREAD_PREEMPT_ENABLE
Definition
thread.h:17
THREAD_USER
@ THREAD_USER
Definition
thread.h:15
THREAD_PREEMPT_DISABLE
@ THREAD_PREEMPT_DISABLE
Definition
thread.h:18
THREAD_KERNEL
@ THREAD_KERNEL
Definition
thread.h:16
vxCreateThread
thread_id vxCreateThread(const uintptr_t entry, uint16_t core_affinity, uint8_t priority, uint16_t flags)
priority
uint8_t priority
Definition
thread.h:4
thread_t
struct thread thread_t
Definition
thread.h:29
flags
uint16_t flags
Definition
thread.h:5
THREAD_STATE_READY
@ THREAD_STATE_READY
Definition
thread.h:23
THREAD_STATE_TERMINATED
@ THREAD_STATE_TERMINATED
Definition
thread.h:26
THREAD_STATE_RUNNING
@ THREAD_STATE_RUNNING
Definition
thread.h:24
THREAD_STATE_CREATE
@ THREAD_STATE_CREATE
Definition
thread.h:22
THREAD_STATE_HAL
@ THREAD_STATE_HAL
Definition
thread.h:25
__attribute__
typedef __attribute__
Definition
msi.c:47
thread_id
uint64_t thread_id
Definition
thread.h:12
core_affinity
uint16_t core_affinity
Definition
thread.h:2
thread_bucket_t
struct thread_bucket thread_bucket_t
register.h
spinlock.h
spinlock_t
Definition
spinlock.h:10
thread_bucket
Definition
thread.h:54
thread_bucket::lock
spinlock_t lock
Definition
thread.h:56
thread_bucket::slot
thread_slot_t slot[VOXIA_MAX_NUMBER_THREAD]
Definition
thread.h:55
thread_bucket::top_free
uint32_t top_free
Definition
thread.h:57
thread_slot_t
Definition
thread.h:48
thread_slot_t::thread
thread_t * thread
Definition
thread.h:49
thread_slot_t::gen
uint32_t gen
Definition
thread.h:50
thread_slot_t::used
boolean_t used
Definition
thread.h:51
thread
Definition
thread.h:30
thread::_pad1
uint8_t _pad1[64 - 29]
Definition
thread.h:40
thread::has_update_run_time
boolean_t has_update_run_time
Definition
thread.h:39
thread::core_affinity
uint16_t core_affinity
Definition
thread.h:33
thread::last_run_time
uint64_t last_run_time
Definition
thread.h:37
thread::flags
uint16_t flags
Definition
thread.h:36
thread::stack
uint64_t stack
Definition
thread.h:44
thread::reg
cpu_register_t reg
Definition
thread.h:45
thread::priority
uint8_t priority
Definition
thread.h:35
thread::id
thread_id id
Definition
thread.h:32
thread::uuid
uint32_t uuid
Definition
thread.h:38
thread::state
uint8_t state
Definition
thread.h:34
thread::entry_addr
uintptr_t entry_addr
Definition
thread.h:43
uint16_t
unsigned short uint16_t
Definition
type.h:13
uint32_t
unsigned int uint32_t
Definition
type.h:19
boolean_t
uint8_t boolean_t
Definition
type.h:89
uintptr_t
unsigned long uintptr_t
Definition
type.h:73
uint64_t
unsigned long uint64_t
Definition
type.h:25
uint8_t
unsigned char uint8_t
Definition
type.h:7
include
procc
thread.h
Generated on Sat May 30 2026 11:09:57 for Voxia OS by
1.13.2