Skip to content

Commit ea212dd

Browse files
committed
using pymutex on object creation
1 parent e7104b7 commit ea212dd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

quaddtype/numpy_quaddtype/src/scalar.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,22 @@
1515
#include "scalar_ops.h"
1616
#include "dragon4.h"
1717

18+
#ifdef Py_GIL_DISABLED
19+
static PyMutex quad_creation_mutex = {0};
20+
#endif
21+
1822
QuadPrecisionObject *
1923
QuadPrecision_raw_new(QuadBackendType backend)
2024
{
21-
QuadPrecisionObject *new = PyObject_New(QuadPrecisionObject, &QuadPrecision_Type);
25+
QuadPrecisionObject *new;
26+
#ifdef Py_GIL_DISABLED
27+
PyMutex_Lock(&quad_creation_mutex);
28+
#endif
29+
new = PyObject_New(QuadPrecisionObject, &QuadPrecision_Type);
30+
#ifdef Py_GIL_DISABLED
31+
PyMutex_Unlock(&quad_creation_mutex);
32+
#endif
33+
2234
if (!new)
2335
return NULL;
2436
new->backend = backend;

0 commit comments

Comments
 (0)