From 8e26c620fe9f4cd52e0dc3bec5964c89e9a1b2b6 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 27 Jan 2010 10:16:37 +0100 Subject: [PATCH] Small IOCHAN refactor. Introduce iochan_man_t --- src/eventl.c | 34 ++++++++++++++++++++++++++++++++-- src/eventl.h | 9 +++++++-- src/logic.c | 14 ++++++++++---- src/pazpar2.c | 1 + src/test_sel_thread.c | 4 +++- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/eventl.c b/src/eventl.c index bda6cd0..1251dfe 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -53,7 +53,32 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include "eventl.h" -#include + +struct iochan_man_s { + IOCHAN channel_list; +}; + +iochan_man_t iochan_man_create(void) +{ + iochan_man_t man = xmalloc(sizeof(*man)); + man->channel_list = 0; + return man; +} + +void iochan_man_destroy(iochan_man_t *mp) +{ + if (*mp) + { + xfree(*mp); + *mp = 0; + } +} + +void iochan_add(iochan_man_t man, IOCHAN chan) +{ + chan->next = man->channel_list; + man->channel_list = chan; +} IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags) { @@ -73,7 +98,7 @@ IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags) return new_iochan; } -int event_loop(IOCHAN *iochans) +static int event_loop(IOCHAN *iochans) { do /* loop as long as there are active associations to process */ { @@ -186,6 +211,11 @@ int event_loop(IOCHAN *iochans) return 0; } +void iochan_man_events(iochan_man_t man) +{ + event_loop(&man->channel_list); +} + /* * Local variables: * c-basic-offset: 4 diff --git a/src/eventl.h b/src/eventl.h index 0a6b07f..0eb8201 100644 --- a/src/eventl.h +++ b/src/eventl.h @@ -48,6 +48,13 @@ typedef struct iochan struct iochan *next; } *IOCHAN; +typedef struct iochan_man_s *iochan_man_t; + +iochan_man_t iochan_man_create(void); +void iochan_add(iochan_man_t man, IOCHAN chan); +void iochan_man_events(iochan_man_t man); +void iochan_man_destroy(iochan_man_t *mp); + #define iochan_destroy(i) (void)((i)->destroyed = 1) #define iochan_getfd(i) ((i)->fd) #define iochan_setfd(i, f) ((i)->fd = (f)) @@ -61,7 +68,6 @@ typedef struct iochan #define iochan_getfun(i) ((i)->fun) #define iochan_setfun(i, d) ((i)->fun = d) #define iochan_setevent(i, e) ((i)->force_event = (e)) -#define iochan_getnext(i) ((i)->next) #define iochan_settimeout(i, t) ((i)->max_idle = (t), (i)->last_event = time(0)) #define iochan_activity(i) ((i)->last_event = time(0)) #define iochan_setsocketfun(i, f) ((i)->socketfun = (f)) @@ -70,6 +76,5 @@ typedef struct iochan #define iochan_getmaskfun(i) ((i)->maskfun) IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags); -int event_loop(IOCHAN *iochans); #endif diff --git a/src/logic.c b/src/logic.c index be2ec04..598b815 100644 --- a/src/logic.c +++ b/src/logic.c @@ -808,17 +808,23 @@ void statistics(struct session *se, struct statistics *stat) // Master list of connections we're handling events to -static IOCHAN channel_list = 0; /* thread pr */ +static iochan_man_t pazpar2_chan_man = 0; /* thread pr */ + +void pazpar2_chan_man_start(void) +{ + pazpar2_chan_man = iochan_man_create(); +} void pazpar2_add_channel(IOCHAN chan) { - chan->next = channel_list; - channel_list = chan; + assert(pazpar2_chan_man); + iochan_add(pazpar2_chan_man, chan); } void pazpar2_event_loop() { - event_loop(&channel_list); + assert(pazpar2_chan_man); + iochan_man_events(pazpar2_chan_man); } static struct record_metadata *record_metadata_init( diff --git a/src/pazpar2.c b/src/pazpar2.c index 4905399..3a43ed5 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -194,6 +194,7 @@ static int sc_main( "mode"); return 1; } + pazpar2_chan_man_start(); ret = config_start_listeners(config, listener_override); if (ret) return ret; /* error starting http listener */ diff --git a/src/test_sel_thread.c b/src/test_sel_thread.c index 896234e..6ec7ec8 100644 --- a/src/test_sel_thread.c +++ b/src/test_sel_thread.c @@ -107,12 +107,14 @@ static void test_for_real_work(int no_threads) YAZ_CHECK(p); if (p) { + iochan_man_t chan_man = iochan_man_create(); IOCHAN chan = iochan_create(thread_fd, iochan_handler, EVENT_INPUT|EVENT_TIMEOUT); iochan_settimeout(chan, 1); iochan_setdata(chan, p); + iochan_add(chan_man, chan); - event_loop(&chan); + iochan_man_events(chan_man); sel_thread_destroy(p); } } -- 1.7.10.4