xtc_pool(3)
---xtc_pool(3)
bounded resource pool (checkout / return)
| XTC_POOL(3) | Library Functions Manual | XTC_POOL(3) |
NAME
xtc_pool_create,
xtc_pool_destroy,
xtc_pool_add,
xtc_pool_checkout,
xtc_pool_checkin,
xtc_pool_available,
xtc_pool_capacity — bounded
resource pool (checkout / return)
LIBRARY
library “libxtc”
SYNOPSIS
#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);
DESCRIPTION
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.
xtc_pool_create()
sizes a pool for capacity resources.
xtc_pool_add()
registers a resource (as free); XTC_E_RESOURCE is
returned once capacity resources have been added.
xtc_pool_checkout()
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.
xtc_pool_checkin()
returns a checked-out resource, waking one waiter.
xtc_pool_available()
returns the number of resources currently free;
xtc_pool_capacity()
returns the number added (free plus checked out).
xtc_pool_destroy()
releases the pool. It does NOT free the resources -- the caller owns them
and must not destroy a pool with resources still checked out.
RETURN VALUES
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.
EXAMPLES
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);
}
SEE ALSO
| July 10, 2026 | Debian |