summaryrefslogtreecommitdiff
path: root/numpy/fft/fftpack.py
diff options
context:
space:
mode:
authorAlex Stewart <foogod@gmail.com>2014-05-06 09:15:53 -0700
committerAlex Stewart <foogod@gmail.com>2014-05-06 09:15:53 -0700
commit15f02e2515cf879900d5cb27adba23ab0e0ce235 (patch)
tree56e52970bf6edea8602376df6fc968811d432a6f /numpy/fft/fftpack.py
parente24486e15f9f71f63bdbc4309bcaf40e70ce7e31 (diff)
downloadnumpy-15f02e2515cf879900d5cb27adba23ab0e0ce235.tar.gz
Add comments to clarify cache handling in _raw_fft
Diffstat (limited to 'numpy/fft/fftpack.py')
-rw-r--r--numpy/fft/fftpack.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/numpy/fft/fftpack.py b/numpy/fft/fftpack.py
index 7ee0e4bea..236a18d7a 100644
--- a/numpy/fft/fftpack.py
+++ b/numpy/fft/fftpack.py
@@ -53,6 +53,9 @@ def _raw_fft(a, n=None, axis=-1, init_function=fftpack.cffti,
raise ValueError("Invalid number of FFT data points (%d) specified." % n)
try:
+ # Thread-safety note: We rely on list.pop() here to atomically
+ # retrieve-and-remove a wsave from the cache. This ensures that no
+ # other thread can get the same wsave while we're using it.
wsave = fft_cache.setdefault(n, []).pop()
except (IndexError):
wsave = init_function(n)
@@ -76,7 +79,12 @@ def _raw_fft(a, n=None, axis=-1, init_function=fftpack.cffti,
r = work_function(a, wsave)
if axis != -1:
r = swapaxes(r, axis, -1)
+
+ # As soon as we put wsave back into the cache, another thread could pick it
+ # up and start using it, so we must not do this until after we're
+ # completely done using it ourselves.
fft_cache[n].append(wsave)
+
return r