Fixes for GDBInternalPipeStream w.r.t multiple threads.
--- a/GDBInternalPipeStream.st Sat Sep 06 01:02:51 2014 +0100
+++ b/GDBInternalPipeStream.st Sun Sep 07 08:20:01 2014 +0100
@@ -227,7 +227,7 @@
space ifTrue:[
last == 0 ifTrue:[
"/ Special case - empty buffer
- write := remaining min: bytes size.
+ write := remaining min: buffer size.
buffer replaceFrom:1 to: write with: bytes startingAt: offset.
last := write.
] ifFalse:[
@@ -246,14 +246,14 @@
remaining := remaining - write.
written := written + write.
offset := offset + write.
- dataAvailable signalForAll.
+ dataAvailable signalForAll.
].
].
].
^ written.
"Created: / 09-06-2014 / 22:04:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 11-06-2014 / 22:59:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 07-09-2014 / 08:15:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GDBInternalPipeStream methodsFor:'private'!
@@ -321,11 +321,12 @@
| hasSpace |
accessLock critical:[ hasSpace := self hasSpace ].
- hasSpace ifTrue:[
+ hasSpace ifFalse:[
spaceAvailable wait.
].
"Created: / 11-06-2014 / 22:04:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 07-09-2014 / 08:17:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GDBInternalPipeStream methodsFor:'writing'!
@@ -391,7 +392,7 @@
].
"Created: / 09-06-2014 / 21:57:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 11-06-2014 / 23:04:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 06-09-2014 / 16:35:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GDBInternalPipeStream class methodsFor:'documentation'!
--- a/tests/GDBInternalPipeStreamTests.st Sat Sep 06 01:02:51 2014 +0100
+++ b/tests/GDBInternalPipeStreamTests.st Sun Sep 07 08:20:01 2014 +0100
@@ -259,6 +259,246 @@
"Created: / 11-06-2014 / 13:19:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 11-06-2014 / 21:39:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_07a
+ | pipe t1 t1stepper t1blocker t2 t2stepper t2blocker c |
+
+ pipe := GDBInternalPipeStream newWithBufferSize:5.
+ t1stepper := Semaphore new.
+ t1blocker := Semaphore new.
+ t2stepper := Semaphore new.
+ t2blocker := Semaphore new.
+
+
+ t1 := [
+ t1stepper wait.
+ pipe nextPutAll: '123456'.
+ ] newProcess.
+ t1 addExitAction:[t1blocker signal].
+
+ t2 := [
+ t2stepper wait.
+ c := pipe next.
+ ] newProcess.
+ t2 addExitAction:[t2blocker signal].
+
+ t1 resume.
+ t2 resume.
+
+ t1stepper signal.
+ Delay waitForMilliseconds:100.
+ t2stepper signal.
+
+ t1blocker wait.
+ t2blocker wait.
+
+ self assert: c = $1.
+ self assert: t1 isDead.
+ self assert: t2 isDead.
+
+ "Created: / 07-09-2014 / 07:45:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_07b
+ | pipe t1 t1stepper t1blocker t2 t2stepper t2blocker c |
+
+ pipe := GDBInternalPipeStream newWithBufferSize:5.
+ t1stepper := Semaphore new.
+ t1blocker := Semaphore new.
+ t2stepper := Semaphore new.
+ t2blocker := Semaphore new.
+
+
+ t1 := [
+ t1stepper wait.
+ pipe nextPutAll: '123456'.
+ t1blocker signal.
+ ] newProcess.
+
+ t2 := [
+ t2stepper wait.
+ c := pipe next.
+ t2blocker signal.
+ ] newProcess.
+
+ t1 resume.
+ t2 resume.
+
+ t2stepper signal.
+ Delay waitForMilliseconds:100.
+ t1stepper signal.
+
+
+ t1blocker wait.
+ t2blocker wait.
+
+ self assert: c = $1.
+ self assert: t1 isDead.
+ self assert: t2 isDead.
+
+ "Created: / 07-09-2014 / 07:46:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_08a
+ | pipe t1 t1stepper t1blocker t2 t2stepper t2blocker c |
+
+ pipe := GDBInternalPipeStream newWithBufferSize:5.
+ t1stepper := Semaphore new.
+ t1blocker := Semaphore new.
+ t2stepper := Semaphore new.
+ t2blocker := Semaphore new.
+
+
+ t1 := [
+ t1stepper wait.
+ pipe nextPutAll: '123456'.
+ t1blocker signal.
+ ] newProcess.
+ t1 addExitAction:[t1blocker signal].
+
+ t2 := [
+ t2stepper wait.
+ c := pipe next:6.
+ ] newProcess.
+ t2 addExitAction:[t2blocker signal].
+
+ t1 resume.
+ t2 resume.
+
+ t1stepper signal.
+ Delay waitForMilliseconds:100.
+ t2stepper signal.
+
+
+ t1blocker wait.
+ t2blocker wait.
+
+ self assert: c = '123456'.
+ self assert: t1 isDead.
+ self assert: t2 isDead.
+
+ "Created: / 07-09-2014 / 07:48:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_08b
+ | pipe t1 t1stepper t1blocker t2 t2stepper t2blocker c |
+
+ pipe := GDBInternalPipeStream newWithBufferSize:5.
+ t1stepper := Semaphore new.
+ t1blocker := Semaphore new.
+ t2stepper := Semaphore new.
+ t2blocker := Semaphore new.
+
+
+ t1 := [
+ t1stepper wait.
+ pipe nextPutAll: '123456'.
+ ] newProcess.
+ t1 addExitAction:[t1blocker signal].
+
+ t2 := [
+ t2stepper wait.
+ c := pipe next:6.
+ ] newProcess.
+ t2 addExitAction:[t2blocker signal].
+
+ t1 resume.
+ t2 resume.
+
+ t2stepper signal.
+ Delay waitForMilliseconds:100.
+ t1stepper signal.
+
+
+ t1blocker wait.
+ t2blocker wait.
+
+ self assert: c = '123456'.
+ self assert: t1 isDead.
+ self assert: t2 isDead.
+
+ "Created: / 07-09-2014 / 07:48:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_09a
+ | pipe t1 t1stepper t1blocker t2 t2stepper t2blocker c |
+
+ pipe := GDBInternalPipeStream newWithBufferSize:5.
+ t1stepper := Semaphore new.
+ t1blocker := Semaphore new.
+ t2stepper := Semaphore new.
+ t2blocker := Semaphore new.
+
+
+ t1 := [
+ t1stepper wait.
+ pipe nextPutAll: '1234567'.
+ ] newProcess.
+ t1 addExitAction:[t1blocker signal].
+
+ t2 := [
+ t2stepper wait.
+ c := pipe next:7.
+ ] newProcess.
+ t2 addExitAction:[t2blocker signal].
+
+ t1 resume.
+ t2 resume.
+
+ t1stepper signal.
+ Delay waitForMilliseconds:100.
+ t2stepper signal.
+
+
+ t1blocker wait.
+ t2blocker wait.
+
+ self assert: c = '1234567'.
+ self assert: t1 isDead.
+ self assert: t2 isDead.
+
+ "Created: / 07-09-2014 / 07:50:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_09b
+ | pipe t1 t1stepper t1blocker t2 t2stepper t2blocker c |
+
+ pipe := GDBInternalPipeStream newWithBufferSize:5.
+ t1stepper := Semaphore new.
+ t1blocker := Semaphore new.
+ t2stepper := Semaphore new.
+ t2blocker := Semaphore new.
+
+
+ t1 := [
+ t1stepper wait.
+ pipe nextPutAll: '1234567'.
+ ] newProcess.
+ t1 addExitAction:[t1blocker signal].
+
+ t2 := [
+ t2stepper wait.
+ c := pipe next:7.
+ ] newProcess.
+ t2 addExitAction:[t2blocker signal].
+
+ t1 resume.
+ t2 resume.
+
+ t2stepper signal.
+ Delay waitForMilliseconds:100.
+ t1stepper signal.
+
+
+ t1blocker wait.
+ t2blocker wait.
+
+ self assert: c = '1234567'.
+ self assert: t1 isDead.
+ self assert: t2 isDead.
+
+ "Created: / 07-09-2014 / 07:51:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GDBInternalPipeStreamTests class methodsFor:'documentation'!