blob: 53f50e40cc1116632fc1cacac56a9265cc3ca140 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
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
29typedef struct evlog {
30 uint head;
31 uint unitsize;
32 uint len_pow2;
33 uintptr_t *items;
34} evlog_t;
35
36status_t evlog_init_etc(evlog_t *e, uint len, uint unitsize, uintptr_t *items);
37status_t evlog_init(evlog_t *e, uint len, uint unitsize);
38
39/* callback to evlog_dump. */
40typedef void (*evlog_dump_cb)(const uintptr_t *);
41
42void evlog_dump(evlog_t *e, evlog_dump_cb cb);
43
44/* bump the head pointer and return the old one.
45 */
46uint evlog_bump_head(evlog_t *e);
47
48/*
49 * It's assumed you're following a pattern similar to the following:
50 *
51void 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