Hi All,
I realized I need to protect the ordered collections from being changed by a fork while in the middle of a change from another fork (see my other post about makeFixed/makeFree).
Is there any reason I need more than [] critical like using aSemaphore critical: []? See the code below.
I don't think so but sometimes the reasons are not obvious.
Lou
inputBuffer: receiveType
"Answer an input buffer for the receive type (String or ByteArray). Put the buffer in fixed space."
"Buffers are freed by #freeInputBuffer: and are cleared it that time."
^[ | buffer pool bufferSize |
StringInputBuffers isNil ifTrue: [StringInputBuffers := OrderedCollection new: 100].
ByteArrayInputBuffers isNil ifTrue: [ByteArrayInputBuffers := OrderedCollection new: 100].
bufferSize := 32768. "32 * 1024"
pool := (receiveType == String) ifTrue: [StringInputBuffers] ifFalse: [ByteArrayInputBuffers].
buffer := pool notEmpty ifTrue: [pool removeLast] ifFalse: [receiveType new: bufferSize].
buffer makeFixed.
] critical.
freeInputBuffer: buffer
"Clear and then put the input buffer for the receive type (String or ByteArray) into a pool for reuse."
[
buffer isString ifTrue: [
buffer replaceFrom: 1 to: buffer size withObject: Nul.
StringInputBuffers add: buffer.
] ifFalse: [
buffer replaceFrom: 1 to: buffer size withObject: 0.
ByteArrayInputBuffers add: buffer.
].
] critical.
--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
[hidden email].
To post to this group, send email to
[hidden email].
Visit this group at
https://groups.google.com/group/va-smalltalk.
For more options, visit
https://groups.google.com/d/optout.