diff options
author | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-08-27 18:14:04 +0000 |
---|---|---|
committer | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-08-27 18:14:04 +0000 |
commit | 6c13de310492e31ede379bb04df1c62cbdb4b09f (patch) | |
tree | e97ae496cdcdecfec591b74ea60dde5ceb33d32a /java/tests/Concurrency/Condition/SimpleMessageQueue.java | |
parent | b5e068afb139dc7c6b9cf90c53571a4333105c95 (diff) | |
download | ATCD-pre_dynamic_any.tar.gz |
This commit was manufactured by cvs2svn to create tagpre_dynamic_any
'pre_dynamic_any'.
Diffstat (limited to 'java/tests/Concurrency/Condition/SimpleMessageQueue.java')
-rw-r--r-- | java/tests/Concurrency/Condition/SimpleMessageQueue.java | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/java/tests/Concurrency/Condition/SimpleMessageQueue.java b/java/tests/Concurrency/Condition/SimpleMessageQueue.java deleted file mode 100644 index bb703516858..00000000000 --- a/java/tests/Concurrency/Condition/SimpleMessageQueue.java +++ /dev/null @@ -1,86 +0,0 @@ -package tests.Concurrency.Condition; - -import JACE.ASX.TimeoutException; -import JACE.ASX.TimeValue; -import JACE.Concurrency.*; - -public class SimpleMessageQueue -{ - private int num_items_ = 0; - private int head_ = 0, tail_ = 0; - private Object[] queue_; - - private Mutex lock_ = new Mutex (); - private Condition notFull_ = new Condition (lock_); - private Condition notEmpty_ = new Condition (lock_); - - public SimpleMessageQueue(int size) - { - queue_ = new Object[size]; - } - - public void enqueue(Object element, TimeValue timeout) - throws TimeoutException, InterruptedException - { - try - { - lock_.acquire (); - while (this.isFull ()) - notFull_.Wait (timeout); - - if (tail_ == queue_.length) - tail_ = 0; - queue_[tail_] = element; - tail_++; - - num_items_++; - notEmpty_.signal (); - } - finally - { - lock_.release (); - } - } - - public Object dequeue (TimeValue timeout) - throws TimeoutException, InterruptedException - { - Object return_value = null; - - try - { - lock_.acquire (); - while (this.isEmpty ()) - notEmpty_.Wait (timeout); - - return_value = queue_[head_]; - head_++; - if (head_ == queue_.length) - head_ = 0; - - num_items_--; - notFull_.signal (); - } - finally - { - lock_.release (); - } - return return_value; - } - - public boolean isEmpty() - { - return num_items_ == 0; - } - - public boolean isFull() - { - return num_items_ == queue_.length; - } - - public int size() - { - return num_items_; - } -} - |