// ParkingLot is an internal API for building efficient synchronization
// primitives like mutexes and events.
//
// The API and name is inspired by WebKit's WTF::ParkingLot, which in turn
// is inspired Linux's futex API.
// See https://webkit.org/blog/6161/locking-in-webkit/.
//
// The core functionality is an atomic "compare-and-sleep" operation along with
// an atomic "wake-up" operation.
#ifndef Py_INTERNAL_PARKING_LOT_H
#define Py_INTERNAL_PARKING_LOT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
enum {
// The thread was unparked by another thread.
Py_PARK_OK = 0,
// The value of `address` did not match `expected`.
Py_PARK_AGAIN = -1,
// The thread was unparked due to a timeout.
Py_PARK_TIMEOUT = -2,
// The thread was interrupted by a signal.
Py_PARK_INTR = -3,
};
// Checks that `*address == *expected` and puts the thread to sleep until an
// unpark operation is called on the same `address`. Otherwise, the function
// returns `Py_PARK_AGAIN`. The comparison behaves like memcmp, but is
// performed atomically with respect to unpark operations.
//
// The `address_size` argument is the size of the data pointed to by the
// `address` and `expected` pointers (i.e., sizeof(*address)). It must be
// 1, 2, 4, or 8.
//
// The `timeout_ns` argument specifies the maximum amount of time to wait, with
// -1 indicating an infinite wait.
//
// `park_arg`, which can be NULL, is passed to the unpark operation.
//
// If `detach` is true, then the thread will detach/release the GIL while
// waiting.
//
// Example usage:
//
// if (_Py_atomic_compare_exchange_uint8(address, &expected, new_value)) {
// int res = _PyParkingLot_Park(address, &new_value, sizeof(*address),
// timeout_ns, NULL, 1);
// ...
// }
PyAPI_FUNC(int)
_PyParkingLot_Park(const void *address, const void *expected,
size_t address_size, PyTime_t timeout_ns,
void *park_arg, int detach);
// Callback for _PyParkingLot_Unpark:
//
// `arg` is the data of the same name provided to the _PyParkingLot_Unpark()
// call.
// `park_arg` is the data provided to _PyParkingLot_Park() call or NULL if
// no waiting thread was found.
// `has_more_waiters` is true if there are more threads waiting on the same
// address. May be true in cases where threads are waiting on a different
// address that map to the same internal bucket.
typedef void _Py_unpark_fn_t(void *arg, void *park_arg, int has_more_waiters);
// Unparks a single thread waiting on `address`.
//
// Note that fn() is called regardless of whether a thread was unparked. If
// no threads are waiting on `address` then the `park_arg` argument to fn()
// will be NULL.
//
// Example usage:
// void callback(void *arg, void *park_arg, int has_more_waiters);
// _PyParkingLot_Unpark(address, &callback, arg);
PyAPI_FUNC(void)
_PyParkingLot_Unpark(const void *address, _Py_unpark_fn_t *fn, void *arg);
// Unparks all threads waiting on `address`.
PyAPI_FUNC(void) _PyParkingLot_UnparkAll(const void *address);
// Resets the parking lot state after a fork. Forgets all parked threads.
PyAPI_FUNC(void) _PyParkingLot_AfterFork(void);
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_PARKING_LOT_H */
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| mimalloc | Folder | 0755 |
|
|
| pycore_abstract.h | File | 1.87 KB | 0644 |
|
| pycore_asdl.h | File | 2.96 KB | 0644 |
|
| pycore_ast.h | File | 30.78 KB | 0644 |
|
| pycore_ast_state.h | File | 6.62 KB | 0644 |
|
| pycore_atexit.h | File | 1.4 KB | 0644 |
|
| pycore_backoff.h | File | 3.89 KB | 0644 |
|
| pycore_bitutils.h | File | 5.88 KB | 0644 |
|
| pycore_blocks_output_buffer.h | File | 8.57 KB | 0644 |
|
| pycore_brc.h | File | 2.05 KB | 0644 |
|
| pycore_bytes_methods.h | File | 3.84 KB | 0644 |
|
| pycore_bytesobject.h | File | 4.98 KB | 0644 |
|
| pycore_call.h | File | 5.99 KB | 0644 |
|
| pycore_capsule.h | File | 397 B | 0644 |
|
| pycore_cell.h | File | 1.03 KB | 0644 |
|
| pycore_ceval.h | File | 11.12 KB | 0644 |
|
| pycore_ceval_state.h | File | 3.94 KB | 0644 |
|
| pycore_code.h | File | 19.79 KB | 0644 |
|
| pycore_codecs.h | File | 2.41 KB | 0644 |
|
| pycore_compile.h | File | 3.66 KB | 0644 |
|
| pycore_complexobject.h | File | 588 B | 0644 |
|
| pycore_condvar.h | File | 2.64 KB | 0644 |
|
| pycore_context.h | File | 1.15 KB | 0644 |
|
| pycore_critical_section.h | File | 7.78 KB | 0644 |
|
| pycore_crossinterp.h | File | 11.84 KB | 0644 |
|
| pycore_descrobject.h | File | 543 B | 0644 |
|
| pycore_dict.h | File | 11.98 KB | 0644 |
|
| pycore_dict_state.h | File | 732 B | 0644 |
|
| pycore_dtoa.h | File | 1.69 KB | 0644 |
|
| pycore_emscripten_signal.h | File | 685 B | 0644 |
|
| pycore_emscripten_trampoline.h | File | 3.11 KB | 0644 |
|
| pycore_exceptions.h | File | 900 B | 0644 |
|
| pycore_faulthandler.h | File | 2.19 KB | 0644 |
|
| pycore_fileutils.h | File | 9.25 KB | 0644 |
|
| pycore_fileutils_windows.h | File | 2.65 KB | 0644 |
|
| pycore_floatobject.h | File | 1.46 KB | 0644 |
|
| pycore_flowgraph.h | File | 1.45 KB | 0644 |
|
| pycore_format.h | File | 480 B | 0644 |
|
| pycore_frame.h | File | 12.08 KB | 0644 |
|
| pycore_freelist.h | File | 4.7 KB | 0644 |
|
| pycore_function.h | File | 1.5 KB | 0644 |
|
| pycore_gc.h | File | 12.66 KB | 0644 |
|
| pycore_genobject.h | File | 859 B | 0644 |
|
| pycore_getopt.h | File | 490 B | 0644 |
|
| pycore_gil.h | File | 2.14 KB | 0644 |
|
| pycore_global_objects.h | File | 3.02 KB | 0644 |
|
| pycore_global_objects_fini_generated.h | File | 115.04 KB | 0644 |
|
| pycore_global_strings.h | File | 26.08 KB | 0644 |
|
| pycore_hamt.h | File | 3.65 KB | 0644 |
|
| pycore_hashtable.h | File | 4.26 KB | 0644 |
|
| pycore_identifier.h | File | 515 B | 0644 |
|
| pycore_import.h | File | 7.55 KB | 0644 |
|
| pycore_importdl.h | File | 3.96 KB | 0644 |
|
| pycore_initconfig.h | File | 6.23 KB | 0644 |
|
| pycore_instruction_sequence.h | File | 2.11 KB | 0644 |
|
| pycore_instruments.h | File | 2.28 KB | 0644 |
|
| pycore_interp.h | File | 14.72 KB | 0644 |
|
| pycore_intrinsics.h | File | 1.71 KB | 0644 |
|
| pycore_jit.h | File | 527 B | 0644 |
|
| pycore_list.h | File | 1.82 KB | 0644 |
|
| pycore_llist.h | File | 2.36 KB | 0644 |
|
| pycore_lock.h | File | 8.34 KB | 0644 |
|
| pycore_long.h | File | 10.45 KB | 0644 |
|
| pycore_memoryobject.h | File | 427 B | 0644 |
|
| pycore_mimalloc.h | File | 1.6 KB | 0644 |
|
| pycore_modsupport.h | File | 3.27 KB | 0644 |
|
| pycore_moduleobject.h | File | 1.54 KB | 0644 |
|
| pycore_namespace.h | File | 435 B | 0644 |
|
| pycore_object.h | File | 27.28 KB | 0644 |
|
| pycore_object_alloc.h | File | 2.13 KB | 0644 |
|
| pycore_object_stack.h | File | 2.33 KB | 0644 |
|
| pycore_object_state.h | File | 942 B | 0644 |
|
| pycore_obmalloc.h | File | 26.78 KB | 0644 |
|
| pycore_obmalloc_init.h | File | 1.89 KB | 0644 |
|
| pycore_opcode_metadata.h | File | 82.88 KB | 0644 |
|
| pycore_opcode_utils.h | File | 2.07 KB | 0644 |
|
| pycore_optimizer.h | File | 8.11 KB | 0644 |
|
| pycore_parking_lot.h | File | 3.27 KB | 0644 |
|
| pycore_parser.h | File | 2.04 KB | 0644 |
|
| pycore_pathconfig.h | File | 658 B | 0644 |
|
| pycore_pyarena.h | File | 2.79 KB | 0644 |
|
| pycore_pyatomic_ft_wrappers.h | File | 7.87 KB | 0644 |
|
| pycore_pybuffer.h | File | 510 B | 0644 |
|
| pycore_pyerrors.h | File | 4.84 KB | 0644 |
|
| pycore_pyhash.h | File | 2.75 KB | 0644 |
|
| pycore_pylifecycle.h | File | 4.36 KB | 0644 |
|
| pycore_pymath.h | File | 8.4 KB | 0644 |
|
| pycore_pymem.h | File | 5.24 KB | 0644 |
|
| pycore_pymem_init.h | File | 3.44 KB | 0644 |
|
| pycore_pystate.h | File | 9.73 KB | 0644 |
|
| pycore_pystats.h | File | 420 B | 0644 |
|
| pycore_pythonrun.h | File | 758 B | 0644 |
|
| pycore_pythread.h | File | 5.95 KB | 0644 |
|
| pycore_qsbr.h | File | 5.39 KB | 0644 |
|
| pycore_range.h | File | 346 B | 0644 |
|
| pycore_runtime.h | File | 12.86 KB | 0644 |
|
| pycore_runtime_init.h | File | 12.74 KB | 0644 |
|
| pycore_runtime_init_generated.h | File | 45.72 KB | 0644 |
|
| pycore_semaphore.h | File | 1.69 KB | 0644 |
|
| pycore_setobject.h | File | 951 B | 0644 |
|
| pycore_signal.h | File | 2.86 KB | 0644 |
|
| pycore_sliceobject.h | File | 369 B | 0644 |
|
| pycore_stackref.h | File | 5.06 KB | 0644 |
|
| pycore_strhex.h | File | 1013 B | 0644 |
|
| pycore_structseq.h | File | 963 B | 0644 |
|
| pycore_symtable.h | File | 8.47 KB | 0644 |
|
| pycore_sysmodule.h | File | 1.15 KB | 0644 |
|
| pycore_time.h | File | 11.52 KB | 0644 |
|
| pycore_token.h | File | 2.93 KB | 0644 |
|
| pycore_traceback.h | File | 3.54 KB | 0644 |
|
| pycore_tracemalloc.h | File | 4.43 KB | 0644 |
|
| pycore_tstate.h | File | 1.32 KB | 0644 |
|
| pycore_tuple.h | File | 820 B | 0644 |
|
| pycore_typeobject.h | File | 8.67 KB | 0644 |
|
| pycore_typevarobject.h | File | 924 B | 0644 |
|
| pycore_ucnhash.h | File | 958 B | 0644 |
|
| pycore_unicodeobject.h | File | 12.96 KB | 0644 |
|
| pycore_unicodeobject_generated.h | File | 129.04 KB | 0644 |
|
| pycore_unionobject.h | File | 742 B | 0644 |
|
| pycore_uop_ids.h | File | 10.06 KB | 0644 |
|
| pycore_uop_metadata.h | File | 38.72 KB | 0644 |
|
| pycore_warnings.h | File | 840 B | 0644 |
|
| pycore_weakref.h | File | 3.8 KB | 0644 |
|