1 /* 2 * Copyright (c) 2012 Travis Geiselbrecht 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 #pragma once 9 10 #include <inttypes.h> 11 #include <sys/types.h> 12 13 typedef struct evlog { 14 uint head; 15 uint unitsize; 16 uint len_pow2; 17 uintptr_t *items; 18 } evlog_t; 19 20 status_t evlog_init_etc(evlog_t *e, uint len, uint unitsize, uintptr_t *items); 21 status_t evlog_init(evlog_t *e, uint len, uint unitsize); 22 23 /* callback to evlog_dump. */ 24 typedef void (*evlog_dump_cb)(const uintptr_t *); 25 26 void evlog_dump(evlog_t *e, evlog_dump_cb cb); 27 28 /* bump the head pointer and return the old one. 29 */ 30 uint evlog_bump_head(evlog_t *e); 31 32 /* 33 * It's assumed you're following a pattern similar to the following: 34 * 35 void evlog_add2(evlog_t *e, uintptr_t a, uintptr_t b) 36 { 37 uint index = evlog_bump_head(e); 38 39 e->items[index] = a; 40 e->items[index + 1] = b; 41 } 42 */ 43 44