From patchwork Thu Jan 22 00:26:54 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 19749 X-Patchwork-Delegate: jk@ozlabs.org Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 04AA7DE285 for ; Thu, 22 Jan 2009 14:38:31 +1100 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E2C77DDF80; Thu, 22 Jan 2009 14:32:11 +1100 (EST) Received: from hera.kernel.org (IDENT:U2FsdGVkX18QsqpbbERjQ9MXXM/OCn52YoVoULB77Y8@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n0M39vBV002822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 22 Jan 2009 03:09:57 GMT Received: (from geoff@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n0M39uPW002821; Thu, 22 Jan 2009 03:09:56 GMT Message-Id: <20090122002653.250342945@am.sony.com> References: <20090122002653.146035454@am.sony.com> In-Reply-To: <20090122002653.146035454@am.sony.com> User-Agent: quilt/0.46-1 Date: Wed, 21 Jan 2009 16:26:54 -0800 From: Geoff Levand To: Jeremy Kerr Content-Disposition: inline; filename=move-waiter-to-lib.diff X-Virus-Scanned: ClamAV 0.93.3/8886/Wed Jan 21 22:46:06 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Thu, 22 Jan 2009 03:09:58 +0000 (UTC) Cc: cbe-oss-dev@ozlabs.org Subject: [Cbe-oss-dev] [patch 1/9] petitboot: Move waiter to library X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Move the waiter routines into the petitboot library. The waiter routines are generic enough to be used for both server and client. Does not change the waiter source. Signed-off-by: Geoff Levand --- discover/waiter.c | 83 ------------------------------------------------------ discover/waiter.h | 23 -------------- lib/waiter.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/waiter.h | 23 ++++++++++++++ rules.mk | 5 +-- 5 files changed, 109 insertions(+), 108 deletions(-) --- a/discover/waiter.c +++ /dev/null @@ -1,83 +0,0 @@ - -#include -#include -#include - -#include - -#include "waiter.h" - -struct waiter { - int fd; - int events; - waiter_cb callback; - void *arg; -}; - -static struct waiter *waiters; -static int n_waiters; - -struct waiter *waiter_register(int fd, int events, - waiter_cb callback, void *arg) -{ - struct waiter *waiter; - - n_waiters++; - - waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters); - waiter = &waiters[n_waiters - 1]; - - waiter->fd = fd; - waiter->events = events; - waiter->callback = callback; - waiter->arg = arg; - - return 0; -} - -void waiter_remove(struct waiter *waiter) -{ - int i; - - i = waiter - waiters; - assert(i >= 0 && i < n_waiters); - - n_waiters--; - memmove(&waiters[i], &waiters[i+1], n_waiters - i); - - waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters); -} - -int waiter_poll(void) -{ - static struct pollfd *pollfds; - static int n_pollfds; - int i, rc; - - if (n_waiters > n_pollfds) { - pollfds = talloc_realloc(NULL, pollfds, - struct pollfd, n_waiters); - } - - for (i = 0; i < n_waiters; i++) { - pollfds[i].fd = waiters[i].fd; - pollfds[i].events = waiters[i].events; - pollfds[i].revents = 0; - } - - rc = poll(pollfds, n_waiters, -1); - - if (rc <= 0) - return rc; - - for (i = 0; i < n_waiters; i++) { - if (pollfds[i].revents) { - rc = waiters[i].callback(waiters[i].arg); - - if (rc) - waiter_remove(&waiters[i]); - } - } - - return 0; -} --- a/discover/waiter.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _WAITER_H -#define _WAITER_H - -#include - -struct waiter; - -enum events { - WAIT_IN = POLLIN, - WAIT_OUT = POLLOUT, -}; - -typedef int (*waiter_cb)(void *); - -struct waiter *waiter_register(int fd, int events, - waiter_cb callback, void *arg); - -void waiter_remove(struct waiter *waiter); - -int waiter_poll(void); -#endif /* _WAITER_H */ - - --- /dev/null +++ b/lib/waiter.c @@ -0,0 +1,83 @@ + +#include +#include +#include + +#include + +#include "waiter.h" + +struct waiter { + int fd; + int events; + waiter_cb callback; + void *arg; +}; + +static struct waiter *waiters; +static int n_waiters; + +struct waiter *waiter_register(int fd, int events, + waiter_cb callback, void *arg) +{ + struct waiter *waiter; + + n_waiters++; + + waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters); + waiter = &waiters[n_waiters - 1]; + + waiter->fd = fd; + waiter->events = events; + waiter->callback = callback; + waiter->arg = arg; + + return 0; +} + +void waiter_remove(struct waiter *waiter) +{ + int i; + + i = waiter - waiters; + assert(i >= 0 && i < n_waiters); + + n_waiters--; + memmove(&waiters[i], &waiters[i+1], n_waiters - i); + + waiters = talloc_realloc(NULL, waiters, struct waiter, n_waiters); +} + +int waiter_poll(void) +{ + static struct pollfd *pollfds; + static int n_pollfds; + int i, rc; + + if (n_waiters > n_pollfds) { + pollfds = talloc_realloc(NULL, pollfds, + struct pollfd, n_waiters); + } + + for (i = 0; i < n_waiters; i++) { + pollfds[i].fd = waiters[i].fd; + pollfds[i].events = waiters[i].events; + pollfds[i].revents = 0; + } + + rc = poll(pollfds, n_waiters, -1); + + if (rc <= 0) + return rc; + + for (i = 0; i < n_waiters; i++) { + if (pollfds[i].revents) { + rc = waiters[i].callback(waiters[i].arg); + + if (rc) + waiter_remove(&waiters[i]); + } + } + + return 0; +} --- /dev/null +++ b/lib/waiter.h @@ -0,0 +1,23 @@ +#ifndef _WAITER_H +#define _WAITER_H + +#include + +struct waiter; + +enum events { + WAIT_IN = POLLIN, + WAIT_OUT = POLLOUT, +}; + +typedef int (*waiter_cb)(void *); + +struct waiter *waiter_register(int fd, int events, + waiter_cb callback, void *arg); + +void waiter_remove(struct waiter *waiter); + +int waiter_poll(void); +#endif /* _WAITER_H */ + + --- a/rules.mk +++ b/rules.mk @@ -16,6 +16,7 @@ artwork = background.jpg cdrom.png hdd.p talloc_objs = lib/talloc/talloc.o list_objs = lib/list/list.o +waiter_objs = lib/waiter.o server_objs = lib/pb-protocol/pb-protocol.o parser_objs = discover/parser.o discover/parser-utils.o \ $(foreach p, $(parsers), discover/$(p)-parser.o) @@ -46,8 +47,8 @@ ui/test/pb-test: $(pb_test_objs) # $(foreach p,$(parsers),discover/$(p)-parser.o) pb_discover_objs = discover/pb-discover.o discover/udev.o discover/log.o \ - discover/waiter.o discover/discover-server.o \ - discover/device-handler.o discover/paths.o \ + discover/discover-server.o discover/device-handler.o \ + discover/paths.o $(waiter_objs) \ $(talloc_objs) $(server_objs) $(parser_objs) $(list_objs) discover/pb-discover: $(pb_discover_objs)