libxtc 0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
xtc_pdict.h
1/*-
2 * Copyright (c) 2026, The XTC Project
3 * @stability stable
4 * Use of this source code is governed by the ISC License.
5 *
6 * src/inc/xtc_pdict.h
7 * Per-process dictionary -- string-keyed kv store local to each
8 * xtc_proc. Models Erlang's `put/2`, `get/1`, `erase/1`,
9 * `get_keys/0`. Used for:
10 * - per-proc tracing / debug names
11 * - request context (correlation ids, span ids) carried with
12 * a proc as it processes work
13 * - test-time per-proc state injection
14 *
15 * Implementation: tiny linked list inside `struct xtc_proc`.
16 * Linear lookup; entries usually <16 per proc. M11.5 swaps in
17 * a small hash table once we have one.
18 *
19 * All entries live in process memory and are freed at proc exit.
20 * Values are caller-owned `void *`; the store stores the pointer
21 * verbatim (no deep copy). If a value's lifetime should match
22 * the proc, register a destructor via `xtc_pdict_put_with_dtor`.
23 */
24
25#ifndef XTC_PDICT_H
26#define XTC_PDICT_H
27
28#include "xtc_export.h"
29
30#include <stddef.h>
31
32#include "xtc.h"
33
34typedef void (*xtc_pdict_dtor_fn)(void *value);
35
36/*
37 * PUBLIC: int xtc_pdict_put __P((const char *, void *));
38 * PUBLIC: int xtc_pdict_put_with_dtor __P((const char *, void *, xtc_pdict_dtor_fn));
39 * PUBLIC: int xtc_pdict_get __P((const char *, void **));
40 * PUBLIC: int xtc_pdict_erase __P((const char *));
41 * PUBLIC: int xtc_pdict_count __P((void));
42 * PUBLIC: int xtc_pdict_clear __P((void));
43 */
44
45/* All operations apply to the calling proc's dict. When called
46 * outside any proc, all return XTC_E_INVAL. */
47
48XTC_API int xtc_pdict_put(const char *key, void *value);
49XTC_API int xtc_pdict_put_with_dtor(const char *key, void *value,
50 xtc_pdict_dtor_fn dtor);
51
52/* Retrieve. Sets *value if found; returns XTC_E_INVAL if no entry. */
53XTC_API int xtc_pdict_get(const char *key, void **value);
54
55/* Remove (and run destructor if any). Returns XTC_OK if erased,
56 * XTC_E_INVAL if absent. */
57XTC_API int xtc_pdict_erase(const char *key);
58
59XTC_API int xtc_pdict_count(void);
60XTC_API int xtc_pdict_clear(void);
61
62#endif /* XTC_PDICT_H */