forked from vsamtuc/tinyos3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel_proc.h
134 lines (93 loc) · 3.75 KB
/
kernel_proc.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef __KERNEL_PROC_H
#define __KERNEL_PROC_H
/**
@file kernel_proc.h
@brief The process table and process management.
@defgroup proc Processes
@ingroup kernel
@brief The process table and process management.
This file defines the PCB structure and basic helpers for
process access.
@{
*/
#include "tinyos.h"
#include "kernel_sched.h"
/**
@brief PID state
A PID can be either free (no process is using it), ALIVE (some running process is
using it), or ZOMBIE (a zombie process is using it).
*/
typedef enum pid_state_e {
FREE, /**< @brief The PID is free and available */
ALIVE, /**< @brief The PID is given to a process */
ZOMBIE /**< @brief The PID is held by a zombie */
} pid_state;
/**
@brief Process Control Block.
This structure holds all information pertaining to a process.
*/
typedef struct process_control_block {
pid_state pstate; /**< @brief The pid state for this PCB */
uint thread_count;
PCB* parent; /**< @brief Parent's pcb. */
int exitval; /**< @brief The exit value of the process */
TCB* main_thread; /**< @brief The main thread */
Task main_task; /**< @brief The main thread's function */
int argl; /**< @brief The main thread's argument length */
void* args; /**< @brief The main thread's argument string */
rlnode children_list; /**< @brief List of children */
rlnode exited_list; /**< @brief List of exited children */
rlnode thread_list;
rlnode children_node; /**< @brief Intrusive node for @c children_list */
rlnode exited_node; /**< @brief Intrusive node for @c exited_list */
CondVar child_exit; /**< @brief Condition variable for @c WaitChild.
This condition variable is broadcast each time a child
process terminates. It is used in the implementation of
@c WaitChild() */
FCB* FIDT[MAX_FILEID]; /**< @brief The fileid table of the process */
} PCB;
typedef struct process_thread_control_block {
uint ref_count;//How many threads are waiting for this thread
TCB *tcb ;//Pointer to the tcb
rlnode thread_list_node;//Intrusive node to ptcb
Task task;//Pointer to the task function of this thread
uint argl;//The length of the argument
void *args;//The pointer to the argument
int exitval;//The value that is returned by the function pointed by task
int exited;//Boolean variable ,1 if the thread is exited
int detached;//Boolean variable , 1 if the thread is detached
CondVar exit_cv;//Condition variable to wait on, when waiting for the thread to exit
} PTCB;
typedef struct system_info_control_block {
procinfo curinfo;
uint cursor;//Its a counter for the process table
} SICB;
/**
@brief Initialize the process table.
This function is called during kernel initialization, to initialize
any data structures related to process creation.
*/
void initialize_processes();
/**
@brief Get the PCB for a PID.
This function will return a pointer to the PCB of
the process with a given PID. If the PID does not
correspond to a process, the function returns @c NULL.
@param pid the pid of the process
@returns A pointer to the PCB of the process, or NULL.
*/
PCB* get_pcb(Pid_t pid);
/**
@brief Get the PID of a PCB.
This function will return the PID of the process
whose PCB is pointed at by @c pcb. If the pcb does not
correspond to a process, the function returns @c NOPROC.
@param pcb the pcb of the process
@returns the PID of the process, or NOPROC.
*/
Pid_t get_pid(PCB* pcb);
int sys_System_Info_Read(void* stream_object, char *buf, unsigned int size);
int sys_System_Info_Close(void* streamobj);
int sys_Info_Void(void* stream_object, char *buf, unsigned int size);
/** @} */
#endif