cpython/Lib
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
..
__phello__
asyncio gh-108903: Remove unneeded `lambda`s from `asyncio` (GH-108904) 2023-09-05 18:11:12 +03:00
collections gh-108751: Add copy.replace() function (GH-108752) 2023-09-06 23:55:42 +03:00
concurrent gh-107219: Fix concurrent.futures terminate_broken() (#109244) 2023-09-11 08:11:31 +00:00
ctypes gh-105751: test_ctypes avoids "from ctypes import *" (#105768) 2023-06-14 03:34:11 +00:00
curses
dbm
email gh-106186: Don't report MultipartInvariantViolationDefect for valid multipart emails when parsing header only (#107016) 2023-07-23 12:25:18 +02:00
encodings gh-98433: Fix quadratic time idna decoding. (#99092) 2022-11-07 16:54:41 -08:00
ensurepip gh-106774: Update bundled pip version to 23.2.1 (#106775) 2023-07-25 10:59:25 +01:00
html
http gh-109096: Deprecate `http.server.CGIHTTPRequestHandler` (#109387) 2023-09-15 14:26:45 -07:00
idlelib IDLE: Condense run.main threading.Thread start. (#106125) 2023-06-27 13:12:56 -04:00
importlib GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300) 2023-09-13 10:25:45 -07:00
json Revert "GH-96145: Add AttrDict to JSON module for use with object_hook (#96146)" (#105948) 2023-06-26 20:35:53 +02:00
logging gh-103384: Generalize the regex pattern `BaseConfigurator.INDEX_PATTERN` to allow spaces and non-alphanumeric characters in keys. (GH-103391) 2023-08-25 09:15:26 +01:00
multiprocessing gh-107219: Fix concurrent.futures terminate_broken() (#109244) 2023-09-11 08:11:31 +00:00
pydoc_data
re gh-56166: Deprecate passing confusing positional arguments in re functions (#107778) 2023-08-16 13:35:35 -07:00
site-packages
sqlite3 gh-108590: Revert gh-108657 (commit 400a1cebc) (#108686) 2023-08-30 14:53:10 +00:00
test gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344) 2023-09-19 09:54:29 -06:00
tkinter gh-72684: Tkinter: provide interface for "tk busy" subcommands (GH-107684) 2023-08-19 14:48:02 +03:00
tomllib
turtledemo
unittest gh-84867: Do not load tests from TestCase and FunctionTestCase (GH-100497) 2023-09-12 16:33:30 +03:00
urllib
venv GH-83417: Allow `venv` to add a `.gitignore` file to environments via a new `scm_ignore_file` parameter (GH-108125) 2023-09-15 22:38:08 +00:00
wsgiref
xml gh-50002: xml.dom.minidom now preserves whitespaces in attributes (GH-107947) 2023-08-23 15:23:41 +03:00
xmlrpc
zipfile gh-106752: Sync with zipp 3.16.2 (#106757) 2023-07-15 09:21:17 -04:00
zoneinfo
__future__.py
__hello__.py
_aix_support.py
_collections_abc.py
_compat_pickle.py
_compression.py
_markupbase.py
_opcode_metadata.py GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300) 2023-09-13 10:25:45 -07:00
_osx_support.py
_py_abc.py
_pydatetime.py Fix date.__repr__() docstring (#109422) 2023-09-15 15:05:19 +02:00
_pydecimal.py
_pyio.py
_pylong.py
_sitebuiltins.py
_strptime.py
_threading_local.py
_weakrefset.py
abc.py
antigravity.py
argparse.py
ast.py gh-108843: fix ast.unparse for f-string with many quotes (#108981) 2023-09-18 14:56:19 +01:00
base64.py
bdb.py
bisect.py
bz2.py
cProfile.py
calendar.py GH-108202: Document ``calendar``'s command-line interface (#109020) 2023-09-06 21:19:54 +00:00
cmd.py
code.py
codecs.py gh-50644: Forbid pickling of codecs streams (GH-109180) 2023-09-10 20:06:09 +03:00
codeop.py
colorsys.py gh-106498: Revert incorrect colorsys.rgb_to_hls change (#106627) 2023-07-11 11:07:20 -04:00
compileall.py
configparser.py
contextlib.py gh-102799: use sys.exception() instead of sys.exc_info() in contextlib (#103311) 2023-07-20 14:41:32 +05:30
contextvars.py
copy.py gh-108751: Add copy.replace() function (GH-108752) 2023-09-06 23:55:42 +03:00
copyreg.py
csv.py
dataclasses.py gh-108751: Add copy.replace() function (GH-108752) 2023-09-06 23:55:42 +03:00
datetime.py
decimal.py
difflib.py
dis.py gh-107932: Fix dis module for bytecode that does not have an associated source line (GH-107988) 2023-08-25 09:31:26 +01:00
doctest.py gh-108794: doctest counts skipped tests (#108795) 2023-09-02 16:42:07 +02:00
enum.py gh-109022: [Enum] require `names=()` to create empty enum type (GH-109048) 2023-09-07 18:19:03 -07:00
filecmp.py
fileinput.py
fnmatch.py gh-89973: Fix re.error in the fnmatch module. (GH-93072) 2022-06-05 11:46:29 +03:00
fractions.py
ftplib.py
functools.py gh-102757: fix function signature mismatch for `functools.reduce` between code and documentation (#102759) 2023-09-18 10:42:58 -06:00
genericpath.py
getopt.py
getpass.py
gettext.py gh-62519: Make pgettext search plurals when translation is not found (#107118) 2023-07-23 16:08:28 +02:00
glob.py
graphlib.py
gzip.py gh-108111: Flush gzip write buffer before seeking, fixing bad writes (#108341) 2023-08-24 10:23:01 +02:00
hashlib.py
heapq.py
hmac.py
imaplib.py
inspect.py gh-108751: Add copy.replace() function (GH-108752) 2023-09-06 23:55:42 +03:00
io.py
ipaddress.py gh-87799: Improve the textual representation of IPv4-mapped IPv6 addresses (#29345) 2023-07-31 14:33:26 +00:00
keyword.py
linecache.py
locale.py
lzma.py
mailbox.py
mimetypes.py
modulefinder.py
netrc.py
ntpath.py gh-106242: Make ntpath.realpath errors consistent with abspath when there are embedded nulls (GH-108248) 2023-08-22 00:16:02 +00:00
nturl2path.py
numbers.py
opcode.py gh-109039: Branch prediction for Tier 2 interpreter (#109038) 2023-09-11 18:20:24 +00:00
operator.py
optparse.py
os.py gh-106046: Improve error message from `os.fspath` if `__fspath__` is set to `None` (#106082) 2023-06-26 00:06:12 +01:00
pathlib.py GH-78722: Raise exceptions from `pathlib.Path.iterdir()` without delay. (#107320) 2023-09-02 16:08:03 +01:00
pdb.py gh-109375: Fix bug where pdb registers an alias without an associated command (#109376) 2023-09-14 22:31:30 +01:00
pickle.py gh-93627: Align Python implementation of pickle with C implementation of pickle (GH-103035) 2023-09-10 10:06:08 +03:00
pickletools.py
pkgutil.py
platform.py
plistlib.py
poplib.py gh-106200: Remove unused imports (#106201) 2023-06-28 11:55:41 +00:00
posixpath.py
pprint.py
profile.py
pstats.py
pty.py
py_compile.py
pyclbr.py
pydoc.py gh-107782: Pydoc: fall back to __text_signature__ if inspect.signature() fails (GH-107786) 2023-08-11 20:51:36 +03:00
queue.py
quopri.py
random.py Fix an ironic typo in a code comment. (gh-109186) 2023-09-09 10:21:42 -05:00
reprlib.py gh-107409: set `__wrapped__` attribute in `reprlib.recursive_repr` (#107410) 2023-08-10 06:55:49 +00:00
rlcompleter.py
runpy.py
sched.py
secrets.py
selectors.py gh-106751: Optimize _PolllikeSelector for many iteration case (gh-106884) 2023-07-20 09:53:11 +09:00
shelve.py gh-107089: Improve Shelf.clear method performance (gh-107090) 2023-07-29 09:08:11 +09:00
shlex.py
shutil.py gh-99203: shutil.make_archive(): restore select CPython <= 3.10.5 behavior (GH-99802) 2023-08-16 10:00:03 +03:00
signal.py
site.py
smtplib.py gh-65495: Use lowercase `mail from` and `rcpt to` in `smtplib.SMTP` (#107019) 2023-07-22 16:46:59 +02:00
socket.py
socketserver.py
sre_compile.py
sre_constants.py
sre_parse.py
ssl.py gh-108342: Break ref cycle in SSLSocket._create() exc (#108344) 2023-08-23 05:26:01 +00:00
stat.py gh-108638: Fix stat.filemode() when _stat is missing (#108639) 2023-08-29 15:46:46 +00:00
statistics.py gh-108322: Optimize statistics.NormalDist.samples() (gh-108324) 2023-08-27 08:59:40 -05:00
string.py
stringprep.py
struct.py
subprocess.py gh-106723: forward -Xfrozen_modules option to spawned process interpreters (#106724) 2023-07-28 05:04:26 +00:00
symtable.py
sysconfig.py gh-106789: avoid importing pprint from sysconfig (#106790) 2023-07-17 10:28:33 +01:00
tabnanny.py
tarfile.py gh-107811: tarfile: treat overflow in UID/GID as failure to set it (#108369) 2023-08-23 20:00:07 +02:00
tempfile.py
textwrap.py gh-107369: optimize textwrap.indent() (#107374) 2023-07-29 06:37:23 +00:00
this.py
threading.py gh-102029: Deprecate passing arguments to `_PyRLock` in `threading` (#102071) 2023-08-17 09:19:07 -07:00
timeit.py gh-105052:update timeit function's description (#105060) 2023-08-27 03:22:27 -04:00
token.py gh-107015: Remove async_hacks from the tokenizer (#107018) 2023-07-26 16:34:15 +01:00
tokenize.py gh-71299: Fix __all__ in tokenize (#105907) 2023-06-19 13:31:57 +02:00
trace.py
traceback.py gh-106922: Fix error location for constructs with spaces and parentheses (#108959) 2023-09-08 17:18:35 +01:00
tracemalloc.py
tty.py
turtle.py gh-107805: Fix signatures of module-level generated functions in `turtle` (#107807) 2023-09-01 01:18:15 -07:00
types.py gh-107576: Ensure `__orig_bases__` are our own in `get_original_bases` (#107584) 2023-08-03 14:19:24 +00:00
typing.py gh-105509: Simplify implementation of `typing.Annotated` (#105510) 2023-09-01 13:57:25 -07:00
uuid.py
warnings.py
wave.py
weakref.py
webbrowser.py
zipapp.py gh-104527: zippapp will now avoid appending an archive to itself. (gh-106076) 2023-06-26 10:09:08 +01:00
zipimport.py gh-103200: Fix performance issues with `zipimport.invalidate_caches()` (GH-103208) 2023-07-07 22:02:13 +00:00