cpython/Lib/test/test_capi
Sam Gross 0c89056fe5
gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344)
PyMutex is a one byte lock with fast, inlineable lock and unlock functions for the common uncontended case.  The design is based on WebKit's WTF::Lock.

PyMutex is built using the _PyParkingLot APIs, which provides a cross-platform futex-like API (based on WebKit's WTF::ParkingLot).  This internal API will be used for building other synchronization primitives used to implement PEP 703, such as one-time initialization and events.

This also includes tests and a mini benchmark in Tools/lockbench/lockbench.py to compare with the existing PyThread_type_lock.

Uncontended acquisition + release:
* Linux (x86-64): PyMutex: 11 ns, PyThread_type_lock: 44 ns
* macOS (arm64): PyMutex: 13 ns, PyThread_type_lock: 18 ns
* Windows (x86-64): PyMutex: 13 ns, PyThread_type_lock: 38 ns

PR Overview:

The primary purpose of this PR is to implement PyMutex, but there are a number of support pieces (described below).

* PyMutex:  A 1-byte lock that doesn't require memory allocation to initialize and is generally faster than the existing PyThread_type_lock.  The API is internal only for now.
* _PyParking_Lot:  A futex-like API based on the API of the same name in WebKit.  Used to implement PyMutex.
* _PyRawMutex:  A word sized lock used to implement _PyParking_Lot.
* PyEvent:  A one time event.  This was used a bunch in the "nogil" fork and is useful for testing the PyMutex implementation, so I've included it as part of the PR.
* pycore_llist.h:  Defines common operations on doubly-linked list.  Not strictly necessary (could do the list operations manually), but they come up frequently in the "nogil" fork. ( Similar to https://man.freebsd.org/cgi/man.cgi?queue)

---------

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2023-09-19 09:54:29 -06:00
..
__init__.py
__main__.py
check_config.py gh-104621: Check for Incompatible Extensions in import_find_extension() (gh-107184) 2023-07-27 15:08:38 -06:00
test_abstract.py gh-108511: Add C API functions which do not silently ignore errors (GH-109025) 2023-09-17 14:23:31 +03:00
test_codecs.py gh-99593: Add tests for Unicode C API (part 3) (GH-104728) 2023-07-10 14:04:34 +03:00
test_dict.py gh-108314: Add PyDict_ContainsString() function (#108323) 2023-08-24 15:59:12 +02:00
test_eval_code_ex.py gh-101072: support default and kw default in PyEval_EvalCodeEx for 3.11+ (#101127) 2023-02-07 10:34:21 +01:00
test_exceptions.py gh-107915: Handle errors in C API functions PyErr_Set*() and PyErr_Format() (GH-107918) 2023-08-19 14:51:03 +03:00
test_getargs.py gh-109050: Remove remaining tests for legacy Unicode C API (GH-109068) 2023-09-09 05:44:46 +00:00
test_immortal.py gh-84436: Add integration C API tests for immortal objects (gh-103962) 2023-05-03 00:05:30 +09:00
test_long.py gh-108444: Add PyLong_AsInt() public function (#108445) 2023-08-24 23:55:30 +02:00
test_mem.py gh-108634: Py_TRACE_REFS uses a hash table (#108663) 2023-08-31 18:33:34 +02:00
test_misc.py gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344) 2023-09-19 09:54:29 -06:00
test_pyatomic.py gh-108337: Add pyatomic.h header (#108701) 2023-08-31 21:41:18 +00:00
test_structmembers.py gh-47146: Soft-deprecate structmember.h, expose its contents via Python.h (GH-99014) 2022-11-22 08:25:43 +01:00
test_unicode.py gh-106320: Remove _PyUnicode_TransformDecimalAndSpaceToASCII() (#106398) 2023-07-04 08:59:09 +00:00
test_watchers.py gh-91051: fix type watcher test to be robust to existing watcher (#107989) 2023-08-16 13:13:32 -06:00