BoltLock.st
changeset 2802 3cadee07e98f
parent 2801 c1ed819bc4a9
child 3143 292e6ffa0b21
equal deleted inserted replaced
2801:c1ed819bc4a9 2802:3cadee07e98f
   221     "/ do not set to nil - a waiting process may be suspended and will not be resumed...
   221     "/ do not set to nil - a waiting process may be suspended and will not be resumed...
   222     "/    waitingProcesses := nil.
   222     "/    waitingProcesses := nil.
   223 
   223 
   224     "/ todo: resume by priority; higher first.
   224     "/ todo: resume by priority; higher first.
   225     processes do:[:eachProcess | 
   225     processes do:[:eachProcess | 
   226         Transcript showCR:('   wakeup thread %1' bindWith:eachProcess name).
   226         "/ Transcript showCR:('   wakeup thread %1' bindWith:eachProcess name).
   227         Processor resume:eachProcess
   227         Processor resume:eachProcess
   228     ].
   228     ].
   229 
   229 
   230     "Created: / 06-08-2012 / 16:05:01 / cg"
   230     "Created: / 06-08-2012 / 16:05:01 / cg"
   231 ! !
   231 ! !
   236     "release the lock"
   236     "release the lock"
   237 
   237 
   238     |activeProcess wasBlocked|
   238     |activeProcess wasBlocked|
   239 
   239 
   240     wasBlocked := OperatingSystem blockInterrupts.
   240     wasBlocked := OperatingSystem blockInterrupts.
   241     Transcript showCR:'  release in state ',state.
   241     "/ Transcript showCR:'  release in state ',state.
   242     activeProcess := Processor activeProcess.
   242     activeProcess := Processor activeProcess.
   243     state == StateLocked ifTrue:[
   243     state == StateLocked ifTrue:[
   244         "I am the writer"
   244         "I am the writer"
   245         state := StateFree.
   245         state := StateFree.
   246     ] ifFalse:[
   246     ] ifFalse:[
   265 
   265 
   266     |activeProcess wasBlocked|
   266     |activeProcess wasBlocked|
   267 
   267 
   268     wasBlocked := OperatingSystem blockInterrupts.
   268     wasBlocked := OperatingSystem blockInterrupts.
   269 
   269 
   270     Transcript showCR:'  waitForRead in state ',state.
   270     "/ Transcript showCR:'  waitForRead in state ',state.
   271     (state == StateFree or:[state == StateBusy]) ifFalse:[
   271     (state == StateFree or:[state == StateBusy]) ifFalse:[
   272         "being written; wait until released"
   272         "being written; wait until released"
   273         activeProcess := Processor activeProcess.
   273         activeProcess := Processor activeProcess.
   274         [
   274         [
   275             self addWaitingProcess:activeProcess.
   275             self addWaitingProcess:activeProcess.
   298 
   298 
   299     |activeProcess wasBlocked|
   299     |activeProcess wasBlocked|
   300 
   300 
   301     wasBlocked := OperatingSystem blockInterrupts.
   301     wasBlocked := OperatingSystem blockInterrupts.
   302 
   302 
   303     Transcript showCR:'  waitForWrite in state ',state.
   303     "/ Transcript showCR:'  waitForWrite in state ',state.
   304     state ~~ StateFree ifTrue:[
   304     state ~~ StateFree ifTrue:[
   305         "being read or written"
   305         "being read or written"
   306         state == StateBusy ifTrue:[
   306         state == StateBusy ifTrue:[
   307             "/ no new readers
   307             "/ no new readers
   308             state := StateWantLock
   308             state := StateWantLock
   331 ! !
   331 ! !
   332 
   332 
   333 !BoltLock class methodsFor:'documentation'!
   333 !BoltLock class methodsFor:'documentation'!
   334 
   334 
   335 version
   335 version
   336     ^ '$Header: /cvs/stx/stx/libbasic2/BoltLock.st,v 1.3 2012-08-06 15:12:30 cg Exp $'
   336     ^ '$Header: /cvs/stx/stx/libbasic2/BoltLock.st,v 1.4 2012-08-06 15:13:43 cg Exp $'
   337 !
   337 !
   338 
   338 
   339 version_CVS
   339 version_CVS
   340     ^ '$Header: /cvs/stx/stx/libbasic2/BoltLock.st,v 1.3 2012-08-06 15:12:30 cg Exp $'
   340     ^ '$Header: /cvs/stx/stx/libbasic2/BoltLock.st,v 1.4 2012-08-06 15:13:43 cg Exp $'
   341 ! !
   341 ! !
   342 
   342 
   343 BoltLock initialize!
   343 BoltLock initialize!