9P-INTMAP(3)
okay bestie, this is 9P-INTMAP(3) from the Library Functions Manual ππ β the integer-to-pointer map page, and it's lowkey a whole reference-counting vibe.
π NAME π
Intmap, allocmap, freemap, insertkey, caninsertkey, lookupkey, deletekey β integer to data structure maps π¦
β¨ SYNOPSIS β¨
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
Intmap* allocmap(void (*inc)(void*))
void freemap(Intmap *map, void (*dec)(void*))
void* lookupkey(Intmap *map, ulong key)
void* insertkey(Intmap *map, ulong key, void *val)
int caninsertkey(Intmap *map, ulong key, void *val)
void* lookupkey(Intmap *map, ulong key)
void* deletekey(Intmap *map, ulong key)
πΈ DESCRIPTION πΈ
An Intmap is literally an arbitrary mapping from integers to pointers. No cap, that's the whole concept. Here's the function-by-function tea:
allocmapβ creates a new map. Theincfunction is called each time a new pointer is added to the map; typicallyincmaintains reference counts. β¨freemapβ destroys the map. Thedecfunction is called on each pointer left in the map when it is being freed; typicallydecmaintains reference counts. π«Άinsertkeyβ adds new entries to the map. It returns the previous value associated with the given key, or zero if there was no previous value.caninsertkeyβ likeinsertkey, but it only insertsvalif there is no current mapping. It returns1ifvalwas inserted,0otherwise. πlookupkeyβ returns the pointer associated withkey, or zero if there is no such pointer.deletekeyβ removes the entry foridfrom the map, returning the associated pointer, if any.
Concurrent access to Intmaps is safe, moderated via a QLock stored in the Intmap structure. Thread-safe icon behavior, fr fr. π₯
In anticipation of the storage of reference-counted structures, an increment function inc may be specified at map creation time. lookupkey calls inc (if non-zero) on pointers before returning them. If the reference count adjustments were left to the caller (and thus not protected by the lock), it would be possible to accidentally reclaim a structure if, for example, it was deleted from the map and its reference count decremented between the return of insertkey and the external increment. So the lock is doing important main character work, okay? π
insertkey and caninsertkey do not call inc when inserting val into the map, nor do insertkey or deletekey call inc when returning old map entries. The rationale is that calling an insertion function transfers responsibility for the reference to the map, and responsibility is given back via the return value of deletekey or the next insertkey. Periodt. π
Intmaps are used by the 9P library to implement Fidpools and Reqpools. Iconic crossover event. π«Ά
π SOURCE π
/src/lib9p/intmap.c
π SEE ALSO π
that's the whole 9P-INTMAP(3) situation, bestie β Library Functions Manual page, source at /src/lib9p/intmap.c, and the footer is just the page name with no extra date drama. byeee π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms