gstfunnel: avoid access of freed pad
[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., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23
24 #ifndef __GST_TRACE_H__
25 #define __GST_TRACE_H__
26
27 #include <glib.h>
28
29 G_BEGIN_DECLS
30
31 /**
32  * GstAllocTraceFlags:
33  * @GST_ALLOC_TRACE_NONE: No tracing specified or desired. Since 0.10.36.
34  * @GST_ALLOC_TRACE_LIVE: Trace number of non-freed memory.
35  * @GST_ALLOC_TRACE_MEM_LIVE: Trace pointers of unfreed memory.
36  *
37  * Flags indicating which tracing feature to enable.
38  */
39 typedef enum {
40   GST_ALLOC_TRACE_NONE      = 0,
41   GST_ALLOC_TRACE_LIVE      = (1 << 0),
42   GST_ALLOC_TRACE_MEM_LIVE  = (1 << 1)
43 } GstAllocTraceFlags;
44
45 typedef struct _GstAllocTrace   GstAllocTrace;
46
47 /**
48  * GstAllocTrace:
49  * @name: The name of the tracing object
50  * @flags: Flags for this object
51  * @offset: offset of the GType
52  * @live: counter for live memory
53  * @mem_live: list with pointers to unfreed memory
54  *
55  * The main tracing object
56  */
57 struct _GstAllocTrace {
58   gchar         *name;
59   gint           flags;
60
61   goffset        offset;
62   gint           live;
63   GSList        *mem_live;
64 };
65
66 #ifndef GST_DISABLE_TRACE
67
68 GST_EXPORT GMutex       _gst_trace_mutex;
69
70 void                    _priv_gst_alloc_trace_initialize (void);
71 void                    _priv_gst_alloc_trace_deinit     (void);
72 GstAllocTrace*          _priv_gst_alloc_trace_register   (const gchar *name, goffset offset);
73
74 void                    _priv_gst_alloc_trace_dump       (void);
75
76 #ifndef GST_DISABLE_ALLOC_TRACE
77 /**
78  * gst_alloc_trace_register:
79  * @name: The name of the tracer object
80  *
81  * Register a new alloc tracer with the given name
82  */
83 #define _gst_alloc_trace_register(name,offset) _priv_gst_alloc_trace_register (name,offset)
84
85 #define _gst_alloc_trace_dump                  _priv_gst_alloc_trace_dump
86
87 /**
88  * gst_alloc_trace_new:
89  * @trace: The tracer to use
90  * @mem: The memory allocated
91  *
92  * Use the tracer to trace a new memory allocation
93  */
94 #define _gst_alloc_trace_new(trace, mem)           \
95 G_STMT_START {                                          \
96   if (G_UNLIKELY ((trace)->flags)) {                    \
97     g_mutex_lock (&_gst_trace_mutex);            \
98     if ((trace)->flags & GST_ALLOC_TRACE_LIVE)          \
99       (trace)->live++;                                  \
100     if ((trace)->flags & GST_ALLOC_TRACE_MEM_LIVE)      \
101       (trace)->mem_live =                               \
102         g_slist_prepend ((trace)->mem_live, mem);       \
103     g_mutex_unlock (&_gst_trace_mutex);          \
104   }                                                     \
105 } G_STMT_END
106
107 /**
108  * gst_alloc_trace_free:
109  * @trace: The tracer to use
110  * @mem: The memory that is freed
111  *
112  * Trace a memory free operation
113  */
114 #define _gst_alloc_trace_free(trace, mem)                \
115 G_STMT_START {                                          \
116   if (G_UNLIKELY ((trace)->flags)) {                    \
117     g_mutex_lock (&_gst_trace_mutex);            \
118     if ((trace)->flags & GST_ALLOC_TRACE_LIVE)          \
119       (trace)->live--;                                  \
120     if ((trace)->flags & GST_ALLOC_TRACE_MEM_LIVE)      \
121       (trace)->mem_live =                               \
122         g_slist_remove ((trace)->mem_live, mem);        \
123     g_mutex_unlock (&_gst_trace_mutex);          \
124   }                                                     \
125 } G_STMT_END
126
127 #else
128 #define _gst_alloc_trace_register(name) (NULL)
129 #define _gst_alloc_trace_new(trace, mem)
130 #define _gst_alloc_trace_free(trace, mem)
131 #define _gst_alloc_trace_dump()
132 #endif
133
134 #else /* GST_DISABLE_TRACE */
135
136 #define _gst_alloc_trace_register(name, offset)  (NULL)
137 #define _gst_alloc_trace_new(trace, mem)
138 #define _gst_alloc_trace_free(trace, mem)
139 #define _gst_alloc_trace_dump()
140
141 #endif /* GST_DISABLE_TRACE */
142
143 G_END_DECLS
144
145 #endif /* __GST_TRACE_H__ */