Skip to content

Commit fa6a116

Browse files
refactor: use PyMutex in socket module
1 parent 46b5e3e commit fa6a116

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

Modules/socketmodule.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ new_sockobject(socket_state *state, SOCKET_T fd, int family, int type,
11701170
/* Lock to allow python interpreter to continue, but only allow one
11711171
thread to be in gethostbyname or getaddrinfo */
11721172
#if defined(USE_GETHOSTBYNAME_LOCK)
1173-
static PyThread_type_lock netdb_lock;
1173+
static PyMutex netdb_lock;
11741174
#endif
11751175

11761176

@@ -6217,7 +6217,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
62176217
#endif
62186218
#else /* not HAVE_GETHOSTBYNAME_R */
62196219
#ifdef USE_GETHOSTBYNAME_LOCK
6220-
PyThread_acquire_lock(netdb_lock, 1);
6220+
PyMutex_Lock(&netdb_lock);
62216221
#endif
62226222
_Py_COMP_DIAG_PUSH
62236223
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
@@ -6233,7 +6233,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
62336233
ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr),
62346234
sa->sa_family);
62356235
#ifdef USE_GETHOSTBYNAME_LOCK
6236-
PyThread_release_lock(netdb_lock);
6236+
PyMutex_Unlock(&netdb_lock);
62376237
#endif
62386238
finally:
62396239
PyMem_Free(name);
@@ -6324,7 +6324,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
63246324
#endif
63256325
#else /* not HAVE_GETHOSTBYNAME_R */
63266326
#ifdef USE_GETHOSTBYNAME_LOCK
6327-
PyThread_acquire_lock(netdb_lock, 1);
6327+
PyMutex_Lock(&netdb_lock);
63286328
#endif
63296329
_Py_COMP_DIAG_PUSH
63306330
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
@@ -6334,7 +6334,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
63346334
Py_END_ALLOW_THREADS
63356335
ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr), af);
63366336
#ifdef USE_GETHOSTBYNAME_LOCK
6337-
PyThread_release_lock(netdb_lock);
6337+
PyMutex_Unlock(&netdb_lock);
63386338
#endif
63396339
finally:
63406340
PyMem_Free(ip_num);
@@ -9290,14 +9290,6 @@ socket_exec(PyObject *m)
92909290
#endif
92919291
#endif /* _MSTCPIP_ */
92929292

9293-
/* Initialize gethostbyname lock */
9294-
#if defined(USE_GETHOSTBYNAME_LOCK)
9295-
netdb_lock = PyThread_allocate_lock();
9296-
if (netdb_lock == NULL) {
9297-
goto error;
9298-
}
9299-
#endif
9300-
93019293
#ifdef MS_WINDOWS
93029294
/* remove some flags on older version Windows during run-time */
93039295
if (remove_unusable_flags(m) < 0) {

0 commit comments

Comments
 (0)