Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

OS::SharedQueue Class Reference

#include <SharedQueue.h>

Inheritance diagram for OS::SharedQueue:

Inheritance graph
[legend]
Collaboration diagram for OS::SharedQueue:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SharedQueue (long size=2)
virtual String * className (void) const
 Answer receiver class name.
virtual Object * next (void)
virtual void nextPut (Object *object)
virtual Object * peek (void)
virtual long size (void)
virtual bool isEmpty (void)

Protected Attributes

OrderedCollection * content
Semaphore * emptySemaphore
Semaphore * accessLock

Constructor & Destructor Documentation

OS::SharedQueue::SharedQueue (  long  size = 2  ) 
 

Definition at line 31 of file SharedQueue.cc.

References accessLock, content, emptySemaphore, and OS::Semaphore::forMutualExclusion().

00032 {
00033     content = new OrderedCollection(size);
00034     accessLock = Semaphore::forMutualExclusion();
00035     emptySemaphore = new Semaphore;
00036 }


Member Function Documentation

String * OS::SharedQueue::className (  void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented from Core::Object.

Definition at line 39 of file SharedQueue.cc.

00040 {
00041     return new String("SharedQueue");
00042 }

bool OS::SharedQueue::isEmpty (  void   )  [virtual]
 

Definition at line 81 of file SharedQueue.cc.

References content, and Core::Collection::isEmpty().

Referenced by peek().

00082 {
00083     return content->isEmpty();
00084 }

Object * OS::SharedQueue::next (  void   )  [virtual]
 

Definition at line 45 of file SharedQueue.cc.

References accessLock, content, emptySemaphore, Core::OrderedCollection::removeFirst(), OS::Semaphore::signal(), and OS::Semaphore::wait().

00046 {
00047     Object *data;
00048 
00049     emptySemaphore->wait();
00050     accessLock->wait();
00051     data = content->removeFirst();
00052     accessLock->signal();
00053     return data;
00054 }

void OS::SharedQueue::nextPut (  Object *  object  )  [virtual]
 

Definition at line 56 of file SharedQueue.cc.

References accessLock, Core::OrderedCollection::addLast(), content, emptySemaphore, OS::Semaphore::signal(), and OS::Semaphore::wait().

00057 {
00058     accessLock->wait();
00059     content->addLast(object);
00060     emptySemaphore->signal();
00061     accessLock->signal();
00062 }

Object * OS::SharedQueue::peek (  void   )  [virtual]
 

Definition at line 64 of file SharedQueue.cc.

References accessLock, content, Core::OrderedCollection::first(), isEmpty(), nil, OS::Semaphore::signal(), and OS::Semaphore::wait().

00065 {
00066     Object *data;
00067 
00068     accessLock->wait();
00069     if (isEmpty()) data = nil;
00070               else data = content->first();
00071     accessLock->signal();
00072     return data;
00073 }

long OS::SharedQueue::size (  void   )  [virtual]
 

Definition at line 75 of file SharedQueue.cc.

References content, and Core::OrderedCollection::size().

00076 {
00077     return content->size();
00078 }


Member Data Documentation

Semaphore* OS::SharedQueue::accessLock [protected]
 

Definition at line 39 of file SharedQueue.h.

Referenced by next(), nextPut(), peek(), and SharedQueue().

OrderedCollection* OS::SharedQueue::content [protected]
 

Definition at line 37 of file SharedQueue.h.

Referenced by isEmpty(), next(), nextPut(), peek(), SharedQueue(), and size().

Semaphore* OS::SharedQueue::emptySemaphore [protected]
 

Definition at line 38 of file SharedQueue.h.

Referenced by next(), nextPut(), and SharedQueue().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:52:23 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2