ProcessorScheduler.st
changeset 16319 d38c34400bd0
parent 16317 8da5e8858f22
child 16322 a8391a3cb10a
--- a/ProcessorScheduler.st	Thu Apr 10 17:45:26 2014 +0200
+++ b/ProcessorScheduler.st	Thu Apr 10 21:14:50 2014 +0200
@@ -2414,55 +2414,65 @@
       Or on systems, where we cannot select on a displays eventQ, such as windows)"
 
     |idx "{ Class: SmallInteger }"
-     wasBlocked|
+     wasBlocked slot|
 
     wasBlocked := OperatingSystem blockInterrupts.
 
+    "Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock)
+     aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil"
+
     aFileDescriptor isNil ifTrue:[
-        (idx := readCheckArray identityIndexOf:aSemaphore startingAt:1) == 0 ifTrue:[
-            idx := readFdArray identityIndexOf:nil startingAt:1.
-            idx ~~ 0 ifTrue:[
+        idx := readSemaphoreArray identityIndexOf:aSemaphore or:nil.
+        idx == 0 ifTrue:[
+            "aSemaphore is not registered yet, have to create a new slot"
+            readFdArray := readFdArray copyWith:nil.
+            readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
+            readCheckArray := readCheckArray copyWith:aBlock.
+        ] ifFalse:[
+            slot := readSemaphoreArray at:idx.
+            slot isNil ifTrue:[
+                readSemaphoreArray at:idx put:aSemaphore.
+                readCheckArray at:idx put:aBlock
+            ] ifFalse:[
+                "/ someone has already registered aSemaphore.
+                "/ Check if it is the block changes...
+                (readCheckArray at:idx) notNil ifTrue:[
+                    (readCheckArray at:idx) ~~ aBlock ifTrue:[
+                        'Processor [info]: checkblock changed for read-check' infoPrintCR.
+                        readCheckArray at:idx put:aBlock.
+                    ].
+                ].
+            ].
+        ]
+    ] ifFalse:[
+        idx := readFdArray identityIndexOf:aFileDescriptor or:nil.
+        idx == 0 ifTrue:[
+            "aFileDescriptor is not registered yet, have to create a new slot"
+            readFdArray := readFdArray copyWith:aFileDescriptor.
+            readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
+            readCheckArray := readCheckArray copyWith:aBlock.
+        ] ifFalse:[
+            slot := readFdArray at:idx.
+            slot isNil ifTrue:[
                 readFdArray at:idx put:aFileDescriptor.
                 readSemaphoreArray at:idx put:aSemaphore.
                 readCheckArray at:idx put:aBlock
             ] ifFalse:[
-                readFdArray := readFdArray copyWith:nil.
-                readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
-                readCheckArray := readCheckArray copyWith:aBlock.
-            ]
-        ] ifFalse:[
-            (readCheckArray at:idx) notNil ifTrue:[
+                "/ someone has already registered aFileDescriptor.
+                "/ Check if it is the semaphore or block changes...
+                (readSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[
+                    'Processor [info]: sema changed for read-check' infoPrintCR.
+                    readSemaphoreArray at:idx put:aSemaphore.
+                ].
                 (readCheckArray at:idx) ~~ aBlock ifTrue:[
-                    'ouch - checkblock changed for read-check' infoPrintCR.
+                    'Processor [info]: checkblock changed for read-check' infoPrintCR.
                     readCheckArray at:idx put:aBlock.
-                ]
+                ].
             ].
-        ]
-    ] ifFalse:[
-        (idx := readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
-            idx := readFdArray identityIndexOf:nil startingAt:1.
-            idx ~~ 0 ifTrue:[
-                readFdArray at:idx put:aFileDescriptor.
-                readSemaphoreArray at:idx put:aSemaphore.
-                readCheckArray at:idx put:aBlock
-            ] ifFalse:[
-                readFdArray := readFdArray copyWith:aFileDescriptor.
-                readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
-                readCheckArray := readCheckArray copyWith:aBlock.
-            ].
-            useIOInterrupts ifTrue:[
-                OperatingSystem enableIOInterruptsOn:aFileDescriptor
-            ].
-        ] ifFalse:[
-            (readSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[
-                'ouch - sema changed for read-check' infoPrintCR.
-                readSemaphoreArray at:idx put:aSemaphore.
-            ].
-            (readCheckArray at:idx) ~~ aBlock ifTrue:[
-                'ouch - checkblock changed for read-check' infoPrintCR.
-                readCheckArray at:idx put:aBlock.
-            ].
-        ]
+        ].
+        (useIOInterrupts and:[slot isNil]) ifTrue:[
+            OperatingSystem enableIOInterruptsOn:aFileDescriptor
+        ].
     ].
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
@@ -2503,41 +2513,66 @@
      not know about sockets."
 
     |idx "{ Class: SmallInteger }"
-     wasBlocked|
+     wasBlocked slot|
 
     wasBlocked := OperatingSystem blockInterrupts.
 
+    "Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock)
+     aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil"
+
     aFileDescriptor isNil ifTrue:[
-        (writeCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[
-            idx := writeFdArray identityIndexOf:nil startingAt:1.
-            idx ~~ 0 ifTrue:[
+        idx := writeSemaphoreArray identityIndexOf:aSemaphore or:nil.
+        idx == 0 ifTrue:[
+            "aSemaphore is not registered yet, have to create a new slot"
+            writeFdArray := writeFdArray copyWith:nil.
+            writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
+            writeCheckArray := writeCheckArray copyWith:aBlock.
+        ] ifFalse:[
+            slot := writeSemaphoreArray at:idx.
+            slot isNil ifTrue:[
+                writeSemaphoreArray at:idx put:aSemaphore.
+                writeCheckArray at:idx put:aBlock
+            ] ifFalse:[
+                "/ someone has already registered aSemaphore.
+                "/ Check if it is the block changes...
+                (writeCheckArray at:idx) notNil ifTrue:[
+                    (writeCheckArray at:idx) ~~ aBlock ifTrue:[
+                        'Processor [info]: checkblock changed for write-check' infoPrintCR.
+                        writeCheckArray at:idx put:aBlock.
+                    ].
+                ].
+            ].
+        ]
+    ] ifFalse:[
+        idx := writeFdArray identityIndexOf:aFileDescriptor or:nil.
+        idx == 0 ifTrue:[
+            "aFileDescriptor is not registered yet, have to create a new slot"
+            writeFdArray := writeFdArray copyWith:aFileDescriptor.
+            writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
+            writeCheckArray := writeCheckArray copyWith:aBlock.
+        ] ifFalse:[
+            slot := writeFdArray at:idx.
+            slot isNil ifTrue:[
                 writeFdArray at:idx put:aFileDescriptor.
                 writeSemaphoreArray at:idx put:aSemaphore.
                 writeCheckArray at:idx put:aBlock
             ] ifFalse:[
-                writeFdArray := writeFdArray copyWith:nil.
-                writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
-                writeCheckArray := writeCheckArray copyWith:aBlock.
-            ]
-        ]
-    ] ifFalse:[
-        (writeFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
-            idx := writeFdArray identityIndexOf:nil startingAt:1.
-            idx ~~ 0 ifTrue:[
-                writeFdArray at:idx put:aFileDescriptor.
-                writeSemaphoreArray at:idx put:aSemaphore.
-                writeCheckArray at:idx put:aBlock
-            ] ifFalse:[
-                writeFdArray := writeFdArray copyWith:aFileDescriptor.
-                writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
-                writeCheckArray := writeCheckArray copyWith:aBlock.
+                "/ someone has already registered aFileDescriptor.
+                "/ Check if it is the semaphore or block changes...
+                (writeSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[
+                    'Processor [info]: sema changed for write-check' infoPrintCR.
+                    writeSemaphoreArray at:idx put:aSemaphore.
+                ].
+                (writeCheckArray at:idx) ~~ aBlock ifTrue:[
+                    'Processor [info]: checkblock changed for write-check' infoPrintCR.
+                    writeCheckArray at:idx put:aBlock.
+                ].
             ].
-            useIOInterrupts ifTrue:[
-                OperatingSystem enableIOInterruptsOn:aFileDescriptor
-            ].
-        ]
+        ].
+        (useIOInterrupts and:[slot isNil]) ifTrue:[
+            OperatingSystem enableIOInterruptsOn:aFileDescriptor
+        ].
     ].
-
     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
     "Modified: 4.8.1997 / 15:21:49 / cg"
@@ -3372,11 +3407,11 @@
 !ProcessorScheduler class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.283 2014-04-10 15:40:54 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.284 2014-04-10 19:14:50 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.283 2014-04-10 15:40:54 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.284 2014-04-10 19:14:50 stefan Exp $'
 ! !