2 Unix SMB/CIFS implementation.
3 Samba mutex/lock functions
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) James J Myers 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 static smb_mutex_t mutex_list[MUTEX_MAX];
25 /* the registered mutex handlers */
31 int mutex_lock_by_id(enum mutex_id id, const char *name)
33 return mutex_lock(&mutex_list[id], name);
36 int mutex_unlock_by_id(enum mutex_id id, const char *name)
38 return mutex_unlock(&mutex_list[id], name);
41 int mutex_init(smb_mutex_t *mutex, const char *name)
43 if (mutex_handlers.ops.mutex_init) {
44 return mutex_handlers.ops.mutex_init(mutex, name);
49 int mutex_destroy(smb_mutex_t *mutex, const char *name)
51 if (mutex_handlers.ops.mutex_destroy) {
52 return mutex_handlers.ops.mutex_destroy(mutex, name);
57 int mutex_lock(smb_mutex_t *mutex, const char *name)
59 if (mutex_handlers.ops.mutex_lock) {
60 return mutex_handlers.ops.mutex_lock(mutex, name);
65 int mutex_unlock(smb_mutex_t *mutex, const char *name)
67 if (mutex_handlers.ops.mutex_unlock) {
68 return mutex_handlers.ops.mutex_unlock(mutex, name);
73 /* read/write lock routines */
75 int rwlock_init(smb_rwlock_t *rwlock, const char *name)
77 if (mutex_handlers.ops.rwlock_init) {
78 return mutex_handlers.ops.rwlock_init(rwlock, name);
83 int rwlock_destroy(smb_rwlock_t *rwlock, const char *name)
85 if (mutex_handlers.ops.rwlock_destroy) {
86 return mutex_handlers.ops.rwlock_destroy(rwlock, name);
91 int rwlock_lock_write(smb_rwlock_t *rwlock, const char *name)
93 if (mutex_handlers.ops.rwlock_lock_write) {
94 return mutex_handlers.ops.rwlock_lock_write(rwlock, name);
99 int rwlock_lock_read(smb_rwlock_t *rwlock, const char *name)
101 if (mutex_handlers.ops.rwlock_lock_read) {
102 return mutex_handlers.ops.rwlock_lock_read(rwlock, name);
107 int rwlock_unlock(smb_rwlock_t *rwlock, const char *name)
109 if (mutex_handlers.ops.rwlock_unlock) {
110 return mutex_handlers.ops.rwlock_unlock(rwlock, name);
117 register a set of mutex/rwlock handlers.
118 Should only be called once in the execution of smbd.
120 BOOL register_mutex_handlers(const char *name, struct mutex_ops *ops)
122 if (mutex_handlers.name != NULL) {
123 /* it's already registered! */
124 DEBUG(2,("mutex handler '%s' already registered - failed '%s'\n",
125 mutex_handlers.name, name));
129 mutex_handlers.name = name;
130 mutex_handlers.ops = *ops;
132 if (mutex_handlers.ops.mutex_init) {
134 for (id=0; id < MUTEX_MAX; id++) {
135 mutex_handlers.ops.mutex_init(&mutex_list[id], "mutex_list");
139 DEBUG(2,("mutex handler '%s' registered\n", name));