cpython/Python/parking_lot.c

#include "Python.h"

#include "pycore_llist.h"
#include "pycore_lock.h"          // _PyRawMutex
#include "pycore_parking_lot.h"
#include "pycore_pyerrors.h"      // _Py_FatalErrorFormat
#include "pycore_pystate.h"       // _PyThreadState_GET
#include "pycore_semaphore.h"     // _PySemaphore
#include "pycore_time.h"          // _PyTime_Add()

#include <stdbool.h>


Bucket;

struct wait_entry {};

// Prime number to avoid correlations with memory addresses.
// We want this to be roughly proportional to the number of CPU cores
// to minimize contention on the bucket locks, but not too big to avoid
// wasting memory. The exact choice does not matter much.
#define NUM_BUCKETS

#define BUCKET_INIT(b, i)
#define BUCKET_INIT_2(b, i)
#define BUCKET_INIT_4(b, i)
#define BUCKET_INIT_8(b, i)
#define BUCKET_INIT_16(b, i)
#define BUCKET_INIT_32(b, i)
#define BUCKET_INIT_64(b, i)
#define BUCKET_INIT_128(b, i)
#define BUCKET_INIT_256(b, i)

// Table of waiters (hashed by address)
static Bucket buckets[NUM_BUCKETS] =;

void
_PySemaphore_Init(_PySemaphore *sema)
{}

void
_PySemaphore_Destroy(_PySemaphore *sema)
{}

static int
_PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
{}

int
_PySemaphore_Wait(_PySemaphore *sema, PyTime_t timeout, int detach)
{}

void
_PySemaphore_Wakeup(_PySemaphore *sema)
{}

static void
enqueue(Bucket *bucket, const void *address, struct wait_entry *wait)
{}

static struct wait_entry *
dequeue(Bucket *bucket, const void *address)
{}

static void
dequeue_all(Bucket *bucket, const void *address, struct llist_node *dst)
{}

// Checks that `*addr == *expected` (only works for 1, 2, 4, or 8 bytes)
static int
atomic_memcmp(const void *addr, const void *expected, size_t addr_size)
{}

int
_PyParkingLot_Park(const void *addr, const void *expected, size_t size,
                   PyTime_t timeout_ns, void *park_arg, int detach)
{}

void
_PyParkingLot_Unpark(const void *addr, _Py_unpark_fn_t *fn, void *arg)
{}

void
_PyParkingLot_UnparkAll(const void *addr)
{}

void
_PyParkingLot_AfterFork(void)
{}