--- libaitrpc/src/srv.c 2012/11/05 17:06:51 1.11.2.4 +++ libaitrpc/src/srv.c 2012/11/13 09:21:27 1.11.2.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srv.c,v 1.11.2.4 2012/11/05 17:06:51 misho Exp $ +* $Id: srv.c,v 1.11.2.5 2012/11/13 09:21:27 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -737,13 +737,16 @@ rpc_srv_initServer(u_int regProgID, u_char regProcID, srv->srv_server.cli_parent = srv; memcpy(&srv->srv_server.cli_sa, &sa, sizeof srv->srv_server.cli_sa); - /* init functions list */ - TAILQ_INIT(&srv->srv_funcs); + /* init functions */ + pthread_mutex_init(&srv->srv_funcs.mtx, NULL); + SLIST_INIT(&srv->srv_funcs); + AVL_INIT(&srv->srv_funcs); /* init scheduler */ srv->srv_root = schedBegin(); if (!srv->srv_root) { rpc_SetErr(sched_GetErrno(), "%s", sched_GetError()); + pthread_mutex_destroy(&srv->srv_funcs.mtx); io_free(srv); return NULL; } @@ -753,6 +756,7 @@ rpc_srv_initServer(u_int regProgID, u_char regProcID, if (!srv->srv_clients) { rpc_SetErr(io_GetErrno(), "%s", io_GetError()); schedEnd(&srv->srv_root); + pthread_mutex_destroy(&srv->srv_funcs.mtx); io_free(srv); return NULL; } @@ -763,6 +767,7 @@ rpc_srv_initServer(u_int regProgID, u_char regProcID, LOGERR; io_arrayDestroy(&srv->srv_clients); schedEnd(&srv->srv_root); + pthread_mutex_destroy(&srv->srv_funcs.mtx); io_free(srv); return NULL; } @@ -792,6 +797,7 @@ err: /* error condition */ close(srv->srv_server.cli_sock); io_arrayDestroy(&srv->srv_clients); schedEnd(&srv->srv_root); + pthread_mutex_destroy(&srv->srv_funcs.mtx); io_free(srv); return NULL; } @@ -815,6 +821,7 @@ rpc_srv_endServer(rpc_srv_t ** __restrict psrv) (*psrv)->srv_kill = 1; sleep(RPC_SCHED_POLLING); + pthread_mutex_destroy(&(*psrv)->srv_funcs.mtx); io_free(*psrv); *psrv = NULL; } @@ -830,7 +837,7 @@ rpc_srv_loopServer(rpc_srv_t * __restrict srv) { rpc_cli_t *c; register int i; - rpc_func_t *f, *tmp; + rpc_func_t *f; struct timespec ts = { RPC_SCHED_POLLING, 0 }; if (!srv) { @@ -872,12 +879,15 @@ rpc_srv_loopServer(rpc_srv_t * __restrict srv) close(srv->srv_server.cli_sock); /* detach exported calls */ - TAILQ_FOREACH_SAFE(f, &srv->srv_funcs, func_node, tmp) { - TAILQ_REMOVE(&srv->srv_funcs, f, func_node); + RPC_FUNCS_LOCK(&srv->srv_funcs); + while ((f = SLIST_FIRST(&srv->srv_funcs))) { + SLIST_REMOVE_HEAD(&srv->srv_funcs, func_next); AIT_FREE_VAL(&f->func_name); io_free(f); } + srv->srv_funcs.avlh_root = NULL; + RPC_FUNCS_UNLOCK(&srv->srv_funcs); schedEnd(&srv->srv_root); return 0;