Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PortToP11] 17029-Image-crash-or-errors-when-openning-another-developper-Pharo-11-image #17583

Open
wants to merge 1 commit into
base: Pharo11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/ThreadedFFI-UFFI-Tests/TFUFFIConcurrencyTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Class {
#name : #TFUFFIConcurrencyTest,
#superclass : #TFUFFITestCase,
#instVars : [
'p1',
'p2'
],
#category : #'ThreadedFFI-UFFI-Tests'
}

{ #category : #'ffi-calls' }
TFUFFIConcurrencyTest >> booleanToInt: boolean [

^ self ffiCall: #(int id_int(Boolean boolean))
]

{ #category : #'ffi-calls' }
TFUFFIConcurrencyTest >> methodCallingBooleanToInt [

^ self booleanToInt: true
]

{ #category : #running }
TFUFFIConcurrencyTest >> tearDown [

FFIMethodRegistry uniqueInstance resetSingleClass: self class.

p1 ifNotNil: #terminate.
p2 ifNotNil: #terminate.

(self class >> #booleanToInt: hasProperty: #ffiNonCompiledMethod)
ifTrue: [
self class compile: '
booleanToInt: boolean

^ self ffiCall: #(int id_int(Boolean boolean)) ' ].
super tearDown
]

{ #category : #tests }
TFUFFIConcurrencyTest >> testConcurrentlyCompiling [

| barrier finish installedMethod nonCompiledMethod |
self deny:
(self class >> #booleanToInt: hasProperty: #ffiNonCompiledMethod).

barrier := Semaphore new.
finish := Semaphore new.


p1 := [
[
barrier wait.
self methodCallingBooleanToInt.
finish signal ] repeat ] forkAt: 39.

p2 := [
[
barrier wait.
self methodCallingBooleanToInt.
finish signal ] repeat ] forkAt: 39.

500 timesRepeat: [

FFIMethodRegistry uniqueInstance resetSingleClass: self class.

barrier
signal;
signal.
finish
wait;
wait.

installedMethod := self class >> #booleanToInt:.
nonCompiledMethod := installedMethod propertyAt:
#ffiNonCompiledMethod.

self assert: (installedMethod hasProperty: #ffiNonCompiledMethod).
self deny: (nonCompiledMethod hasProperty: #ffiNonCompiledMethod) ]
]
2 changes: 1 addition & 1 deletion src/UnifiedFFI/FFICalloutAPI.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ FFICalloutAPI >> function: functionSignature library: moduleNameOrLibrary [
methodClass: sender methodClass. "Replace with generated ffi method, but save old one for future use"
ffiMethod
propertyAt: #ffiNonCompiledMethod
put: (sender methodClass methodDict at: sender selector). "For senders search, one need to keep the selector in the properties"
put: sender method. "For senders search, one need to keep the selector in the properties"
ffiMethod propertyAt: #ffiMethodSelector put: ffiMethodSelector.
sender methodClass methodDict at: sender selector put: ffiMethod. "Register current method as compiled for ffi"
FFIMethodRegistry uniqueInstance registerMethod: ffiMethod. "Resend"
Expand Down