diff options
author | Philippe Normand <pnormand@igalia.com> | 2010-07-15 10:10:31 +0200 |
---|---|---|
committer | Tim-Philipp Müller <tim.muller@collabora.co.uk> | 2010-08-04 16:19:09 +0100 |
commit | 864a52d8aa938fbc308a5bf027cbc4bd8a23d45e (patch) | |
tree | 370a106ddc93ff7c0e7fd219150f53ad6fb4e228 | |
parent | f6240a47731643678e1eb41d63de52bb3514e312 (diff) |
pulsesink: use G_TYPE_DEFINE to define ring buffer type
The existing get_type() implementation is racy, and the
g_type_class_ref() workaround didn't actually work because
it was in the wrong function. Since class creation in GObject
is thread-safe these days (since 2.16), the class_ref workaround
is no longer needed and it is sufficient to ensure the _get_type()
function is thread-safe, which G_TYPE_DEFINE does.
https://bugzilla.gnome.org/show_bug.cgi?id=624338
-rw-r--r-- | ext/pulse/pulsesink.c | 38 |
1 files changed, 3 insertions, 35 deletions
diff --git a/ext/pulse/pulsesink.c b/ext/pulse/pulsesink.c index 9feaed388..3f6f7baae 100644 --- a/ext/pulse/pulsesink.c +++ b/ext/pulse/pulsesink.c @@ -131,9 +131,7 @@ struct _GstPulseRingBufferClass GstRingBufferClass parent_class; }; -static void gst_pulseringbuffer_class_init (GstPulseRingBufferClass * klass); -static void gst_pulseringbuffer_init (GstPulseRingBuffer * ringbuffer, - GstPulseRingBufferClass * klass); +static GType gst_pulseringbuffer_get_type (void); static void gst_pulseringbuffer_finalize (GObject * object); static GstRingBufferClass *ring_parent_class = NULL; @@ -151,32 +149,7 @@ static guint gst_pulseringbuffer_commit (GstRingBuffer * buf, guint64 * sample, guchar * data, gint in_samples, gint out_samples, gint * accum); -/* ringbuffer abstract base class */ -static GType -gst_pulseringbuffer_get_type (void) -{ - static GType ringbuffer_type = 0; - - if (!ringbuffer_type) { - static const GTypeInfo ringbuffer_info = { - sizeof (GstPulseRingBufferClass), - NULL, - NULL, - (GClassInitFunc) gst_pulseringbuffer_class_init, - NULL, - NULL, - sizeof (GstPulseRingBuffer), - 0, - (GInstanceInitFunc) gst_pulseringbuffer_init, - NULL - }; - - ringbuffer_type = - g_type_register_static (GST_TYPE_RING_BUFFER, "GstPulseSinkRingBuffer", - &ringbuffer_info, 0); - } - return ringbuffer_type; -} +G_DEFINE_TYPE (GstPulseRingBuffer, gst_pulseringbuffer, GST_TYPE_RING_BUFFER); static void gst_pulseringbuffer_class_init (GstPulseRingBufferClass * klass) @@ -207,15 +180,10 @@ gst_pulseringbuffer_class_init (GstPulseRingBufferClass * klass) GST_DEBUG_FUNCPTR (gst_pulseringbuffer_clear); gstringbuffer_class->commit = GST_DEBUG_FUNCPTR (gst_pulseringbuffer_commit); - - /* ref class from a thread-safe context to work around missing bit of - * thread-safety in GObject */ - g_type_class_ref (GST_TYPE_PULSERING_BUFFER); } static void -gst_pulseringbuffer_init (GstPulseRingBuffer * pbuf, - GstPulseRingBufferClass * g_class) +gst_pulseringbuffer_init (GstPulseRingBuffer * pbuf) { pbuf->stream_name = NULL; pbuf->context = NULL; |