1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2010 Index Data
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <yaz/yaz-util.h>
23 #include <yaz/mutex.h>
30 #include "normalize_cache.h"
32 #include "pazpar2_config.h"
36 struct cached_item *next;
37 normalize_record_t nt;
40 struct normalize_cache_s {
41 struct cached_item *items;
46 normalize_cache_t normalize_cache_create(void)
48 NMEM nmem = nmem_create();
49 normalize_cache_t nc = nmem_malloc(nmem, sizeof(*nc));
53 yaz_mutex_create(&nc->mutex);
54 yaz_mutex_set_name(nc->mutex, "normalize_cache");
58 normalize_record_t normalize_cache_get(normalize_cache_t nc,
59 struct conf_service *service,
62 normalize_record_t nt;
63 struct cached_item *ci;
65 yaz_mutex_enter(nc->mutex);
66 for (ci = nc->items; ci; ci = ci->next)
67 if (!strcmp(spec, ci->spec))
73 nt = normalize_record_create(service, spec);
76 ci = nmem_malloc(nc->nmem, sizeof(*ci));
80 ci->spec = nmem_strdup(nc->nmem, spec);
83 yaz_mutex_leave(nc->mutex);
87 void normalize_cache_destroy(normalize_cache_t nc)
91 struct cached_item *ci = nc->items;
92 for (; ci; ci = ci->next)
93 normalize_record_destroy(ci->nt);
94 yaz_mutex_destroy(&nc->mutex);
95 nmem_destroy(nc->nmem);
102 * c-file-style: "Stroustrup"
103 * indent-tabs-mode: nil
105 * vim: shiftwidth=4 tabstop=8 expandtab