@@ -8,8 +8,9 @@ See [`gc`](@ref).
88module GC
99
1010using .. C: C
11+ using .. Utils: Lockable
1112
12- const QUEUE = (; items = C. PyPtr[], lock = Threads. SpinLock ())
13+ const QUEUE = Lockable ( C. PyPtr[], Threads. SpinLock ())
1314const HOOK = Ref {WeakRef} ()
1415
1516"""
@@ -67,13 +68,13 @@ function gc()
6768end
6869
6970function 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[]
7273 if ptr != C. PyNULL
7374 C. Py_DecRef (ptr)
7475 end
7576 end
76- empty! (QUEUE. items )
77+ empty! (QUEUE[] )
7778 end
7879 nothing
7980end
@@ -87,7 +88,7 @@ function enqueue(ptr::C.PyPtr)
8788 # If the current thread holds the GIL, then we can immediately free.
8889 C. Py_DecRef (ptr)
8990 # We may as well also free any other enqueued objects.
90- if ! isempty (QUEUE. items )
91+ if ! isempty (QUEUE. value )
9192 unsafe_free_queue ()
9293 end
9394 else
@@ -96,7 +97,7 @@ function enqueue(ptr::C.PyPtr)
9697 # in the branch above.
9798 # (b) If the GCHook() object below is finalized in an ordinary GC.
9899 # (c) If the user calls PythonCall.GC.gc().
99- Base. @lock QUEUE. lock push! (QUEUE. items , ptr)
100+ Base. @lock QUEUE push! (QUEUE[] , ptr)
100101 end
101102 end
102103 nothing
@@ -110,11 +111,11 @@ function enqueue_all(ptrs)
110111 C. Py_DecRef (ptr)
111112 end
112113 end
113- if ! isempty (QUEUE. items )
114+ if ! isempty (QUEUE. value )
114115 unsafe_free_queue ()
115116 end
116117 else
117- Base. @lock QUEUE. lock append! (QUEUE. items , ptrs)
118+ Base. @lock QUEUE append! (QUEUE[] , ptrs)
118119 end
119120 end
120121 nothing
139140function _gchook_finalizer (x)
140141 if C. CTX. is_initialized
141142 finalizer (_gchook_finalizer, x)
142- if ! isempty (QUEUE. items ) && C. PyGILState_Check () == 1
143+ if ! isempty (QUEUE. value ) && C. PyGILState_Check () == 1
143144 unsafe_free_queue ()
144145 end
145146 end
0 commit comments