nachos.kernel.threads
Class SynchList

java.lang.Object
  extended by nachos.kernel.threads.List
      extended by nachos.kernel.threads.SynchList

public class SynchList
extends List

This class defines a "synchronized list" -- a list for which these constraints hold: 1. Threads trying to remove an item from a list will wait until the list has an element on it. 2. One thread at a time can access list data structures


Nested Class Summary
 
Nested classes/interfaces inherited from class nachos.kernel.threads.List
List.ListElement
 
Field Summary
private  Condition listEmpty
          Used in remove to wait if the list is empty.
private  Lock lock
          Lock to enforce mutual exclusive access to the list.
 
Constructor Summary
SynchList()
          Allocate and initialize the data structures needed for a synchronized list, empty to start with.
 
Method Summary
 void append(java.lang.Object item)
          Append an "item" to the end of the list.
 void prepend(java.lang.Object item)
          Put an "item" on the front of the list.
 java.lang.Object remove()
          Remove an "item" from the beginning of the list.
 void sortedInsert(java.lang.Object item, long sortKey)
          Insert an "item" into a list, so that the list elements are sorted in increasing order by "sortKey".
 
Methods inherited from class nachos.kernel.threads.List
isEmpty, List
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lock

private Lock lock
Lock to enforce mutual exclusive access to the list.


listEmpty

private Condition listEmpty
Used in remove to wait if the list is empty.

Constructor Detail

SynchList

public SynchList()
Allocate and initialize the data structures needed for a synchronized list, empty to start with. Elements can then be added to the list.

Method Detail

append

public void append(java.lang.Object item)
Append an "item" to the end of the list. Wake up anyone waiting for an element to be appended.

Overrides:
append in class List
Parameters:
item - The thing to put on the list, it can be any object.

prepend

public void prepend(java.lang.Object item)
Put an "item" on the front of the list. Wake up anyone waiting for an element to be appended.

Overrides:
prepend in class List
Parameters:
item - The thing to put on the list, it can be any object.

remove

public java.lang.Object remove()
Remove an "item" from the beginning of the list. Wait if the list is empty.

Overrides:
remove in class List
Returns:
the removed item.

sortedInsert

public void sortedInsert(java.lang.Object item,
                         long sortKey)
Insert an "item" into a list, so that the list elements are sorted in increasing order by "sortKey". Wakeup anyone waiting for an item to be inserted

Overrides:
sortedInsert in class List
Parameters:
item - The thing to put on the list, it can be any object.
sortKey - The priority of the item.