[Spice-devel] [PATCH spice-gtk 1/4] Add spice_audio_get()

Christophe Fergeau cfergeau at redhat.com
Mon Nov 7 00:28:07 PST 2011


On Sat, Nov 05, 2011 at 05:56:06PM +0100, Marc-André Lureau wrote:
> We are going to deprecate spice_audio_new()
> some day. There are a few know problems:
> - SpiceAudio is an abstract class,
>   so it can't have a ctor
> - SpiceAudio should be a singleton,
>   associated with the session lifetime
> - SpiceSession should have a enable-audio property,
>   internal code should be able to access the audio object
> 
> That way of getting the audio object is similar to the smartcard manager and usb manager.
> ---
> +{
> +    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
> +    SpiceAudio *self;
> +
> +    g_static_mutex_lock(&mutex);
> +    self = g_object_get_data(G_OBJECT(session), "spice-audio");
> +    if (self == NULL) {
> +        self = spice_audio_new(session, context, NULL);
> +        g_object_set_data(G_OBJECT(session), "spice-audio", self);
> +        if (self)
> +            g_object_weak_ref(G_OBJECT(session), (GWeakNotify)g_object_unref, self);
> +    }
> +    g_static_mutex_unlock(&mutex);
> +
> +    return self;
> +}

Is there any reason for not using a GOnce here?

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20111107/47f43126/attachment-0001.pgp>


More information about the Spice-devel mailing list