Data-HashMap-Shared
view release on metacpan or search on metacpan
shm_generic.h view on Meta::CPAN
/*
* shm_generic.h -- Macro-template for shared-memory hash maps.
*
* Before including, define:
* SHM_PREFIX -- function prefix (e.g., shm_ii)
* SHM_NODE_TYPE -- node struct name
* SHM_VARIANT_ID -- unique integer for header validation
*
* Key type (choose one):
* SHM_KEY_IS_INT + SHM_KEY_INT_TYPE -- integer key
* (leave undefined for string keys via arena)
*
* Value type (choose one):
* SHM_VAL_IS_STR -- string value via arena
* SHM_VAL_INT_TYPE -- integer value
*
* Optional:
* SHM_HAS_COUNTERS -- generate incr/decr/incr_by, max/min, and integer cas (integer values only)
*/
/* ---- Part 1: shared definitions (included once) ---- */
#ifndef SHM_DEFS_H
#define SHM_DEFS_H
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <sys/mman.h>
#include <sys/stat.h>
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#error "shm_generic.h: inline string packing requires little-endian architecture"
#endif
#include <sys/file.h>
#include <pthread.h> /* pthread_atfork -- available in libc on modern glibc; no -lpthread needed */
#include <sys/syscall.h>
#include <limits.h>
#include <signal.h>
#include <errno.h>
#include <linux/futex.h>
#ifdef __SSE2__
#include <emmintrin.h>
#endif
#define XXH_INLINE_ALL
#include "xxhash.h"
/* ---- Constants ---- */
#define SHM_MAGIC 0x53484D31U /* "SHM1" */
#define SHM_VERSION 10U /* 10: added the occupancy bitmap region (layout change) */
/* Ceiling on new_sharded's shard count: the power-of-two round-up must not
* overflow. */
#define SHM_MAX_SHARDS 4096U
#ifndef SHM_READER_SLOTS
( run in 0.663 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )