-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOS.h
More file actions
154 lines (115 loc) · 3.14 KB
/
OS.h
File metadata and controls
154 lines (115 loc) · 3.14 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Problem 3 - Discontinuities
* TCSS 422 A Spring 2016
* Bun Kak, Chris Ottersen, Mark Peters, Paul Zander
*/
#ifndef OS_H
#define OS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <pthread.h>
#include "FIFOq.h"
#include "PCB.h"
#include "fthread.h"
//RENAMES
#define thread pthread_t
#define mutex pthread_mutex_t
#define cond pthread_cond_t
//OUTPUT SETTINGS
#define DEBUG false
#define THREAD_DEBUG false
#define STACK_DEBUG false
#define CREATEPCB_DEBUG false
#define EXIT_STATUS_MESSAGE true
#define OUTPUT true
#define OUTPUT_CONTEXT_SWITCH 1
#define FIRST_IO 1
//PCB SETTINGS
#define EXIT_ON_MAX_PROCESSES false
#define MAX_PROCESSES ULONG_MAX
#define MAX_NEW_PCB 5
#define START_IDLE false
#define PCB_CREATE_EVERY false
#define PCB_CREATE_FIRST false
#define PCB_SCHEDULE_EVERY false
#define PCB_CREATE_CHANCE (TIME_QUANTUM * 50)
#define RUN_MIN_TIME 3000
#define RUN_TIME_RANGE 1000
#define STARVATION_CHECK_FREQUENCY (TIME_QUANTUM / 15)
#define STARVATION_CLOCK_LIMIT (TIME_QUANTUM * 50)
#define PROMOTION_ALLOWANCE 1
//INTERRUPT CODES
#define NO_INTERRUPT 9999
#define INTERRUPT_TIMER 5555
#define INTERRUPT_TERMINATE 8888
#define INTERRUPT_IOCOMPLETE 4444
//SYSTEM DETAILS
#define SHUTDOWN 100000
#define TIME_QUANTUM 300
#define TIMER_SLEEP (TIME_QUANTUM * 1000)
#define IO_MAX_SLEEP (TIME_QUANTUM * 2000)
#define IO_MIN_SLEEP (TIME_QUANTUM * 10)
#define SYSSIZE 256
#define SYSTEM_RUNS 3
//ERRORS
#define OS_NO_ERROR 0//EXIT_SUCCESS
#define STACK_ERROR_DEFAULT 0
#define CPU_NULL_ERROR 71
#define CPU_STACK_ERROR 73
#define OS_UNKOWN_INTERRUPT_ERROR 79
//note on style: ALLCAPS_lowercase is either a MUTEX_ variable or the data
// protected by the MUTEX_
struct CPU
{
REG_p regs;
};
struct shared_resource
{
int members;
mutex_lock_type fmutex[MUTUAL_MAX_RESOURCES];
cond_var_type fcond[MUTUAL_MAX_RESOURCES];
bool flag[MUTUAL_MAX_RESOURCES];
word resource[MUTUAL_MAX_RESOURCES];
};
struct io_thread_type
{
thread THREAD_io;
mutex MUTEX_io;
cond COND_io;
bool INTERRUPT_iocomplete;
bool SHUTOFF_io;
FIFOq_p waitingQ;
};
typedef struct io_thread_type *io_thread;
typedef struct shared_resource *PCB_r;
//extern word SsyStack[SYSSIZE];
//extern int SysPointer;
int bootOS();
int mainLoopOS(int *error);
void *timer(void *);
void *io(void *);
void trap_terminate(int *error);
void trap_iohandler(const int T, int *error);
void trap_mutexhandler(const int T, int *error);
void trap_requehandler(const int T, int *error);
void interrupt(const int INTERRUPT, void *, int *error);
void isr_timer(int *error);
void isr_iocomplete(const int IO, int *error);
void scheduler(int *error);
void dispatcher(int *error);
int createPCBs(int *error);
PCB_r mutexPair(int *error);
void mutexEmpty(PCB_r, int *error);
void sysStackPush(REG_p, int *error);
void sysStackPop(REG_p, int *error);
void cleanup(int *error);
void queueCleanup(FIFOq_p, char *, int *error);
void stackCleanup();
void mutexCleanup(PCB_r, int *error);
void nanosleeptest();
void awakeStarvationDaemon(int *error);
//static void run (word *pc, int *error);
#endif