8000 gh-134745: Change threading.Lock implementation to PyMutex · python/cpython@0e1fada · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e1fada

Browse files
committed
gh-134745: Change threading.Lock implementation to PyMutex
PyMutex is a fast and portable lock currently only used internally by Python. This change modify _thread.allocate_lock() and threading.Lock to reuse PyMutex.
1 parent 965662e commit 0e1fada

File tree

3 files changed

+15
-321
lines changed

3 files changed

+15
-321
lines changed

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ def test_thread_info(self):
729729
info = sys.thread_info
730730
self.assertEqual(len(info), 3)
731731
self.assertIn(info.name, ('nt', 'pthread', 'pthread-stubs', 'solaris', None))
732-
self.assertIn(info.lock, ('semaphore', 'mutex+cond', None))
732+
self.assertIn(info.lock, ('pymutex', None))
733733
if sys.platform.startswith(("linux", "android", "freebsd")):
734734
self.assertEqual(info.name, "pthread")
735735
elif sys.platform == "win32":

Python/thread.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,7 @@ PyThread_GetInfo(void)
261261
#ifdef HAVE_PTHREAD_STUBS
262262
value = Py_NewRef(Py_None);
263263
#elif defined(_POSIX_THREADS)
264-
#ifdef USE_SEMAPHORES
265-
value = PyUnicode_FromString("semaphore");
266-
#else
267-
value = PyUnicode_FromString("mutex+cond");
268-
#endif
264+
value = PyUnicode_FromString("pymutex");
269265
if (value == NULL) {
270266
Py_DECREF(threadinfo);
271267
return NULL;

0 commit comments

Comments
 (0)
0