@@ -8,8 +8,9 @@ See [`gc`](@ref).
8
8
module GC
9
9
10
10
using .. C: C
11
+ using .. Utils: Lockable
11
12
12
- const QUEUE = (; items = C. PyPtr[], lock = Threads. SpinLock ())
13
+ const QUEUE = Lockable ( C. PyPtr[], Threads. SpinLock ())
13
14
const HOOK = Ref {WeakRef} ()
14
15
15
16
"""
@@ -67,13 +68,13 @@ function gc()
67
68
end
68
69
69
70
function unsafe_free_queue ()
70
- Base. @lock QUEUE. lock begin
71
- for ptr in QUEUE. items
71
+ Base. @lock QUEUE begin
72
+ for ptr in QUEUE[]
72
73
if ptr != C. PyNULL
73
74
C. Py_DecRef (ptr)
74
75
end
75
76
end
76
- empty! (QUEUE. items )
77
+ empty! (QUEUE[] )
77
78
end
78
79
nothing
79
80
end
@@ -87,7 +88,7 @@ function enqueue(ptr::C.PyPtr)
87
88
# If the current thread holds the GIL, then we can immediately free.
88
89
C. Py_DecRef (ptr)
89
90
# We may as well also free any other enqueued objects.
90
- if ! isempty (QUEUE. items )
91
+ if ! isempty (QUEUE. value )
91
92
unsafe_free_queue ()
92
93
end
93
94
else
@@ -96,7 +97,7 @@ function enqueue(ptr::C.PyPtr)
96
97
# in the branch above.
97
98
# (b) If the GCHook() object below is finalized in an ordinary GC.
98
99
# (c) If the user calls PythonCall.GC.gc().
99
- Base. @lock QUEUE. lock push! (QUEUE. items , ptr)
100
+ Base. @lock QUEUE push! (QUEUE[] , ptr)
100
101
end
101
102
end
102
103
nothing
@@ -110,11 +111,11 @@ function enqueue_all(ptrs)
110
111
C. Py_DecRef (ptr)
111
112
end
112
113
end
113
- if ! isempty (QUEUE. items )
114
+ if ! isempty (QUEUE. value )
114
115
unsafe_free_queue ()
115
116
end
116
117
else
117
- Base. @lock QUEUE. lock append! (QUEUE. items , ptrs)
118
+ Base. @lock QUEUE append! (QUEUE[] , ptrs)
118
119
end
119
120
end
120
121
nothing
139
140
function _gchook_finalizer (x)
140
141
if C. CTX. is_initialized
141
142
finalizer (_gchook_finalizer, x)
142
- if ! isempty (QUEUE. items ) && C. PyGILState_Check () == 1
143
+ if ! isempty (QUEUE. value ) && C. PyGILState_Check () == 1
143
144
unsafe_free_queue ()
144
145
end
145
146
end
0 commit comments