qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] glib: move compat functions into glib-compat.h
@ 2014-02-03 13:31 Stefan Hajnoczi
  2014-02-03 13:31 ` [Qemu-devel] [PATCH 1/3] glib: move g_poll() replacement " Stefan Hajnoczi
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Stefan Hajnoczi @ 2014-02-03 13:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Anthony Liguori

glib has deprecated APIs like GStaticMutex, g_thread_create(), and others.  In
QEMU support both old and new APIs since using deprecated APIs would flood us
with warnings but legacy distros must continue to build the QEMU source code.

This patch series reduces ifdefs by moving glib compat functions into
glib-compat.h, where they can be reused.

There are two strategies for compat functions:

1. Implement the new API using the deprecated API.  This compat function is
   used when building on a legacy host.  Sometimes the API semantics are so
   different that this option is not feasible.

2. Add a new wrapper API that maps to the deprecated API.  The wrapper is not
   marked deprecated so it works as a drop-in replacement but is implemented
   using the new API where possible.

Stefan Hajnoczi (3):
  glib: move g_poll() replacement into glib-compat.h
  glib: add g_thread_new() compat function
  glib: add compat wrapper for GStaticMutex

 coroutine-gthread.c   | 26 ++++++++++----------------
 include/glib-compat.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 include/qemu-common.h | 12 ------------
 trace/simple.c        | 31 ++++++++++---------------------
 4 files changed, 64 insertions(+), 49 deletions(-)

-- 
1.8.5.3

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH 3/3] glib: add compat wrapper for GStaticMutex
@ 2014-05-02 11:08 Michael Tokarev
  2014-05-05 12:11 ` Stefan Hajnoczi
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Tokarev @ 2014-05-02 11:08 UTC (permalink / raw)
  To: stefanha; +Cc: qemu-devel

Stefan Hajnoczi:

> Avoid duplicating ifdefs for the deprecated GStaticMutex API by
> introducing compat_g_static_mutex_*() in glib-compat.h.
>
> GStaticMutex users should use the compat API to avoid dealing with
> deprecation.

To my taste this is a wrong(ish) approach.

GStaticMutex is nothing more than a pointer to GMutex wrapped in an internal
structure, and each function from g_static_mutex_* family first checks for
this pointer, whenever it is initialized, and calls g_mutex_new() if not.
So if there's a good place to actually init (allocate) a GMutex, it is better
to use it directly instead of checking for the init in every place.

(Note also that this checking itself may need a protection using a mutex,
to avoid 2 threads allocating the same GStaticMutex ;) -- this is done in
g_static_mutex_get_mutex_impl() inside glib).

But that's cosmetics.

More to the point is that this is re-introduction of old API for new program.
It'd be very nice if we were able to actually use the new API everywhere,
instead of re-introducing old API.

And this introduces some (light) wrapper #ifdefery too.

So we not only will use the old API in the code, we also will use wrappers
for almost everything.  So it becomes rather clumsy.

It is, I think, better to try to switch to the new API as much as possible,
or to use our own types and wrappers instead, without resoting to use
foo_compat_deprecated_* (where "deprecated" part comes from staticmutex --
ie, instead of regular g_mutex_foo, we use g_compat_static_mutex_foo).

Other the bit of clumsiness, this should work.


> +/* GStaticMutex was deprecated in 2.32.0.  Use the compat_g_static_mutex_*()
> + * wrappers to hide the GStaticMutex/GMutex distinction.
> + */
> +#if GLIB_CHECK_VERSION(2, 32, 0)

It is actually deprecated in 2.31, even if the glib docs says 2.32.
Probably not a big deal, as, I think, there's no 2.31 glib in the wild
due to bugs in there, so they had to quickly release 2.32.

Thanks,

/mjt

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-05-05 12:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-03 13:31 [Qemu-devel] [PATCH 0/3] glib: move compat functions into glib-compat.h Stefan Hajnoczi
2014-02-03 13:31 ` [Qemu-devel] [PATCH 1/3] glib: move g_poll() replacement " Stefan Hajnoczi
2014-02-03 13:31 ` [Qemu-devel] [PATCH 2/3] glib: add g_thread_new() compat function Stefan Hajnoczi
2014-02-03 13:31 ` [Qemu-devel] [PATCH 3/3] glib: add compat wrapper for GStaticMutex Stefan Hajnoczi
2014-02-14 12:31 ` [Qemu-devel] [PATCH 0/3] glib: move compat functions into glib-compat.h Stefan Hajnoczi
2014-05-02  9:35 ` Stefan Hajnoczi
  -- strict thread matches above, loose matches on Subject: below --
2014-05-02 11:08 [Qemu-devel] [PATCH 3/3] glib: add compat wrapper for GStaticMutex Michael Tokarev
2014-05-05 12:11 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).