Commit a63fe911 authored by Stefan Behnel's avatar Stefan Behnel

Configure THREAD_LOCKS_PREALLOCATED in MemoryView.pyx via Tempita code...

Configure THREAD_LOCKS_PREALLOCATED in MemoryView.pyx via Tempita code generation rather than a DEF statement (as we ask users to do as well).

See https://github.com/cython/cython/issues/4310
parent 90cd6add
...@@ -814,6 +814,7 @@ context = { ...@@ -814,6 +814,7 @@ context = {
'max_dims': Options.buffer_max_dims, 'max_dims': Options.buffer_max_dims,
'memviewslice_name': memviewslice_cname, 'memviewslice_name': memviewslice_cname,
'memslice_init': PyrexTypes.MemoryViewSliceType.default_value, 'memslice_init': PyrexTypes.MemoryViewSliceType.default_value,
'THREAD_LOCKS_PREALLOCATED': 8,
} }
memviewslice_declare_code = load_memview_c_utility( memviewslice_declare_code = load_memview_c_utility(
"MemviewSliceStruct", "MemviewSliceStruct",
......
...@@ -320,17 +320,11 @@ cdef void *align_pointer(void *memory, size_t alignment) nogil: ...@@ -320,17 +320,11 @@ cdef void *align_pointer(void *memory, size_t alignment) nogil:
# pre-allocate thread locks for reuse # pre-allocate thread locks for reuse
## note that this could be implemented in a more beautiful way in "normal" Cython, ## note that this could be implemented in a more beautiful way in "normal" Cython,
## but this code gets merged into the user module and not everything works there. ## but this code gets merged into the user module and not everything works there.
DEF THREAD_LOCKS_PREALLOCATED = 8
cdef int __pyx_memoryview_thread_locks_used = 0 cdef int __pyx_memoryview_thread_locks_used = 0
cdef PyThread_type_lock[THREAD_LOCKS_PREALLOCATED] __pyx_memoryview_thread_locks = [ cdef PyThread_type_lock[{{THREAD_LOCKS_PREALLOCATED}}] __pyx_memoryview_thread_locks = [
PyThread_allocate_lock(), {{for _ in range(THREAD_LOCKS_PREALLOCATED)}}
PyThread_allocate_lock(),
PyThread_allocate_lock(),
PyThread_allocate_lock(),
PyThread_allocate_lock(),
PyThread_allocate_lock(),
PyThread_allocate_lock(),
PyThread_allocate_lock(), PyThread_allocate_lock(),
{{endfor}}
] ]
...@@ -360,7 +354,7 @@ cdef class memoryview: ...@@ -360,7 +354,7 @@ cdef class memoryview:
Py_INCREF(Py_None) Py_INCREF(Py_None)
global __pyx_memoryview_thread_locks_used global __pyx_memoryview_thread_locks_used
if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: if __pyx_memoryview_thread_locks_used < {{THREAD_LOCKS_PREALLOCATED}}:
self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
__pyx_memoryview_thread_locks_used += 1 __pyx_memoryview_thread_locks_used += 1
if self.lock is NULL: if self.lock is NULL:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment