cpython/Tools/c-analyzer/cpython
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 bpo-36876: Fix the C analyzer tool. (GH-22841) 2020-10-22 18:42:51 -06:00
__main__.py gh-102033: Fix syntax error in Tools/c-analyzer (GH-102066) 2023-03-22 07:59:32 -07:00
_analyzer.py gh-105407: Remove unused imports in Tools/c-analyzer/ (#105410) 2023-06-06 21:08:48 +00:00
_builtin_types.py gh-94673: [c-analyzer] Add a Script to Identify Static Types (#94989) 2022-07-18 19:03:57 -06:00
_capi.py gh-102033: Fix syntax error in Tools/c-analyzer (GH-102066) 2023-03-22 07:59:32 -07:00
_files.py bpo-36876: Make sure the c-analyzer is checking all the source files.' (gh-31264) 2022-02-10 16:14:19 -07:00
_parser.py gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344) 2023-09-19 09:54:29 -06:00
globals-to-fix.tsv gh-106320: Remove _PyAnextAwaitable_Type from the public C API (#108597) 2023-08-29 02:05:11 +00:00
ignored.tsv gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344) 2023-09-19 09:54:29 -06:00
known.tsv bpo-36876: Fix the C analyzer tool. (GH-22841) 2020-10-22 18:42:51 -06:00