xtc_pool(3)

---

xtc_pool(3)

bounded resource pool (checkout / return)

XTC_POOL(3) Library Functions Manual XTC_POOL(3)

xtc_pool_create, xtc_pool_destroy, xtc_pool_add, xtc_pool_checkout, xtc_pool_checkin, xtc_pool_available, xtc_pool_capacitybounded resource pool (checkout / return)

library “libxtc”

#include <xtc_pool.h>

int
xtc_pool_create(size_t capacity, xtc_pool_t **out);

void
xtc_pool_destroy(xtc_pool_t *p);

int
xtc_pool_add(xtc_pool_t *p, void *resource);

int
xtc_pool_checkout(xtc_pool_t *p, int64_t timeout_ns, void **out);

int
xtc_pool_checkin(xtc_pool_t *p, void *resource);

size_t
xtc_pool_available(const xtc_pool_t *p);

size_t
xtc_pool_capacity(const xtc_pool_t *p);

A resource pool tracks a fixed set of caller-owned resources (connections, buffers, handles) that fibers check out and return. A checkout blocks the calling fiber when all resources are busy, so the pool doubles as a concurrency limiter. This is the checkout / return half of the connection-pool pattern; the supervisor's bounded dynamic pool (xtc_sup_opts_t.max_children) is the spawn-workers half.

The pool does not create or own the resources. () sizes a pool for capacity resources. () registers a resource (as free); XTC_E_RESOURCE is returned once capacity resources have been added.

() returns a free resource in *out, blocking the calling fiber until one is free or timeout_ns elapses. timeout_ns of 0 tries once (returning XTC_E_AGAIN immediately if none is free); a negative value blocks indefinitely. () returns a checked-out resource, waking one waiter.

() returns the number of resources currently free; () returns the number added (free plus checked out).

() releases the pool. It does NOT free the resources -- the caller owns them and must not destroy a pool with resources still checked out.

xtc_pool_create(), xtc_pool_add(), and xtc_pool_checkin() return XTC_OK or a negative XTC_E_* code. xtc_pool_checkout() returns XTC_OK, or XTC_E_AGAIN if no resource became free within timeout_ns. xtc_pool_available() and xtc_pool_capacity() return counts.

xtc_pool_destroy() returns no value.

xtc_pool_t *pool;
xtc_pool_create(8, &pool);              /* 8 connections */
for (int i = 0; i < 8; i++)
    xtc_pool_add(pool, open_conn());

/* A worker fiber: */
void *conn;
if (xtc_pool_checkout(pool, 1000000000LL, &conn) == XTC_OK) {
    use_conn(conn);
    xtc_pool_checkin(pool, conn);
}

xtc_sync(3), xtc_supervisor(3), xtc_proc(3), xtc(7)

July 10, 2026 Debian

View the mdoc source