Skip to content

Commit

Permalink
Force rescheduling of inactive process when changing its priority
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanecek committed Aug 30, 2024
1 parent 8efb901 commit ee1b272
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Extension { #name : 'ProcessorScheduler' }

{ #category : '*Ansible-Pharo-Pending-Patches' }
ProcessorScheduler >> interpriorityYield: modifiedProcess [
"The original yield only works within processes of the same priority.
The primitive does not try to resume a process in a higher priority.
By suspending and resuming the modified process, we force it to be rescheduled.
When modifying the active process, we must handle the resume from a forked process.
We must also be careful not to resume a process that was suspended to begin with.
(In particular, processes all receive #priority: as part of their creation, before
it is safe to resume them.)
This message should not be used directly.
The only application so far is when changing the priority of a process.
"

modifiedProcess isActive
ifTrue: [
[ modifiedProcess resume ] fork.
modifiedProcess suspend ]
ifFalse: [
(modifiedProcess suspendingList isKindOf: ProcessList) ifTrue: [
modifiedProcess
suspend;
resume ] ]
]
21 changes: 21 additions & 0 deletions source/Ansible-Pharo-Pending-Patches/SocketStream.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,24 @@ SocketStream >> flush [
ifFalse: [ "swallow" ] ].
outNextToWrite := 1 ]
]

{ #category : '*Ansible-Pharo-Pending-Patches' }
SocketStream >> nextPutAllFlush: aCollection [
"Put a String or a ByteArray onto the stream.
You can use this if you have very large data - it avoids
copying into the buffer (and avoids buffer growing)
and also flushes any other pending data first."

| toPut |
toPut := binary
ifTrue: [ aCollection asByteArray ]
ifFalse: [ aCollection asString ].
self flush. "first flush pending stuff, then directly send"
socket isOtherEndClosed ifFalse: [
[ socket sendData: toPut count: toPut size ]
on: NetworkError
do: [ :ex |
shouldSignal
ifTrue: [ ex pass ]
ifFalse: [ "swallow" ] ] ]
]

0 comments on commit ee1b272

Please sign in to comment.