[comp.lang.c++] Corrections to OOPS class library

keith@nih-csl.UUCP (keith gorlen) (01/29/88)

Object-Oriented Program Support Class Library Corrections 28-Jan-88


Class SharedQueue:

If a SharedQueue is full the function SharedQueue::printOn() doesn't
print the objects in the queue.  This bug occurs in all versions of
OOPS sent out before 28-Jan-88.  Here is a corrected version of
SharedQueue::printOn():

void SharedQueue::printOn(ostream& strm)
{
	strm << className() << "(\n";
	strm << "valueAvailable " << valueAvailable;
	strm << "spaceAvailable " << spaceAvailable;
	strm << "queue:\n";
	int i = readPosition;
	for (int n = valueAvailable.value(); n>0; n--) {
		queue[i++]->printOn(strm);
		strm << "\n";
		if (i == queue.capacity()) i = 0;
	}
	strm << ")\n";
}


Class Semaphore:

On 30-Dec-87 Semaphore::signal() was changed.  A parameter "n" was
added to signal the next "n" waiting processes, but the change caused
a signal(1) to incorrectly increment "count" by 2 if "count" was 0.
This problem occurs in all versions of OOPS sent out between 30-Dec-87
and 28-Jan-88.  Here is a corrected version of Semaphore::signal():

void Semaphore::signal(unsigned n)
{
	if (n == 0) return;
	AST_DISABLE;
		register Process* next;
		while (count<0 && n>0) {
			next = (Process*)waitList.removeFirst();
			if (next->state() != TERMINATED) {
				next->resume();
				n--;
			}
			count++;
		}
		count += n;
	AST_ENABLE;
}

-- 
	Keith Gorlen			phone: (301) 496-5363
	Building 12A, Room 2017		uucp: uunet!ncifcrf.gov!nih-csl!keith
	National Institutes of Health	Internet: keith%nih-csl@ncifcrf.gov
	Bethesda, MD 20892