ustream: prevent recursive calls to the read callback
[project/libubox.git] / udebug-priv.h
1 /*
2 * udebug - debug ring buffer library
3 *
4 * Copyright (C) 2023 Felix Fietkau <nbd@nbd.name>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 #ifndef __UDEBUG_UTIL_H
19 #define __UDEBUG_UTIL_H
20
21 #include "blobmsg.h"
22 #include "udebug.h"
23 #include "udebug-proto.h"
24
25 #define UDEBUG_TIMEOUT 1000
26
27 __hidden int udebug_buf_open(struct udebug_buf *buf, int fd, uint32_t ring_size, uint32_t data_size);
28 __hidden struct udebug_client_msg *
29 udebug_send_and_wait(struct udebug *ctx, struct udebug_client_msg *msg, int *rfd);
30
31 static inline int32_t u32_sub(uint32_t a, uint32_t b)
32 {
33 return a - b;
34 }
35
36 static inline int32_t u32_max(uint32_t a, uint32_t b)
37 {
38 return u32_sub(a, b) > 0 ? a : b;
39 }
40
41 static inline void u32_set(void *ptr, uint32_t val)
42 {
43 volatile uint32_t *v = ptr;
44 *v = val;
45 }
46
47 static inline uint32_t u32_get(void *ptr)
48 {
49 volatile uint32_t *v = ptr;
50 return *v;
51 }
52
53 #endif