gstreamer/gst/gstdata.c
Benjamin Otte 0aa86db75c - rewrite of GstQueue, hope it works now, though I'm not absolutely sure there couldn'T be a deadlock
Original commit message from CVS:
- rewrite of GstQueue, hope it works now, though I'm not absolutely sure there couldn'T be a deadlock
- fixes to GstThread (this thing has to work without calling queues\!)
- changes to scheduler (use GAsyncQueue for events)
2002-03-17 00:50:42 +00:00

103 lines
No EOL
2.4 KiB
C

#include "gstdata.h"
/* debugging and error checking */
#include "gstlog.h"
#include "gstinfo.h"
static void gst_data_destroy (GstData *data);
static void gst_data_free (GstData *data);
void
gst_data_init (GstData *data)
{
guint i;
data->dispose = gst_data_dispose;
data->free = gst_data_free;
#ifdef HAVE_ATOMIC_H
atomic_set (&data->refcount, 1);
#else
data->refcount = 1;
data->reflock = g_mutex_new();
#endif
data->flags = 0;
for (i = 0; i < GST_OFFSET_TYPES; i++)
{
data->offset[i] = GST_OFFSET_INVALID;
}
}
void
gst_data_copy (GstData *to, const GstData *from)
{
guint i;
g_assert (to->type == from->type);
to->flags = from->flags & (~GST_DATA_READONLY);
for (i = 0; i < GST_OFFSET_TYPES; i++)
{
to->offset[i] = from->offset[i];
}
}
void
gst_data_dispose (GstData *data)
{
#ifdef HAVE_ATOMIC_H
#else
g_mutex_free (data->reflock);
#endif
}
static void
gst_data_free (GstData *data)
{
g_free (data);
}
static void
gst_data_destroy (GstData *data)
{
GST_DEBUG (GST_CAT_BUFFER, "destroying %p (type %d)\n", data, data->type);
data->dispose (data);
data->free (data);
}
void
gst_data_ref (GstData* data)
{
g_return_if_fail (data != NULL);
#ifdef HAVE_ATOMIC_H
GST_DEBUG (GST_CAT_BUFFER, "ref data %p, current count is %d", data, atomic_read (&data->refcount));
g_return_if_fail (atomic_read (&data->refcount) > 0);
atomic_inc (&data->refcount);
#else
GST_INFO (GST_CAT_BUFFER, "ref data %p, current count is %d", data, data->refcount);
g_return_if_fail (data->refcount > 0);
g_mutex_lock (data->reflock);
buffer->refcount++;
g_mutex_unlock (data->reflock);
#endif
}
void
gst_data_unref (GstData* data)
{
gint destroy;
g_return_if_fail (data != NULL);
#ifdef HAVE_ATOMIC_H
GST_DEBUG (GST_CAT_BUFFER, "unref data %p (type %d), current count is %d\n", data, data->type, atomic_read (&data->refcount));
g_return_if_fail (atomic_read (&data->refcount) > 0);
destroy = atomic_dec_and_test (&data->refcount);
#else
GST_DEBUG (GST_CAT_BUFFER, "unref data %p (type %d), current count is %d\n", data, data->type, atomic_read (&data->refcount));
g_return_if_fail (data->refcount > 0);
g_mutex_lock (data->reflock);
data->refcount--;
destroy = (buffer->refcount == 0);
g_mutex_lock (data->reflock);
#endif
/* if we ended up with the refcount at zero, destroy the buffer */
if (destroy) {
gst_data_destroy (data);
}
}