1 /*
2 * Copyright 2017 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 */
25
26 /**
27 * \file u_async_debug.h
28 * Provides a helper implementation of util_debug_callback which allows debug
29 * messages from non-application threads to be passed back to the application
30 * thread.
31 */
32
33 #ifndef UTIL_ASYNC_DEBUG_H
34 #define UTIL_ASYNC_DEBUG_H
35
36 #include "pipe/p_state.h"
37 #include "util/u_debug.h"
38 #include "util/simple_mtx.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 struct util_debug_message {
45 unsigned *id;
46 enum util_debug_type type;
47 char *msg;
48 };
49
50 struct util_async_debug_callback {
51 struct util_debug_callback base;
52
53 simple_mtx_t lock;
54 unsigned count;
55 unsigned max;
56 struct util_debug_message *messages;
57 };
58
59 void
60 u_async_debug_init(struct util_async_debug_callback *adbg);
61 void
62 u_async_debug_cleanup(struct util_async_debug_callback *adbg);
63
64 void
65 _u_async_debug_drain(struct util_async_debug_callback *adbg,
66 struct util_debug_callback *dst);
67
68 static inline void
u_async_debug_drain(struct util_async_debug_callback * adbg,struct util_debug_callback * dst)69 u_async_debug_drain(struct util_async_debug_callback *adbg,
70 struct util_debug_callback *dst)
71 {
72 /* Read the count without taking the lock to avoid atomics in the fast path.
73 * We'll re-read the count after taking the lock. */
74 if (adbg->count)
75 _u_async_debug_drain(adbg, dst);
76 }
77
78 #ifdef __cplusplus
79 }
80 #endif
81
82 #endif /* UTIL_ASYNC_DEBUG_H */
83