1 /* 2 * Copyright (c) 2012 Travis Geiselbrecht 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files 6 * (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, merge, 8 * publish, distribute, sublicense, and/or sell copies of the Software, 9 * and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 #ifndef __LIB_EVLOG_H 24 #define __LIB_EVLOG_H 25 26 #include <inttypes.h> 27 #include <sys/types.h> 28 29 typedef struct evlog { 30 uint head; 31 uint unitsize; 32 uint len_pow2; 33 uintptr_t *items; 34 } evlog_t; 35 36 status_t evlog_init_etc(evlog_t *e, uint len, uint unitsize, uintptr_t *items); 37 status_t evlog_init(evlog_t *e, uint len, uint unitsize); 38 39 /* callback to evlog_dump. */ 40 typedef void (*evlog_dump_cb)(const uintptr_t *); 41 42 void evlog_dump(evlog_t *e, evlog_dump_cb cb); 43 44 /* bump the head pointer and return the old one. 45 */ 46 uint evlog_bump_head(evlog_t *e); 47 48 /* 49 * It's assumed you're following a pattern similar to the following: 50 * 51 void evlog_add2(evlog_t *e, uintptr_t a, uintptr_t b) 52 { 53 uint index = evlog_bump_head(e); 54 55 e->items[index] = a; 56 e->items[index + 1] = b; 57 } 58 */ 59 60 #endif 61 62