diff options
author | Benjamin Otte <otte@gnome.org> | 2002-03-13 23:18:52 +0000 |
---|---|---|
committer | Benjamin Otte <otte@gnome.org> | 2002-03-13 23:18:52 +0000 |
commit | 6f099dfb0ca8a8d9ef7235249d8da6bc634ffaa3 (patch) | |
tree | 8072edb2aa8487529f9166041e4c89f9d5e38cb9 | |
parent | 8618dee2399822d7d88a401e7bdead3567027120 (diff) | |
download | gstreamer-6f099dfb0ca8a8d9ef7235249d8da6bc634ffaa3.tar.gz |
adding new file
Original commit message from CVS:
adding new file
-rw-r--r-- | gst/gstdata.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/gst/gstdata.c b/gst/gstdata.c new file mode 100644 index 0000000000..51abe7114d --- /dev/null +++ b/gst/gstdata.c @@ -0,0 +1,101 @@ +#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 + for (i = 0; i < GST_OFFSET_TYPES; i++) + { + data->offset[i] = 0; + } +} +void +gst_data_copy (GstData *to, const GstData *from) +{ + guint i; + + to->type = from->type; + to->dispose = from->dispose; + 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); + } +} +
\ No newline at end of file |