From: Adam Dickmeiss Date: Thu, 4 Feb 2010 14:38:57 +0000 (+0100) Subject: Add mutex for service (ref counting) X-Git-Tag: v1.4.0~147 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=e356b466f900722adf6c4f13588e2bed05555134;p=pazpar2-moved-to-github.git Add mutex for service (ref counting) --- diff --git a/configure.ac b/configure.ac index 6817819..efdd100 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ AC_LANG(C) AC_C_INLINE -YAZ_INIT([static icu threads],[4.0.1]) +YAZ_INIT([static icu server],[4.0.1]) if test -z "$YAZLIB"; then AC_MSG_ERROR([YAZ development libraries missing]) fi diff --git a/src/Makefile.am b/src/Makefile.am index 74305a7..602d245 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,7 @@ libpazpar2_a_SOURCES = pazpar2_config.c pazpar2_config.h eventl.c eventl.h \ client.c client.h connection.c connection.h host.h parameters.h \ marcmap.c marcmap.h marchash.c marchash.h \ jenkins_hash.c jenkins_hash.h normalize_record.c normalize_record.h \ - normalize_cache.c normalize_cache.h + normalize_cache.c normalize_cache.h incref.c incref.h pazpar2_SOURCES = pazpar2.c pazpar2_LDADD = libpazpar2.a $(YAZLIB) diff --git a/src/http_command.c b/src/http_command.c index e3a290f..3631740 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -283,7 +283,6 @@ static void cmd_init(struct http_channel *c) error(rs, PAZPAR2_NO_SERVICE, service_name ? service_name : "unnamed"); return; } - service_incref(service); } s = http_session_create(service); diff --git a/src/incref.c b/src/incref.c new file mode 100644 index 0000000..2996fe2 --- /dev/null +++ b/src/incref.c @@ -0,0 +1,54 @@ +/* This file is part of Pazpar2. + Copyright (C) 2006-2010 Index Data + +Pazpar2 is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** \file incref.c + \brief MUTEX protect ref counts +*/ + +#if HAVE_CONFIG_H +#include +#endif + +#include "incref.h" + +void pazpar2_incref(int *ref, YAZ_MUTEX mutex) +{ + yaz_mutex_enter(mutex); + (*ref)++; + yaz_mutex_leave(mutex); +} + + +int pazpar2_decref(int *ref, YAZ_MUTEX mutex) +{ + int value ; + yaz_mutex_enter(mutex); + value = --(*ref); + yaz_mutex_leave(mutex); + return value; +} +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/incref.h b/src/incref.h new file mode 100644 index 0000000..144eac1 --- /dev/null +++ b/src/incref.h @@ -0,0 +1,42 @@ +/* This file is part of Pazpar2. + Copyright (C) 2006-2010 Index Data + +Pazpar2 is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** \file incref.h + \brief MUTEX protect ref counts +*/ + +#ifndef PAZPAR2_INCREF_H +#define PAZPAR2_INCREF_H + +#include + +void pazpar2_incref(int *ref, YAZ_MUTEX mutex); +int pazpar2_decref(int *ref, YAZ_MUTEX mutex); + +#endif + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index fb62e99..bcb415a 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if HAVE_UNISTD_H #include #endif +#include "incref.h" #include "pazpar2_config.h" #include "settings.h" #include "eventl.h" @@ -111,6 +112,7 @@ static struct conf_service *service_init(struct conf_server *server, NMEM nmem = nmem_create(); service = nmem_malloc(nmem, sizeof(struct conf_service)); + service->mutex = 0; service->ref_count = 1; service->nmem = nmem; service->next = 0; @@ -238,13 +240,14 @@ void service_destroy(struct conf_service *service) { if (service) { - assert(service->ref_count > 0); - service->ref_count--; - if (service->ref_count == 0) + yaz_log(YLOG_LOG, "service_destroy. p=%p cnt=%d", service, + service->ref_count); + if (!pazpar2_decref(&service->ref_count, service->mutex)) { pp2_charset_destroy(service->relevance_pct); pp2_charset_destroy(service->sort_pct); pp2_charset_destroy(service->mergekey_pct); + yaz_mutex_destroy(&service->mutex); nmem_destroy(service->nmem); } } @@ -252,7 +255,9 @@ void service_destroy(struct conf_service *service) void service_incref(struct conf_service *service) { - service->ref_count++; + yaz_log(YLOG_LOG, "service_incref. p=%p cnt=%d", service, + service->ref_count); + pazpar2_incref(&service->ref_count, service->mutex); } static int parse_metadata(struct conf_service *service, xmlNode *n, @@ -690,6 +695,8 @@ struct conf_service *service_create(struct conf_server *server, { inherit_server_settings(service); resolve_databases(service); + assert(service->mutex == 0); + yaz_mutex_create(&service->mutex); } return service; } @@ -881,10 +888,12 @@ struct conf_service *locate_service(struct conf_server *server, struct conf_service *s = server->service; for (; s; s = s->next) if (s->id && service_id && 0 == strcmp(s->id, service_id)) - return s; + break; else if (!s->id && !service_id) - return s; - return 0; + break; + if (s) + service_incref(s); + return s; } @@ -909,7 +918,7 @@ static int parse_config(struct conf_config *config, xmlNode *root) xmlChar *number = xmlGetProp(n, (xmlChar *) "number"); if (number) { - config->no_threads = atoi(number); + config->no_threads = atoi((const char *) number); xmlFree(number); } } @@ -1034,7 +1043,11 @@ void config_start_databases(struct conf_config *conf) { struct conf_service *s = ser->service; for (;s ; s = s->next) + { resolve_databases(s); + assert(s->mutex == 0); + yaz_mutex_create(&s->mutex); + } } } diff --git a/src/pazpar2_config.h b/src/pazpar2_config.h index 9b57167..41d9431 100644 --- a/src/pazpar2_config.h +++ b/src/pazpar2_config.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "normalize_cache.h" #include +#include #include "charsets.h" enum conf_metadata_type { @@ -97,6 +98,7 @@ struct conf_server; // however, only a single service is possible. struct conf_service { + YAZ_MUTEX mutex; int num_metadata; struct conf_metadata *metadata; int num_sortkeys; diff --git a/src/settings.h b/src/settings.h index b7bf53d..15fbf3c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -68,6 +68,7 @@ void settings_read_node_x(xmlNode *n, void expand_settings_array(struct setting ***set_ar, int *num, int offset, NMEM nmem); +void pazpar2_chan_man_start(int no_threads); #endif