migrated some primitives from Processor to System.

Fixed a bug in manipulating moo->sem_io_wait_count.
Experimenting to add a shortcut exception handling syntax
This commit is contained in:
hyunghwan.chung
2017-11-21 09:15:22 +00:00
parent 85b25d53bc
commit b07cab3874
7 changed files with 151 additions and 49 deletions

View File

@ -239,6 +239,54 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit
^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 |
@ -254,8 +302,13 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit
## arrange the processor to notify upon timeout.
System signal: s after: seconds.
## wait on the semaphore group.
r := self wait.
[
## wait on the semaphore group.
r := self wait.
] on: Exception do: [:ex |
System _unsignal: s.
ex throw
].
## if the internal semaphore has been signaled,
## arrange to return nil to indicate timeout.
@ -270,6 +323,7 @@ method(#class,#abstract) xxx. => method(#class) xxx { self subclassResponsibilit
^r.
}
*)
}
class SemaphoreHeap(Object)
@ -471,10 +525,4 @@ class(#final,#limited) ProcessScheduler(Object)
].
*)
}
method return: object to: context
{
<primitive: #_processor_return_to>
self primitiveFailed.
}
}