-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevMan.c
More file actions
111 lines (91 loc) · 2.28 KB
/
DevMan.c
File metadata and controls
111 lines (91 loc) · 2.28 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
//=======================================
// Multi-level Host Dispatcher
//
// EECE 315 - Project 4
// Group 11
//
// Siddhartha Balasubramanian
// Nabil Lathiff
// Mark Duppenthaler
// Michael Peterson
//=======================================
//=======================================
// DevMan.c
//=======================================
// Device manager module
//
// Handles requests for usage of devices
// and peripherals.
//
// Keeps a running count of free devices
// and assigns devices to processes.
//
// Frees devices if a process terminates
//
#include "SystemDefs.h"
#include "ProcMan.h"
#include "DevMan.h"
int DevManisInit;
DeviceState devices;
DEVMANERR DevManInit()
// Initialize the device manager
{
devices.cd = SYSTEMNUMCD;
devices.scan = SYSTEMNUMSCAN;
devices.print = SYSTEMNUMPRINT;
devices.modem = SYSTEMNUMMODEM;
DevManisInit = 1;
return DEVMANSUCCESS;
}
DEVMANERR DevManCheckAllocate(ProcInfo* proc)
// Check if a certain set of devices can be allocated to a process
{
if(!DevManisInit)
DevManInit();
if(devices.cd < proc->numCD)
return DEVMANUNAVAILABLE;
if(devices.scan < proc->numScan)
return DEVMANUNAVAILABLE;
if(devices.print < proc->numPrint)
return DEVMANUNAVAILABLE;
if(devices.modem < proc-> numModem)
return DEVMANUNAVAILABLE;
return DEVMANAVAILABLE;
}
DEVMANERR DevManAllocate(ProcInfo* proc)
// Allocate all the devices that are required by a process
{
if(!DevManisInit)
DevManInit();
if(DevManCheckAllocate(proc) == DEVMANAVAILABLE)
{
devices.cd -= proc->numCD;
devices.scan -= proc->numScan;
devices.print -= proc->numPrint;
devices.modem -= proc->numModem;
return DEVMANALLOCATED;
}
else
return DEVMANUNAVAILABLE;
}
DEVMANERR DevManRelease(ProcInfo* proc)
// Release all the devices that has been allocated to a process
{
if(proc->devBlock == DEVMANALLOCATED)
{
devices.cd += proc->numCD;
devices.scan += proc->numScan;
devices.print += proc->numPrint;
devices.modem += proc->numModem;
proc->devBlock = 0;
return DEVMANSUCCESS;
}
else
return DEVMANRELEASEFAIL;
}
DeviceState* DevManGetDeviceState(void)
// Return the device state
// Used to print the device state
{
return &devices;
}