From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:34680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmBYO-0000AC-LI for qemu-devel@nongnu.org; Wed, 27 Jul 2011 17:22:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QmBYN-00015x-Jn for qemu-devel@nongnu.org; Wed, 27 Jul 2011 17:22:08 -0400 Received: from mail-pz0-f43.google.com ([209.85.210.43]:50004) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmBYN-00015g-Ex for qemu-devel@nongnu.org; Wed, 27 Jul 2011 17:22:07 -0400 Received: by pzk1 with SMTP id 1so3471413pzk.30 for ; Wed, 27 Jul 2011 14:22:06 -0700 (PDT) Message-ID: <4E30817A.3070705@codemonkey.ws> Date: Wed, 27 Jul 2011 16:22:02 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1311725174-9635-1-git-send-email-aliguori@us.ibm.com> <4E307999.9080603@us.ibm.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] [RFC] Add glib support to main loop List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: Amit Shah , Paolo Bonzini , qemu-devel@nongnu.org, Hans de Goede On 07/27/2011 04:12 PM, Blue Swirl wrote: > On Wed, Jul 27, 2011 at 11:48 PM, Anthony Liguori wrote: >> On 07/27/2011 03:43 PM, Blue Swirl wrote: >>> >>> On Wed, Jul 27, 2011 at 3:06 AM, Anthony Liguori >>> wrote: >>>> >>>> This allows GSources to be used to register callback events in QEMU. >>>> This is >>>> useful as it allows us to take greater advantage of glib and also because >>>> it >>>> allows us to write code that is more easily testable outside of QEMU >>>> since we >>>> can make use of glib's main loop in unit tests. >>>> >>>> All new code should use glib's callback mechanisms for registering fd >>>> events >>>> which are very well documented at: >>>> >>>> http://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html >>>> >>>> And: >>>> >>>> http://developer.gnome.org/gio/stable/ >>>> >>>> Signed-off-by: Anthony Liguori >>>> --- >>>> vl.c | 74 >>>> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >>>> 1 files changed, 74 insertions(+), 0 deletions(-) >>>> >>>> diff --git a/vl.c b/vl.c >>>> index 4b6688b..19774ac 100644 >>>> --- a/vl.c >>>> +++ b/vl.c >>>> @@ -111,6 +111,8 @@ int main(int argc, char **argv) >>>> #define main qemu_main >>>> #endif /* CONFIG_COCOA */ >>>> >>>> +#include >>>> + >>>> #include "hw/hw.h" >>>> #include "hw/boards.h" >>>> #include "hw/usb.h" >>>> @@ -1309,6 +1311,75 @@ void qemu_system_vmstop_request(int reason) >>>> qemu_notify_event(); >>>> } >>>> >>>> +static GPollFD poll_fds[1024 * 2]; /* this is probably overkill */ >>>> +static int n_poll_fds; >>>> +static int max_priority; >>>> + >>>> +static void glib_select_fill(int *max_fd, fd_set *rfds, fd_set *wfds, >>>> + fd_set *xfds, struct timeval *tv) >>>> +{ >>>> + GMainContext *context = g_main_context_default(); >>>> + int i; >>>> + int timeout = 0, cur_timeout; >>>> + >>>> + g_main_context_prepare(context,&max_priority); >>>> + >>>> + n_poll_fds = g_main_context_query(context, max_priority,&timeout, >>>> + poll_fds, ARRAY_SIZE(poll_fds)); >>>> + g_assert(n_poll_fds<= ARRAY_SIZE(poll_fds)); >>> >>> The use of g_assert() means that production code should define >>> G_DISABLE_ASSERT in addition to NDEBUG. Should we make both default >>> for stable versions? >> >> Oh, this is just me being lazy. There's a way to do this without using the >> assert. I put the assert there to make sure that I didn't leave a latent >> bug. >> >> But in general, I don't think we should ever define NDEBUG. > > Why? I think it's normal practice to define NDEBUG (and > G_DISABLE_ASSERT if g_assert() is used) for production builds. Heh, I guess this is a stylistic thing. The theory is that if you do all of your testing with !defined(NDEBUG), then you wouldn't want to ship something that potentially introduces different code paths to the end user. Besides, if an assert would trigger, I'd rather it drop core and have a predictable error verses an unpredictable behavior. Regards, Anthony Liguori