Skip to content

Commit 84ba453

Browse files
committed
Document legacy PyThread_*lock APIs
1 parent 77cb39e commit 84ba453

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

Doc/c-api/init.rst

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,3 +2539,98 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
25392539
In the default build, this macro expands to ``}``.
25402540
25412541
.. versionadded:: 3.13
2542+
2543+
2544+
Legacy Locking APIs
2545+
-------------------
2546+
2547+
These APIs are obsolete since Python 3.13 with the introduction of
2548+
:c:type:`PyMutex`.
2549+
2550+
.. versionchanged:: 3.15
2551+
These APIs are now a simple wrapper around ``PyMutex``.
2552+
2553+
2554+
.. c:type:: PyThread_type_lock
2555+
2556+
A pointer to a mutual exclusion lock.
2557+
2558+
2559+
.. c:type:: PyLockStatus
2560+
2561+
The result of acquiring a lock with a timeout.
2562+
2563+
.. c:enumerator:: PY_LOCK_FAILURE
2564+
2565+
Failed to acquire the lock.
2566+
2567+
.. c:enumerator:: PY_LOCK_ACQUIRED
2568+
2569+
The lock was successfully acquired.
2570+
2571+
.. c:enumerator:: PY_LOCK_INTR
2572+
2573+
The lock was interrupted by an interrupt signal.
2574+
2575+
2576+
.. c:function:: PyThread_type_lock PyThread_allocate_lock(void)
2577+
2578+
Allocate a new lock.
2579+
2580+
On success, this function returns a non-zero lock; on failure, this
2581+
function returns ``0`` without an exception set.
2582+
2583+
The caller does not need to hold an :term:`attached thread state`.
2584+
2585+
.. versionchanged:: 3.15
2586+
This function now always uses :c:type:`PyMutex`. In prior versions, this
2587+
would use a lock provided by the operating system.
2588+
2589+
2590+
.. c:function:: PyThread_free_lock(PyThread_type_lock lock)
2591+
2592+
Destroy the lock *lock*.
2593+
2594+
2595+
.. c:function:: PyLockStatus PyThread_acquire_lock_timed(PyThread_type_lock lock, long long microseconds, int intr_flag)
2596+
2597+
Acquire lock *lock*.
2598+
2599+
This will wait for *microseconds* microseconds to acquire the lock. If the
2600+
timeout expires, this function returns :c:enumerator:`PY_LOCK_FAILURE`.
2601+
If *microseconds* is ``-1``, this will wait indefinitely until the lock has
2602+
been released.
2603+
2604+
If *intr_flag* is ``1``, acquiring the lock may be interrupted by CTRL^C,
2605+
in which case this function returns :c:enumerator:`PY_LOCK_INTR`.
2606+
2607+
If the lock is successfully acquired, this function returns
2608+
:c:enumerator:`PY_LOCK_ACQUIRED`.
2609+
2610+
The caller does not need to hold an :term:`attached thread state`.
2611+
2612+
2613+
.. c:function:: int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
2614+
2615+
Acquire lock *lock*.
2616+
2617+
If *waitflag* is ``1`` and another thread currently holds the lock, this
2618+
function will wait until the lock can be acquired and will always return
2619+
``1``.
2620+
2621+
If *waitflag* is ``0`` and another thread holds the lock, this function will
2622+
not wait and instead return ``0``. If the lock is not held by any other
2623+
thread, then this function will quickly acquire it and return ``1``.
2624+
2625+
Unlike :c:func:`PyThread_acquire_lock_timed`, acquiring the lock cannot be
2626+
interrupted by CTRL^C.
2627+
2628+
The caller does not need to hold an :term:`attached thread state`.
2629+
2630+
2631+
.. c:function:: int PyThread_release_lock(PyThread_type_lock lock)
2632+
2633+
Release lock *lock*. If *lock* is not held, then this function issues a
2634+
fatal error.
2635+
2636+
The caller does not need to hold an :term:`attached thread state`.

0 commit comments

Comments
 (0)