Compatibility: allow ports to customize semaphore / mutex creation
This commit adds new port methods: `#newSemaphore` and `#newMutex`.
This allows ports to return customized objects. This is needed to accomodate
different implementations / behaviors of semaphores among dialects (e.g, Pharo)
--- a/GDBDebugger.st Fri Aug 18 14:10:59 2023 +0100
+++ b/GDBDebugger.st Fri Aug 18 14:25:54 2023 +0100
@@ -418,7 +418,7 @@
"/ self
"/ assert:Processor activeProcess ~~ connection eventDispatchProcess
"/ message:'Cannot send commands from within event dispatching process. Would deadlock'.
- blocker := Semaphore new.
+ blocker := GDBPortlib current newSemaphore.
self send: command andWithResultDo: [ :r |
result := r.
blocker signal
@@ -444,7 +444,7 @@
"Created: / 02-06-2014 / 23:45:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 26-03-2018 / 21:19:59 / jv"
"Modified: / 28-01-2019 / 21:26:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 22-02-2022 / 13:17:28 / Jan Vrany <jan.vrany@labware.com>"
+ "Modified: / 18-08-2023 / 14:17:04 / Jan Vrany <jan.vrany@labware.com>"
!
send:command andWaitFor:eventHandlers
@@ -733,7 +733,7 @@
"Created: / 05-06-2017 / 17:05:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 09-02-2018 / 09:44:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified (comment): / 19-09-2022 / 23:10:41 / Jan Vrany <jan.vrany@labware.com>"
+ "Modified: / 18-08-2023 / 14:11:27 / Jan Vrany <jan.vrany@labware.com>"
!
exit
@@ -1020,7 +1020,7 @@
self announcer when:GDBEvent do:(handlersArray at:i).
].
handlerFinal := [ :event | connection eventAnnouncerInternal unsubscribe: handlerFinal. blocker signal ].
- blocker := Semaphore new.
+ blocker := GDBPortlib current newSemaphore.
block value.
[
(blocker waitWithTimeoutMs:timeout) isNil ifTrue:[
@@ -1044,7 +1044,7 @@
"Created: / 08-03-2015 / 07:28:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 02-10-2018 / 14:26:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified (format): / 03-10-2018 / 12:58:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 10-09-2021 / 15:41:33 / Jan Vrany <jan.vrany@labware.com>"
+ "Modified: / 18-08-2023 / 14:16:58 / Jan Vrany <jan.vrany@labware.com>"
! !
!GDBDebugger methodsFor:'event handling'!
--- a/GDBInternalPipeStream.st Fri Aug 18 14:10:59 2023 +0100
+++ b/GDBInternalPipeStream.st Fri Aug 18 14:25:54 2023 +0100
@@ -193,14 +193,15 @@
first := 1.
last := 0.
- accessLock := Semaphore forMutualExclusion." Plug new respondTo: #critical: with: [ :block | block value ]; yourself."
- dataAvailable := Semaphore new.
- spaceAvailable := Semaphore new.
+ accessLock := GDBPortlib current newMutex." Plug new respondTo: #critical: with: [ :block | block value ]; yourself."
+ dataAvailable := GDBPortlib current newSemaphore.
+ spaceAvailable := GDBPortlib current newSemaphore.
closed := false
"Created: / 07-06-2014 / 00:49:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 11-06-2014 / 23:12:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 18-08-2023 / 14:18:17 / Jan Vrany <jan.vrany@labware.com>"
! !
!GDBInternalPipeStream methodsFor:'non homogenous reading'!
--- a/GDBPortlib.st Fri Aug 18 14:10:59 2023 +0100
+++ b/GDBPortlib.st Fri Aug 18 14:25:54 2023 +0100
@@ -146,6 +146,20 @@
^ NonPositionableExternalStream makePipe
! !
+!GDBPortlib methodsFor:'synchronization'!
+
+newMutex
+ ^ Semaphore forMutualExclusion
+
+ "Created: / 18-08-2023 / 14:17:36 / Jan Vrany <jan.vrany@labware.com>"
+!
+
+newSemaphore
+ ^ Semaphore new
+
+ "Created: / 18-08-2023 / 14:16:31 / Jan Vrany <jan.vrany@labware.com>"
+! !
+
!GDBPortlib methodsFor:'user interface'!
newCLI: aGDBDebugger
--- a/ports/pharo/src/LibGDBs-Internal-Portlib-Pharo/GDBPortlibPharo.class.st Fri Aug 18 14:10:59 2023 +0100
+++ b/ports/pharo/src/LibGDBs-Internal-Portlib-Pharo/GDBPortlibPharo.class.st Fri Aug 18 14:25:54 2023 +0100
@@ -62,6 +62,14 @@
]
+{ #category : #synchronization }
+GDBPortlibPharo >> newMutex [
+ ^ Mutex new
+
+ "Created: / 18-08-2023 / 14:17:36 / Jan Vrany <jan.vrany@labware.com>"
+
+]
+
{ #category : #streams }
GDBPortlibPharo >> newPTY [
"Allocate a PTY and return it as an instance of GDBPTY"