Skip to content

Instantly share code, notes, and snippets.

@aerodame
aerodame / Kernel_Interrupt.java
Last active August 29, 2015 14:20
ThreadOS Disk I/O Interrupt
public static int interrupt( int irq, int cmd, int param, Object args ) {
TCB myTcb;
switch( irq ) {
case INTERRUPT_SOFTWARE: // System calls
...
...
case INTERRUPT_DISK: // Disk interrupts
// wake up the thread waiting for a service completion
ioQueue.dequeueAndWakeup( 2 );
@aerodame
aerodame / SyncQueueWAIT_EXIT.java
Last active August 29, 2015 14:20
SyncQueue WAIT and EXIT
case WAIT:
// get the current thread id (use Scheduler.getMyTcb( ) )
// let the current thread sleep in waitQueue under the condition
// = this thread id (= tcb.getTid( ) )
return OK; // return a child thread id who woke me up
case EXIT:
// get the current thread's parent id (= tcb.getPid( ) )
// search waitQueue for and wakes up the thread under the condition
// = the current thread's parent id
return OK;
@aerodame
aerodame / SyncQueue-Wail.java
Created April 29, 2015 05:41
SyncQueue WaitQueue
public class Kernel
{
private static SyncQueue waitQueue;
...
public static int interrupt( int irq, int cmd, int param, Object args ) {
TCB myTcb;
switch( irq ) {
case INTERRUPT_SOFTWARE: // System calls
switch( cmd ) {
public class Kernel
{
private static SyncQueue ioQueue;
...
public static int interrupt( int irq, int cmd, int param, Object args ) {
TCB myTcb;
switch( irq ) {
case INTERRUPT_SOFTWARE: // System calls
switch( cmd ) {
@aerodame
aerodame / Inode.java
Created May 27, 2015 03:56
Inode.java
public class Inode {
private final static int iNodeSize = 32; // fix to 32 bytes
private final static int directSize = 11; // # direct pointers
public int length; // file size in bytes
public short count; // # file-table entries pointing to this
public short flag; // 0 = unused, 1 = used, ...
public short direct[] = new short[directSize]; // direct pointers
public short indirect; // a indirect pointer
class Superblock {
public int totalBlocks; // the number of disk blocks
public int totalInodes; // the number of inodes
public int freeList; // the block number of the free list's head
public SuperBlock( int diskSize ) {
...
}
...
}
public class Directory {
private static int maxChars = 30; // max characters of each file name
// Directory entries
private int fsize[]; // each element stores a different file size.
private char fnames[][]; // each element stores a different file name.
public Directory( int maxInumber ) { // directory constructor
fsizes = new int[maxInumber]; // maxInumber = max files
for ( int i = 0; i < maxInumber; i++ )
public class FileTableEntry { // Each table entry should have
public int seekPtr; // a file seek pointer
public final Inode inode; // a reference to its inode
public final short iNumber; // this inode number
public int count; // # threads sharing this entry
public final String mode; // "r", "w", "w+", or "a"
public FileTableEntry ( Inode i, short inumber, String m ) {
seekPtr = 0; // the seek pointer is set to the file top
inode = i;
iNumber = inumber;
public class FileTable {
private Vector table; // the actual entity of this file table
private Directory dir; // the root directory
public FileTable( Directory directory ) { // constructor
table = new Vector( ); // instantiate a file (structure) table
dir = directory; // receive a reference to the Director
} // from the file system
public class TCB {
private Thread thread = null;
private int tid = 0;
private int pid = 0;
private boolean terminate = false;
// User file descriptor table:
// each entry pointing to a file (structure) table entry
public FileTableEntry[] ftEnt = null;