-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreads.h
64 lines (53 loc) · 1.44 KB
/
threads.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef __THREADS_H__
#define __THREADS_H__
#include <stddef.h>
#include <stdint.h>
#include "uni_list.h"
// Rozmiar stosu wątku - 4kb
#define THREAD_STACK_SIZE 0x4000
#define THREAD_MAX_COUNT 256
// Kwant czasu, co 20 ms następuje zmiana wątku
#define THREAD_QUANTUM 20
// Stany wątków
enum thread_state_t
{
THREAD_WAITING_FOR_START,
THREAD_READY,
THREAD_RUNNING,
THREAD_RIP
};
// Struktura wątku
struct thread_t
{
uint32_t esp;
uint32_t stack;
uint32_t task;
uint32_t thread_id;
uint32_t priority;
uint32_t process_pid;
volatile enum thread_state_t state;
};
typedef struct thread_t THREAD;
typedef enum thread_state_t THREAD_STATE;
// Lista wątków
UNI_LIST_H(threads, THREAD*)
typedef struct list_threads_t THREADS_LIST;
typedef struct node_threads_t THREADS_NODE;
// Prototypy
void threads_initialize(void);
uint32_t create_kernel_thread(void);
uint32_t create_thread(uint32_t task_addr);
void destroy_thread(uint32_t id);
void start_thread(uint32_t id);
void terminate_thread(uint32_t id);
void join_thread(uint32_t id);
void debug_display_stack(uint32_t id);
THREAD *get_thread(uint32_t id);
THREAD *get_current_thread(void);
void yield(void);
// Funkcje zewnętrzne
extern void switch_stacks_and_jump(uint32_t current_thread, uint32_t next_thread);
extern void switch_stacks(uint32_t current_thread, uint32_t next_thread);
#endif
typedef struct thread_t THREAD;
typedef enum thread_state_t THREAD_STATE;