Skip to content

Commit b9e0000

Browse files
committed
reentrant trylock should be okay in maybe_destroy_plan
1 parent 23ab25e commit b9e0000

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/fft.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ unsafe_destroy_plan(plan::FFTWPlan{<:fftwSingle}) =
275275
const deferred_destroy_lock = ReentrantLock() # lock protecting the deferred_destroy_plans list
276276
const deferred_destroy_plans = FFTWPlan[]
277277

278-
# hack to get non-reentrant lock, which is necessary to ensure that GC running in the
279-
# same task that acquired fftwlock will use deferred_destroy_plans in maybe_destroy_plan.
280-
trylock_nonreentrant(rl::ReentrantLock) = current_task() !== rl.locked_by && trylock(rl)
281-
282278
function destroy_deferred()
283279
lock(deferred_destroy_lock)
284280
try
@@ -306,7 +302,11 @@ function maybe_destroy_plan(plan::FFTWPlan)
306302
# then we push a deferred plan that may never get freed)
307303
lock(deferred_destroy_lock)
308304
try
309-
if trylock_nonreentrant(fftwlock)
305+
# note: fftwlock is re-entrant, so trylock will succeed here if we
306+
# are in the task that holds the planner lock. That's okay — 
307+
# re-entrant calls to destroy_plan in the planner thread
308+
# should be fine as long as we didn't call make_planner_thread_safe.
309+
if trylock(fftwlock)
310310
try
311311
unsafe_destroy_plan(plan)
312312
finally

0 commit comments

Comments
 (0)