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