-
Notifications
You must be signed in to change notification settings - Fork 2
/
TCB.java
74 lines (63 loc) · 1.58 KB
/
TCB.java
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
public class TCB {
private Thread thread = null;
private int tid = 0;
private int pid = 0;
private boolean terminated = false;
private int sleepTime = 0;
public FileTableEntry[] ftEnt = null; // added for the file system
public TCB( Thread newThread, int myTid, int parentTid ) {
thread = newThread;
tid = myTid;
pid = parentTid;
terminated = false;
ftEnt = new FileTableEntry[32]; // added for the file system
System.err.println( "threadOS: a new thread (thread=" + thread +
" tid=" + tid +
" pid=" + pid + ")");
}
public synchronized Thread getThread( ) {
return thread;
}
public synchronized int getTid( ) {
return tid;
}
public synchronized int getPid( ) {
return pid;
}
public synchronized boolean setTerminated( ) {
terminated = true;
return terminated;
}
public synchronized boolean getTerminated( ) {
return terminated;
}
// added for the file system
public synchronized int getFd( FileTableEntry entry ) {
if ( entry == null )
return -1;
for ( int i = 3; i < 32; i++ ) {
if ( ftEnt[i] == null ) {
ftEnt[i] = entry;
return i;
}
}
return -1;
}
// added for the file system
public synchronized FileTableEntry returnFd( int fd ) {
if ( fd >= 3 && fd < 32 ) {
FileTableEntry oldEnt = ftEnt[fd];
ftEnt[fd] = null;
return oldEnt;
}
else
return null;
}
// added for the file system
public synchronized FileTableEntry getFtEnt( int fd ) {
if ( fd >= 3 && fd < 32 )
return ftEnt[fd];
else
return null;
}
}