[Spice-devel] [RFC PATCH] initialize global images at load time

Victor Toso lists at victortoso.com
Mon Feb 29 10:23:31 UTC 2016


Hi,

On Sat, Feb 27, 2016 at 01:36:23PM -0500, Frediano Ziglio wrote:
> >
> > Hi,
> > 
> > On Fri, Feb 26, 2016 at 10:37:21AM +0000, Frediano Ziglio wrote:
> > > This make sure these stuff are initialized without using runtime
> > > resources.
> > > Also make sure stuff are initialize really earlier.
> > >
> > > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > > ---
> > >  server/red-dispatcher.c | 13 ++++++-------
> > >  1 file changed, 6 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/server/red-dispatcher.c b/server/red-dispatcher.c
> > > index c2ca6b6..d09d56d 100644
> > > --- a/server/red-dispatcher.c
> > > +++ b/server/red-dispatcher.c
> > > @@ -902,6 +902,12 @@ void red_dispatcher_async_complete(struct
> > > RedDispatcher *dispatcher,
> > >      free(async_command);
> > >  }
> > >
> > > +static void __attribute__((constructor)) red_dispatcher_global_init(void)
> > > +{
> > > +    quic_init();
> > > +    sw_canvas_init();
> > > +}
> >
> > We could have a define for it in spice-common and use it in a few more
> > places I think. Also, it seems to be gcc specific so a #define could
> > help dealing with other compilers.
> >
> >
> > Cheers,
> >   toso
> >
>
> Looks like this could be a solution
>
> http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc
>
> constructor attribute is implemented in gcc and clang.
> Static initialization is common in other languages (C++ and Java for instance) so
> object files have a standard (for each architecture/compiler) to specify it.
> Sun compiler have some #pragma (init/fini).

Hmm, I was checking if glib does not have it and it seems that they
don't. gio seems to use it [0] internally

https://git.gnome.org/browse/glib/diff/glib/gconstructor.h?id=968f4e8d79b31

> Which type of compilers are we addressing?

Only gcc AFAIK. But I would love to fix all warnings with clang at some
point.

>
> I think a SPICE_CONSTRUCTOR_FUNCTION(function_name) could work.
> It's possible (if needed) to define similar macro for destruction (actually better
> than calling atexit in a library/shared object).
>
> Frediano

I agree.

cheers,
  toso

>
> > > +
> > >  void red_dispatcher_init(QXLInstance *qxl)
> > >  {
> > >      RedDispatcher *red_dispatcher;
> > > @@ -911,13 +917,6 @@ void red_dispatcher_init(QXLInstance *qxl)
> > >      spice_return_if_fail(qxl != NULL);
> > >      spice_return_if_fail(qxl->st->dispatcher == NULL);
> > >  
> > > -    static gsize initialized = FALSE;
> > > -    if (g_once_init_enter(&initialized)) {
> > > -        quic_init();
> > > -        sw_canvas_init();
> > > -        g_once_init_leave(&initialized, TRUE);
> > > -    }
> > > -
> > >      red_dispatcher = spice_new0(RedDispatcher, 1);
> > >      red_dispatcher->qxl = qxl;
> > >      dispatcher_init(&red_dispatcher->dispatcher, RED_WORKER_MESSAGE_COUNT,
> > >      NULL);
> 


More information about the Spice-devel mailing list