From cb1ab5633b112e083fa252712f8fc667373a93af Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 19 Jan 2012 15:15:57 -0500 Subject: Refactor workers init so we can pass down gpctx --- proxy/src/gp_utils.h | 3 ++- proxy/src/gp_workers.c | 17 ++++++++++------- proxy/src/gssproxy.c | 6 ++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/proxy/src/gp_utils.h b/proxy/src/gp_utils.h index 38ca400..fb77cd7 100644 --- a/proxy/src/gp_utils.h +++ b/proxy/src/gp_utils.h @@ -70,6 +70,7 @@ struct gp_workers; struct gssproxy_ctx { struct gp_config *config; struct gp_workers *workers; + verto_ctx *vctx; }; struct gp_conn; @@ -90,7 +91,7 @@ void gp_socket_send_data(verto_ctx *vctx, struct gp_conn *conn, uint8_t *buffer, size_t buflen); /* from gp_workers.c */ -struct gp_workers *gp_workers_init(verto_ctx *vctx, struct gp_config *cfg); +int gp_workers_init(struct gssproxy_ctx *gpctx); void gp_workers_free(struct gp_workers *w); int gp_query_new(struct gp_workers *w, struct gp_conn *conn, uint8_t *buffer, size_t buflen); diff --git a/proxy/src/gp_workers.c b/proxy/src/gp_workers.c index 3dcefac..3d5467b 100644 --- a/proxy/src/gp_workers.c +++ b/proxy/src/gp_workers.c @@ -63,6 +63,7 @@ struct gp_thread { struct gp_workers { pthread_mutex_t lock; + struct gssproxy_ctx *gpctx; bool shutdown; struct gp_query *wait_list; struct gp_query *reply_list; @@ -78,7 +79,7 @@ static void gp_handle_reply(verto_ctx *vctx, verto_ev *ev); /** DISPATCHER FUNCTIONS **/ -struct gp_workers *gp_workers_init(verto_ctx *vctx, struct gp_config *cfg) +int gp_workers_init(struct gssproxy_ctx *gpctx) { struct gp_workers *w; struct gp_thread *t; @@ -90,18 +91,19 @@ struct gp_workers *gp_workers_init(verto_ctx *vctx, struct gp_config *cfg) w = calloc(1, sizeof(struct gp_workers)); if (!w) { - return NULL; + return ENOMEM; } + w->gpctx = gpctx; /* init global queue mutex */ ret = pthread_mutex_init(&w->lock, NULL); if (ret) { free(w); - return NULL; + return ENOMEM; } - if (cfg->num_workers > 0) { - w->num_threads = cfg->num_workers; + if (gpctx->config->num_workers > 0) { + w->num_threads = gpctx->config->num_workers; } else { w->num_threads = DEFAULT_WORKER_THREADS_NUM; } @@ -141,20 +143,21 @@ struct gp_workers *gp_workers_init(verto_ctx *vctx, struct gp_config *cfg) } vflags = VERTO_EV_FLAG_PERSIST | VERTO_EV_FLAG_IO_READ; - ev = verto_add_io(vctx, vflags, gp_handle_reply, w->sig_pipe[0]); + ev = verto_add_io(gpctx->vctx, vflags, gp_handle_reply, w->sig_pipe[0]); if (!ev) { ret = -1; goto done; } verto_set_private(ev, w, NULL); + gpctx->workers = w; ret = 0; done: if (ret) { gp_workers_free(w); } - return w; + return ret; } void gp_workers_free(struct gp_workers *w) diff --git a/proxy/src/gssproxy.c b/proxy/src/gssproxy.c index 9bfad08..2f25899 100644 --- a/proxy/src/gssproxy.c +++ b/proxy/src/gssproxy.c @@ -41,6 +41,7 @@ int main(int argc, const char *argv[]) int vflags; int fd; struct gssproxy_ctx *gpctx; + int ret; struct poptOption long_options[] = { POPT_AUTOHELP @@ -99,6 +100,7 @@ int main(int argc, const char *argv[]) if (!vctx) { return 1; } + gpctx->vctx = vctx; vflags = VERTO_EV_FLAG_PERSIST | VERTO_EV_FLAG_IO_READ; ev = verto_add_io(vctx, vflags, accept_sock_conn, fd); @@ -107,8 +109,8 @@ int main(int argc, const char *argv[]) } verto_set_private(ev, gpctx, NULL); - gpctx->workers = gp_workers_init(vctx, gpctx->config); - if (!gpctx->workers) { + ret = gp_workers_init(gpctx); + if (ret) { exit(EXIT_FAILURE); } -- cgit