gst/parse: Also pass -DGST_EXPORTS here
[platform/upstream/gstreamer.git] / gst / gsttrace.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gsttrace.h: Header for tracing functions (deprecated)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23
24 #ifndef __GST_TRACE_H__
25 #define __GST_TRACE_H__
26
27 #include <glib.h>
28 #include <gst/gstconfig.h>
29
30 G_BEGIN_DECLS
31
32 /**
33  * GstAllocTraceFlags:
34  * @GST_ALLOC_TRACE_NONE: No tracing specified or desired.
35  * @GST_ALLOC_TRACE_LIVE: Trace number of non-freed memory.
36  * @GST_ALLOC_TRACE_MEM_LIVE: Trace pointers of unfreed memory.
37  *
38  * Flags indicating which tracing feature to enable.
39  */
40 typedef enum {
41   GST_ALLOC_TRACE_NONE      = 0,
42   GST_ALLOC_TRACE_LIVE      = (1 << 0),
43   GST_ALLOC_TRACE_MEM_LIVE  = (1 << 1)
44 } GstAllocTraceFlags;
45
46 typedef struct _GstAllocTrace   GstAllocTrace;
47
48 /**
49  * GstAllocTrace:
50  * @name: The name of the tracing object
51  * @flags: Flags for this object
52  * @offset: offset of the GType
53  * @live: counter for live memory
54  * @mem_live: list with pointers to unfreed memory
55  *
56  * The main tracing object
57  */
58 struct _GstAllocTrace {
59   gchar         *name;
60   gint           flags;
61
62   goffset        offset;
63   gint           live;
64   GSList        *mem_live;
65 };
66
67 #ifndef GST_DISABLE_TRACE
68
69 GST_EXPORT GMutex       _gst_trace_mutex;
70
71 void                    _priv_gst_alloc_trace_initialize (void);
72 void                    _priv_gst_alloc_trace_deinit     (void);
73 GstAllocTrace*          _priv_gst_alloc_trace_register   (const gchar *name, goffset offset);
74
75 void                    _priv_gst_alloc_trace_dump       (void);
76
77 #ifndef GST_DISABLE_ALLOC_TRACE
78 /**
79  * gst_alloc_trace_register:
80  * @name: The name of the tracer object
81  *
82  * Register a new alloc tracer with the given name
83  */
84 #define _gst_alloc_trace_register(name,offset) _priv_gst_alloc_trace_register (name,offset)
85
86 #define _gst_alloc_trace_dump                  _priv_gst_alloc_trace_dump
87
88 /**
89  * gst_alloc_trace_new:
90  * @trace: The tracer to use
91  * @mem: The memory allocated
92  *
93  * Use the tracer to trace a new memory allocation
94  */
95 #define _gst_alloc_trace_new(trace, mem)           \
96 G_STMT_START {                                          \
97   if (G_UNLIKELY ((trace)->flags)) {                    \
98     g_mutex_lock (&_gst_trace_mutex);            \
99     if ((trace)->flags & GST_ALLOC_TRACE_LIVE)          \
100       (trace)->live++;                                  \
101     if ((trace)->flags & GST_ALLOC_TRACE_MEM_LIVE)      \
102       (trace)->mem_live =                               \
103         g_slist_prepend ((trace)->mem_live, mem);       \
104     g_mutex_unlock (&_gst_trace_mutex);          \
105   }                                                     \
106 } G_STMT_END
107
108 /**
109  * gst_alloc_trace_free:
110  * @trace: The tracer to use
111  * @mem: The memory that is freed
112  *
113  * Trace a memory free operation
114  */
115 #define _gst_alloc_trace_free(trace, mem)                \
116 G_STMT_START {                                          \
117   if (G_UNLIKELY ((trace)->flags)) {                    \
118     g_mutex_lock (&_gst_trace_mutex);            \
119     if ((trace)->flags & GST_ALLOC_TRACE_LIVE)          \
120       (trace)->live--;                                  \
121     if ((trace)->flags & GST_ALLOC_TRACE_MEM_LIVE)      \
122       (trace)->mem_live =                               \
123         g_slist_remove ((trace)->mem_live, mem);        \
124     g_mutex_unlock (&_gst_trace_mutex);          \
125   }                                                     \
126 } G_STMT_END
127
128 #else
129 #define _gst_alloc_trace_register(name) (NULL)
130 #define _gst_alloc_trace_new(trace, mem)
131 #define _gst_alloc_trace_free(trace, mem)
132 #define _gst_alloc_trace_dump()
133 #endif
134
135 #else /* GST_DISABLE_TRACE */
136
137 #define _gst_alloc_trace_register(name, offset)  (NULL)
138 #define _gst_alloc_trace_new(trace, mem)
139 #define _gst_alloc_trace_free(trace, mem)
140 #define _gst_alloc_trace_dump()
141
142 #endif /* GST_DISABLE_TRACE */
143
144 G_END_DECLS
145
146 #endif /* __GST_TRACE_H__ */