Skip to content

Commit

Permalink
Remove extra critical region
Browse files Browse the repository at this point in the history
  • Loading branch information
guillep committed Jun 25, 2018
1 parent 80e04ee commit 2e012d5
Showing 1 changed file with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,25 @@ checkFinishedChildren
It looks like waitpid ignores the first argument if WNOHANG is specified, and returns with ANY child process id.
This means that, in combination with the previous issue, it may happen that calling waitpid for process X will unregister process Y, what will make fail a subsequent call to waitpid from Y.
"

| waitedChildren childrenSize |

accessProtect critical:[
"Skip checking if we have no children"
waitedChildren := 0.
childrenSize := childProcessList count: [ :process | process isRunning ].

[ waitedChildren < childrenSize ] whileTrue: [ | statusPointer |
[ | status returnValue |
statusPointer := ExternalAddress allocate: systemAccessor sizeOfInt.
returnValue := self
primitiveWaitpid: -1
statusPointer: statusPointer
options: WNOHANG.

"Skip checking if we have no children"
waitedChildren := 0.
childrenSize := self activeChildren size.
[ waitedChildren < childrenSize ]
whileTrue: [ | statusPointer |
[ | status returnValue |
statusPointer := ExternalAddress allocate: systemAccessor sizeOfInt.
returnValue := self primitiveWaitpid: -1 statusPointer: statusPointer options: WNOHANG.

"If return value is 0 then there are no more changes, we can exit"
returnValue = 0 ifTrue: [
^ self ].
returnValue = 0
ifTrue: [ ^ self ].

"Only throw error in case it is an error other than no childs (represented as return -1 and errno=ECHILD)"
(returnValue = -1)
ifTrue: [ systemAccessor perror: 'waitpid()' ].

returnValue = -1
ifTrue: [ systemAccessor perror: 'waitpid()' ].
waitedChildren := waitedChildren + 1.
status := statusPointer platformLongAt: 1.
self updateChildProcessWithId: returnValue withStatus: status.
] ensure: [ statusPointer free ] ] ]
self updateChildProcessWithId: returnValue withStatus: status ]
ensure: [ statusPointer free ] ]

0 comments on commit 2e012d5

Please sign in to comment.