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 "
hal/cpu/register.h
"
6
#include "
procc/process.h
"
7
#include <
spinlock.h
>
8
9
typedef
uint64_t
thread_id
;
10
11
enum :
uint16_t
{
12
THREAD_USER
= (1 << 0),
13
THREAD_PREEMPT_ENABLE
= (1 << 1),
14
};
15
16
enum
{
17
THREAD_STATE_CREATE
= 0,
18
THREAD_STATE_READY
= 1,
19
THREAD_STATE_RUNNING
= 2,
20
THREAD_STATE_BLOCKED
= 3,
21
THREAD_STATE_TERMINATED
= 4,
22
THREAD_STATE_HAL
= 5,
23
};
24
25
typedef
struct
thread
thread_t
;
26
struct
thread
{
27
thread_id
id
;
28
uint16_t
core_affinity
;
29
volatile
uintptr_t
*
page
;
30
uint8_t
state
;
31
uint8_t
priority
;
32
uint16_t
flags
;
33
uint64_t
stack
;
34
uint64_t
last_run_time
;
35
boolean_t
has_update_run_time
;
36
uintptr_t
entry_addr
;
37
uint16_t
current_core_id
;
38
// 1 cache line
39
40
process_t*
process
;
41
uint32_t
*
clear_child_tid
;
42
uint32_t
uuid
;
43
uint64_t
fs_base
;
44
uint64_t
gs_base
;
45
uint8_t
_pad
[12];
46
// 1 cache line
47
48
uintptr_t
kernel_rsp
;
/* RSP saat switch keluar */
49
uintptr_t
kernel_stack_base
;
50
uintptr_t
kernel_stack_top
;
51
bool
in_kernel_sleep
;
52
bool
wake_pending
;
53
54
cpu_register_t
reg
;
55
}
__attribute__
((aligned(64)));
56
57
typedef
struct
{
58
thread_t
*
thread
;
59
uint32_t
gen;
60
boolean_t
used
;
61
}
thread_slot_t
;
62
63
typedef
struct
thread_bucket
{
64
thread_slot_t
slot
[VOXIA_MAX_NUMBER_THREAD];
65
spinlock_t
lock
;
66
uint32_t
top_free
;
67
}
thread_bucket_t
;
68
69
#define THREAD_MAKE_ID(id, gen) ((uint64_t)(gen) << 32 | ((uint64_t)(id) + 1))
70
#define THREAD_GET_ID(tid) ((uint32_t)((tid) & 0xFFFFFFFFULL) - 1)
71
#define THREAD_GET_GEN(tid) ((uint32_t)((tid) >> 32))
72
73
thread_t
*
create_thread
(
volatile
uintptr_t
*
page
,
uintptr_t
entry,
uintptr_t
stack
,
74
uint16_t
core_affinity
,
uint8_t
priority
,
75
uint16_t
flags
);
76
void
vxThreadExit
(
void
);
77
78
#endif
/* __PROCC__THREAD_H__ */
used
boolean_t used
Definition
ehci.hpp:6
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
id
thread_id id
Definition
thread.h:1
priority
uint8_t priority
Definition
thread.h:4
thread_t
struct thread thread_t
Definition
thread.h:29
stack
uint64_t stack
Definition
thread.h:13
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
THREAD_STATE_BLOCKED
@ THREAD_STATE_BLOCKED
Definition
thread.h:20
create_thread
thread_t * create_thread(volatile uintptr_t *page, uintptr_t entry, uintptr_t stack, uint16_t core_affinity, uint8_t priority, uint16_t flags)
Definition
thread.c:41
page
uintptr_t page
Definition
paging.c:0
process.h
spinlock.h
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
Definition
thread.h:30
thread::has_update_run_time
boolean_t has_update_run_time
Definition
thread.h:39
thread::kernel_rsp
uintptr_t kernel_rsp
Definition
thread.h:48
thread::last_run_time
uint64_t last_run_time
Definition
thread.h:37
thread::flags
uint16_t flags
Definition
thread.h:36
thread::process
process_t * process
Definition
thread.h:40
thread::stack
uint64_t stack
Definition
thread.h:44
thread::page
volatile uintptr_t * page
Definition
thread.h:29
thread::reg
cpu_register_t reg
Definition
thread.h:45
thread::priority
uint8_t priority
Definition
thread.h:35
thread::gs_base
uint64_t gs_base
Definition
thread.h:44
thread::_pad
uint8_t _pad[12]
Definition
thread.h:45
thread::current_core_id
uint16_t current_core_id
Definition
thread.h:37
thread::kernel_stack_base
uintptr_t kernel_stack_base
Definition
thread.h:49
thread::in_kernel_sleep
bool in_kernel_sleep
Definition
thread.h:51
thread::uuid
uint32_t uuid
Definition
thread.h:38
thread::kernel_stack_top
uintptr_t kernel_stack_top
Definition
thread.h:50
thread::state
uint8_t state
Definition
thread.h:34
thread::wake_pending
bool wake_pending
Definition
thread.h:52
thread::entry_addr
uintptr_t entry_addr
Definition
thread.h:43
thread::clear_child_tid
uint32_t * clear_child_tid
Definition
thread.h:41
thread::fs_base
uint64_t fs_base
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
kernel
procc
thread.h
Generated on Sat May 30 2026 11:09:57 for Voxia OS by
1.13.2