Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Migrate Lock usage in the :mod:`socket` module to :c:type:`PyMutex`.
15 changes: 5 additions & 10 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ new_sockobject(socket_state *state, SOCKET_T fd, int family, int type,
/* Lock to allow python interpreter to continue, but only allow one
thread to be in gethostbyname or getaddrinfo */
#if defined(USE_GETHOSTBYNAME_LOCK)
static PyThread_type_lock netdb_lock;
static PyMutex netdb_lock;
#endif


Expand Down Expand Up @@ -6217,7 +6217,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
#endif
#else /* not HAVE_GETHOSTBYNAME_R */
#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_acquire_lock(netdb_lock, 1);
PyMutex_Lock(&netdb_lock);
#endif
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
Expand All @@ -6233,7 +6233,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr),
sa->sa_family);
#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_release_lock(netdb_lock);
PyMutex_Unlock(&netdb_lock);
#endif
finally:
PyMem_Free(name);
Expand Down Expand Up @@ -6324,7 +6324,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
#endif
#else /* not HAVE_GETHOSTBYNAME_R */
#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_acquire_lock(netdb_lock, 1);
PyMutex_Lock(&netdb_lock);
#endif
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
Expand All @@ -6334,7 +6334,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
Py_END_ALLOW_THREADS
ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr), af);
#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_release_lock(netdb_lock);
PyMutex_Unlock(&netdb_lock);
#endif
finally:
PyMem_Free(ip_num);
Expand Down Expand Up @@ -9290,11 +9290,6 @@ socket_exec(PyObject *m)
#endif
#endif /* _MSTCPIP_ */

/* Initialize gethostbyname lock */
#if defined(USE_GETHOSTBYNAME_LOCK)
netdb_lock = PyThread_allocate_lock();
#endif

#ifdef MS_WINDOWS
/* remove some flags on older version Windows during run-time */
if (remove_unusable_flags(m) < 0) {
Expand Down
Loading