revised some semaphore related methods, primitive functions
This commit is contained in:
		| @ -218,59 +218,10 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit | ||||
| 	{ | ||||
| 		| x | | ||||
| 		x := self _wait. | ||||
| 		if (x isError) { Exception signal: ('Cannot wait on a semaphore - ' & x asString) }. | ||||
| 		if (x signalAction notNil) { x signalAction value: x }. | ||||
| 		^x | ||||
| 	} | ||||
|  | ||||
| 	method _waitWithTimeout: seconds | ||||
| 	{ | ||||
| 		| s r | | ||||
|  | ||||
| 		## create an internal semaphore for timeout notification. | ||||
| 		s := Semaphore _new. | ||||
| 		if (s isError) { ^s }. | ||||
|  | ||||
| 		## grant the partial membership to the internal semaphore. | ||||
| 		## it's partial because it's not added to self.semarr. | ||||
| 		##s _group: self.  | ||||
| 		if ((r := (self addSemaphore: s)) isError) { ^r }. | ||||
|  | ||||
| 		## arrange the processor to notify upon timeout. | ||||
| 		if ((r := (System _signal: s after: seconds)) isError) { ^r }. | ||||
|  | ||||
| 		if ((r := self _wait) isError)  | ||||
| 		{ | ||||
| 			System _unsignal: s. | ||||
| 			^r. | ||||
| 		}. | ||||
|  | ||||
| 		## if the internal semaphore has been signaled,  | ||||
| 		## arrange to return nil to indicate timeout. | ||||
| 		if (r == s) { r := nil } | ||||
| 		elsif (r signalAction notNil) { r signalAction value: r }. | ||||
|  | ||||
| 		## nullify the membership | ||||
| 		self _removeSemaphore: s. | ||||
|  | ||||
| 		## cancel the notification arrangement in case it didn't time out. | ||||
| 		System _unsignal: s. | ||||
|  | ||||
| 		^r. | ||||
| 	} | ||||
|  | ||||
| 	method waitWithTimeout: seconds | ||||
| 	{ | ||||
| 		| r | | ||||
| 		r := self _waitWithTimeout: seconds. | ||||
| 		if (r isError)   | ||||
| 		{ | ||||
| 			Exception signal: 'Error has occurred...' error: r. | ||||
| 		}. | ||||
| 		^r | ||||
| 	} | ||||
|  | ||||
| (* | ||||
| 	method waitWithTimeout: seconds | ||||
| 	{ | ||||
| 		| s r | | ||||
| @ -290,7 +241,7 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit | ||||
| 			## wait on the semaphore group. | ||||
| 			r := self wait. | ||||
| 		] on: Exception do: [:ex | | ||||
| 			System _unsignal: s. | ||||
| 			System unsignal: s. | ||||
| 			ex throw | ||||
| 		]. | ||||
|  | ||||
| @ -307,7 +258,6 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit | ||||
|  | ||||
| 		^r. | ||||
| 	}  | ||||
| *) | ||||
| } | ||||
|  | ||||
| class SemaphoreHeap(Object) | ||||
|  | ||||
| @ -101,70 +101,13 @@ class System(Apex) | ||||
|  | ||||
| 	## ======================================================================================= | ||||
|  | ||||
| 	method(#class,#primitive) _signal: semaphore afterSecs: secs. | ||||
| 	method(#class,#primitive) _signal: semaphore afterSecs: secs nanosecs: nanosecs. | ||||
| 	method(#class,#primitive) _signal: semaphore onInOutput: file. | ||||
| 	method(#class,#primitive) _signal: semaphore onInput: file. | ||||
| 	method(#class,#primitive) _signal: semaphore onOutput: file. | ||||
| 	method(#class,#primitive) _signalOnGCFin: semaphore. | ||||
| 	method(#class,#primitive) _unsignal: semaphore. | ||||
|  | ||||
| 	method(#class) signal: semaphore afterSecs: secs | ||||
| 	{ | ||||
| 		| x | | ||||
| 		x := self _signal: semaphore afterSecs: secs. | ||||
| 		if (x isError) { Exception raise: 'Cannot register a semaphore for signaling - ' & (x asString) }. | ||||
| 		^x | ||||
| 	} | ||||
|  | ||||
| 	method(#class) signal: semaphore afterSecs: secs nanoSecs: nanosecs | ||||
| 	{ | ||||
| 		| x | | ||||
| 		x := self _signal: semaphore afterSecs: secs nanosecs: nanosecs. | ||||
| 		if (x isError) { Exception raise: 'Cannot register a semaphore for signaling - ' & (x asString) }. | ||||
| 		^x | ||||
| 	} | ||||
|  | ||||
| 	method(#class) signal: semaphore onInput: file | ||||
| 	{ | ||||
| 		| x | | ||||
| 		x := self _signal: semaphore onInput: file. | ||||
| 		if (x isError) { Exception raise: 'Cannot register a semaphore for signaling - ' & (x asString) }. | ||||
| 		^x | ||||
| 	} | ||||
|  | ||||
| 	method(#class) signal: semaphore onOutput: file | ||||
| 	{ | ||||
| 		| x | | ||||
| 		x := self _signal: semaphore onOutput: file. | ||||
| 		if (x isError) { Exception raise: 'Cannot register a semaphore for signaling - ' & (x asString) }. | ||||
| 		^x | ||||
| 	} | ||||
|  | ||||
| 	method(#class) signal: semaphore onInOutput: file | ||||
| 	{ | ||||
| 		| x | | ||||
| 		x := self _signal: semaphore onInOutput: file. | ||||
| 		if (x isError) { Exception raise: 'Cannot register a semaphore for signaling - ' & (x asString) }. | ||||
| 		^x | ||||
| 	} | ||||
|  | ||||
| 	method(#class) signalOnGCFin: semaphore | ||||
| 	{ | ||||
| 		| x | | ||||
| 		x := self _signalOnGCFin: semaphore. | ||||
| 		if (x isError) { Exception raise: 'Cannot register a semaphore for GC finalization - ' & (x asString) }. | ||||
| 		^x | ||||
| 	} | ||||
|  | ||||
| 	method(#class) unsignal: semaphore | ||||
| 	{ | ||||
| 		| x | | ||||
| 		x := self _unsignal: semaphore. | ||||
| 		if (x isError) { Exception raise: 'Cannot deregister a semaphore from signaling ' & (x asString) }. | ||||
| 		^x | ||||
| 	} | ||||
|  | ||||
| 	method(#class,#primitive) signal: semaphore afterSecs: secs. | ||||
| 	method(#class,#primitive) signal: semaphore afterSecs: secs nanosecs: nanosecs. | ||||
| 	method(#class,#primitive) signal: semaphore onInOutput: file. | ||||
| 	method(#class,#primitive) signal: semaphore onInput: file. | ||||
| 	method(#class,#primitive) signal: semaphore onOutput: file. | ||||
| 	method(#class,#primitive) signalOnGCFin: semaphore. | ||||
| 	method(#class,#primitive) unsignal: semaphore. | ||||
|  | ||||
| 	## ======================================================================================= | ||||
| 	method(#class) sleepForSecs: secs | ||||
|  | ||||
		Reference in New Issue
	
	Block a user