librfn
An ad-hoc utility library
Data Structures | Macros | Functions
util.h File Reference
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ratelimit_state_t
 Control structure used for rate limiting. More...
 

Macros

#define containerof(ptr, type, member)   ((type *) (((char *) ptr) - offsetof(type, member)))
 
#define lengthof(x)   ((sizeof(x) / sizeof(*(x))))
 
#define verify(x)   assert(x)
 
#define RATELIMIT_TO(n, window, fn)
 Ratelimit a single expression. More...
 
#define RATELIMIT(fn)   RATELIMIT_TO(3, 10, fn)
 Ratelimit a single expression using default ratelimiter values. More...
 

Functions

int32_t cyclecmp32 (uint32_t a, uint32_t b)
 Compares values that may be subject to overflow. More...
 
bool ratelimit_check (ratelimit_state_t *rs, uint32_t n, uint32_t window)
 Check that the rate limiter has not triggered. More...
 
void rf_internal_out_of_memory (void)
 
void * xmalloc (size_t sz)