-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.h
99 lines (87 loc) · 2.06 KB
/
user.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
struct stat;
struct rtcdate;
// system calls
int fork(void);
int exit(void) __attribute__((noreturn));
int wait(void);
int pipe(int*);
int write(int, const void*, int);
int read(int, void*, int);
int close(int);
int kill(int);
int exec(char*, char**);
int open(const char*, int);
int mknod(const char*, short, short);
int unlink(const char*);
int fstat(int fd, struct stat*);
int link(const char*, const char*);
int mkdir(const char*);
int chdir(const char*);
int dup(int);
int getpid(void);
char* sbrk(int);
int sleep(int);
int uptime(void);
int clone(int (*fn)(void *, void *), void *arg1, void *arg2, void *child_stack, int flags);
int join(int pid);
int park(void *chan);
int unpark(int pid, void *chan);
// ulib.c
int stat(const char*, struct stat*);
char* strcpy(char*, const char*);
void *memmove(void*, const void*, int);
char* strchr(const char*, char c);
int strcmp(const char*, const char*);
void printf(int, const char*, ...);
char* gets(char*, int max);
uint strlen(const char*);
void* memset(void*, int, uint);
void* malloc(uint);
void free(void*);
int atoi(const char*);
// ucthreads.c
typedef struct{
int pid;
char *stack;
}cthread_t;
int cthread_create(cthread_t *thread, int (*fn)(void *, void *), void *arg1, void *arg2);
int cthread_cut(cthread_t *thread);
int cthread_join(cthread_t *thread);
void cthread_exit(void) __attribute__((noreturn));
// ticket lock
typedef struct{
uint ticket;
uint turn;
}tlock_t;
void tlock_init(tlock_t *);
void tlock_acquire(tlock_t *);
void tlock_release(tlock_t *);
// spinlock
typedef uint slock_t;
void slock_init(slock_t *);
void slock_acquire(slock_t *);
void slock_release(slock_t *);
// queue
typedef struct qnode{
struct qnode *next;
int val;
}qnode;
#define QMAX 100
typedef struct{
int arr[QMAX];
int start, end;
uint count;
}queue;
void qinit(queue *q);
void enq(queue *q, int x);
int qisempty(queue *q);
int qisfull(queue *q);
int deq(queue *q);
typedef struct{
slock_t guard;
queue waitq;
int count;
}semaphore_t;
void sem_init(semaphore_t *s, int n);
void sem_up(semaphore_t *s);
void sem_down(semaphore_t *s);