moo/stix/kernel/Process.st

125 lines
1.6 KiB
Smalltalk
Raw Normal View History

#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)
{
#dcl initial active state prev next.
#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
{
^Processor resume: self.
2015-10-18 15:06:17 +00:00
}
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.
}
#method sleep: anInteger
2015-10-15 14:40:08 +00:00
{
<primitive: #_processor_sleep>
self primitiveFailed.
}
#method resume: aProcess
{
<primitive: #_processor_schedule>
self primitiveFailed.
2015-10-15 14:40:08 +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-18 15:06:17 +00:00
}
2015-10-15 14:40:08 +00:00
#method remove: aProcess
{
"<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
{
<primitive: #_processor_yield>
2015-10-15 14:40:08 +00:00
self primitiveFailed
}
"
}