2015-10-22 02:47:25 +00:00
|
|
|
#class Delay(Object)
|
|
|
|
{
|
|
|
|
## TODO: support milliseconds or nanoseconds
|
|
|
|
#dcl delay.
|
|
|
|
|
|
|
|
#method(#class) forSeconds: anInteger
|
|
|
|
{
|
|
|
|
^super basicNew initWith: anInteger.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method initWith: anInteger
|
|
|
|
{
|
|
|
|
self.delay := anInteger.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method wait
|
|
|
|
{
|
|
|
|
Processor sleep: self.delay.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method resume
|
|
|
|
{
|
|
|
|
" TODO: .............. "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 14:40:08 +00:00
|
|
|
#class(#pointer) Process(Object)
|
|
|
|
{
|
2016-02-11 14:26:26 +00:00
|
|
|
#dcl initial active state prev next sp.
|
2015-10-19 06:16:43 +00:00
|
|
|
|
|
|
|
#method new
|
|
|
|
{
|
|
|
|
"instantiation is not allowed"
|
|
|
|
^nil. "TODO: raise an exception"
|
|
|
|
}
|
2015-10-15 14:40:08 +00:00
|
|
|
|
|
|
|
#method prev
|
|
|
|
{
|
|
|
|
^self.prev.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method next
|
|
|
|
{
|
|
|
|
^self.next.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method next: aProcess
|
|
|
|
{
|
|
|
|
self.next := aProcess.
|
|
|
|
}
|
|
|
|
|
|
|
|
#method prev: aProcess
|
|
|
|
{
|
|
|
|
self.prev := aProcess.
|
|
|
|
}
|
2015-10-18 15:06:17 +00:00
|
|
|
|
|
|
|
#method resume
|
|
|
|
{
|
2015-10-22 02:47:25 +00:00
|
|
|
^Processor resume: self.
|
2015-10-18 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 16:23:26 +00:00
|
|
|
#method sp
|
|
|
|
{
|
|
|
|
^sp.
|
|
|
|
}
|
2015-10-15 14:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#class ProcessScheduler(Object)
|
|
|
|
{
|
|
|
|
#dcl tally head tail active.
|
|
|
|
|
|
|
|
#method new
|
|
|
|
{
|
|
|
|
"instantiation is not allowed"
|
|
|
|
^nil. "TODO: raise an exception"
|
|
|
|
}
|
|
|
|
|
|
|
|
#method activeProcess
|
|
|
|
{
|
|
|
|
^self.active.
|
|
|
|
}
|
|
|
|
|
2015-10-22 02:47:25 +00:00
|
|
|
#method sleep: anInteger
|
2015-10-15 14:40:08 +00:00
|
|
|
{
|
2015-10-22 02:47:25 +00:00
|
|
|
<primitive: #_processor_sleep>
|
2015-10-19 06:16:43 +00:00
|
|
|
self primitiveFailed.
|
2015-10-22 02:47:25 +00:00
|
|
|
}
|
2015-10-19 06:16:43 +00:00
|
|
|
|
2015-10-22 02:47:25 +00:00
|
|
|
#method resume: aProcess
|
|
|
|
{
|
|
|
|
<primitive: #_processor_schedule>
|
|
|
|
self primitiveFailed.
|
2015-10-15 14:40:08 +00:00
|
|
|
|
2015-10-22 02:47:25 +00:00
|
|
|
"The primitive does something like the following in principle:
|
2015-10-15 14:40:08 +00:00
|
|
|
(self.tally = 0)
|
|
|
|
ifTrue: [
|
|
|
|
self.head := aProcess.
|
|
|
|
self.tail := aProcess.
|
|
|
|
self.tally := 1.
|
|
|
|
]
|
|
|
|
ifFalse: [
|
|
|
|
aProcess next: self.head.
|
|
|
|
self.head prev: aProcess.
|
|
|
|
self.head := aProcess.
|
|
|
|
self.tally := self.tally + 1.
|
2015-10-22 02:47:25 +00:00
|
|
|
].
|
|
|
|
"
|
2015-10-18 15:06:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-15 14:40:08 +00:00
|
|
|
#method remove: aProcess
|
|
|
|
{
|
2015-10-22 02:47:25 +00:00
|
|
|
"<primitive: #_processor_remove>"
|
2015-10-15 14:40:08 +00:00
|
|
|
"TODO: "
|
2015-10-18 15:06:17 +00:00
|
|
|
}
|
2015-10-15 14:40:08 +00:00
|
|
|
|
2015-10-18 15:06:17 +00:00
|
|
|
#method suspendActive
|
|
|
|
{
|
|
|
|
" TODO: .........."
|
2015-10-15 14:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
"
|
|
|
|
#method yield
|
|
|
|
{
|
2015-10-22 02:47:25 +00:00
|
|
|
<primitive: #_processor_yield>
|
2015-10-15 14:40:08 +00:00
|
|
|
self primitiveFailed
|
|
|
|
}
|
|
|
|
"
|
|
|
|
}
|