forked from ObjectProfile/PythonBridge
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPBObjectRegistry.class.st
More file actions
56 lines (47 loc) · 1.27 KB
/
PBObjectRegistry.class.st
File metadata and controls
56 lines (47 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Class {
#name : #PBObjectRegistry,
#superclass : #Object,
#instVars : [
'objectTable',
'semaphore',
'idTable'
],
#category : #'PythonBridge-Execution'
}
{ #category : #'as yet unclassified' }
PBObjectRegistry >> hasId: anId [
^ semaphore critical: [ idTable includesKey: anId ]
]
{ #category : #'as yet unclassified' }
PBObjectRegistry >> idTable [
^ idTable
]
{ #category : #'as yet unclassified' }
PBObjectRegistry >> initialize [
super initialize.
idTable := WeakValueDictionary new.
semaphore := Semaphore forMutualExclusion
]
{ #category : #'as yet unclassified' }
PBObjectRegistry >> registerObject: anObject [
semaphore critical: [
idTable at: anObject id put: anObject ]
]
{ #category : #'as yet unclassified' }
PBObjectRegistry >> resolve: anId [
^ semaphore critical: [ idTable at: anId ]
]
{ #category : #'as yet unclassified' }
PBObjectRegistry >> resolve: anId ifAbsent: aBlock [
| obj |
obj := semaphore critical: [ idTable at: anId ifAbsent: [ nil ] ].
^ obj ifNil: aBlock.
]
{ #category : #'as yet unclassified' }
PBObjectRegistry >> unregisterId: anId [
semaphore critical: [ idTable removeKey: anId ]
]
{ #category : #'as yet unclassified' }
PBObjectRegistry >> unregisterObject: anObject [
semaphore critical: [ idTable removeKey: anObject id ]
]