From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVeoA-0000WA-9p for qemu-devel@nongnu.org; Fri, 26 Apr 2013 05:19:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UVeo7-0001x9-Qj for qemu-devel@nongnu.org; Fri, 26 Apr 2013 05:19:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46130) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVeo7-0001wV-Js for qemu-devel@nongnu.org; Fri, 26 Apr 2013 05:19:07 -0400 Date: Fri, 26 Apr 2013 11:19:00 +0200 From: Stefan Hajnoczi Message-ID: <20130426091900.GC17609@stefanha-thinkpad.redhat.com> References: <1366944455-14239-1-git-send-email-qemulist@gmail.com> <1366944455-14239-2-git-send-email-qemulist@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1366944455-14239-2-git-send-email-qemulist@gmail.com> Subject: Re: [Qemu-devel] [RFC PATCH v5 01/14] util: introduce gsource event abstraction List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Ping Fan Cc: mdroth , Jan Kiszka , qemu-devel@nongnu.org, Anthony Liguori , Paolo Bonzini On Fri, Apr 26, 2013 at 10:47:22AM +0800, Liu Ping Fan wrote: > +GPollFD *events_source_add_gfd(EventsGSource *src, int fd) > +{ > + GPollFD *retfd; > + > + retfd = g_slice_alloc(sizeof(GPollFD)); > + retfd->events = 0; > + retfd->fd = fd; > + src->pollfds_list = g_list_append(src->pollfds_list, retfd); > + if (fd > 0) { 0 (stdin) is a valid fd number. Maybe just assert(fd >= 0)? > +static gboolean events_source_check(GSource *src) > +{ > + EventsGSource *nsrc = (EventsGSource *)src; > + GList *cur; > + GPollFD *gfd; > + > + cur = nsrc->pollfds_list; > + while (cur) { > + gfd = cur->data; > + if (gfd->fd > 0 && (gfd->revents & gfd->events)) { revents will always be 0 if fd is invalid, since we didn't call g_source_add_poll(). Is there a reason to perform the fd > 0 check again? > +void events_source_release(EventsGSource *src) > +{ assert that pollfds_list is empty? We don't g_slice_free() GPollFDs so it must be empty here.