From 8594b65bf640c54efb08038642a7ae490b05bb14 Mon Sep 17 00:00:00 2001 From: Robert Blackwell Date: Tue, 10 Sep 2024 14:20:39 -0400 Subject: [PATCH] fftw_lock: share lock and init between float/double --- src/finufft.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/finufft.cpp b/src/finufft.cpp index c9552e7ad..2528dbc60 100644 --- a/src/finufft.cpp +++ b/src/finufft.cpp @@ -86,9 +86,9 @@ namespace finufft { namespace common { #ifndef FINUFFT_USE_DUCC0 -// Technically global state... -// Needs to be static to avoid name collision with SINGLE/DOUBLE -static std::mutex fftw_lock; +// The only global state in finufft. Inline ensures variables shared between float/double +inline std::mutex fftw_lock; +inline bool did_fftw_init = false; class FFTWLockGuard { public: @@ -692,7 +692,6 @@ int FINUFFT_MAKEPLAN(int type, int dim, BIGINT *n_modes, int iflag, int ntrans, // Now place FFTW initialization in a lock, courtesy of OMP. Makes FINUFFT // thread-safe (can be called inside OMP) { - static bool did_fftw_init = false; // the only global state of FINUFFT FFTWLockGuard lock(p->opts.fftw_lock_fun, p->opts.fftw_unlock_fun, p->opts.fftw_lock_data); if (!did_fftw_init) {