2 * This file handles locking and seaching resources
4 * Kern Sibbald, January MM
5 * Split from parse_conf.c April MMV
11 Copyright (C) 2000-2005 Kern Sibbald
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of
16 the License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public
24 License along with this program; if not, write to the Free
25 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33 extern int debug_level;
35 /* Each daemon has a slightly different set of
36 * resources, so it will define the following
41 extern RES_TABLE resources[];
42 extern RES **res_head;
45 // work around visual studio name manling preventing external linkage since res_all
46 // is declared as a different type when instantiated.
47 extern "C" CURES res_all;
48 extern "C" int res_all_size;
51 extern int res_all_size;
55 brwlock_t res_lock; /* resource lock */
56 static int res_locked = 0; /* set when resource chains locked -- for debug */
60 /* #define TRACE_RES */
62 void b_LockRes(const char *file, int line)
66 Pmsg4(000, "LockRes locked=%d w_active=%d at %s:%d\n",
67 res_locked, res_lock.w_active, file, line);
69 Pmsg2(000, "LockRes writerid=%d myid=%d\n", res_lock.writer_id,
73 if ((errstat=rwl_writelock(&res_lock)) != 0) {
74 Emsg3(M_ABORT, 0, "rwl_writelock failure at %s:%d: ERR=%s\n",
75 file, line, strerror(errstat));
80 void b_UnlockRes(const char *file, int line)
83 if ((errstat=rwl_writeunlock(&res_lock)) != 0) {
84 Emsg3(M_ABORT, 0, "rwl_writeunlock failure at %s:%d:. ERR=%s\n",
85 file, line, strerror(errstat));
89 Pmsg4(000, "UnLockRes locked=%d wactive=%d at %s:%d\n",
90 res_locked, res_lock.w_active, file, line);
95 * Return resource of type rcode that matches name
98 GetResWithName(int rcode, char *name)
101 int rindex = rcode - r_first;
104 res = res_head[rindex];
106 if (strcmp(res->name, name) == 0) {
117 * Return next resource of type rcode. On first
118 * call second arg (res) is NULL, on subsequent
119 * calls, it is called with previous value.
122 GetNextRes(int rcode, RES *res)
125 int rindex = rcode - r_first;
128 // if (!res_locked) {
129 // Emsg0(M_ABORT, 0, "Resource chain not locked.\n");
132 nres = res_head[rindex];