r13248: Revert revision 13071. It turns out that sys/param.h can be implicitly
[kai/samba.git] / source4 / include / mutex.h
1 #ifndef _MUTEX_H_
2 #define _MUTEX_H_
3 /* 
4    Unix SMB/CIFS implementation.
5    Samba mutex functions
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) James J Myers 2003
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 /* To add a new read/write lock, add it to enum rwlock_id
25  */
26 enum rwlock_id { RWLOCK_SMBD,           /* global smbd lock */
27
28                 RWLOCK_MAX /* this MUST be kept last */
29 };
30
31 #define MUTEX_LOCK_BY_ID(mutex_index) smb_mutex_lock_by_id(mutex_index, #mutex_index)
32 #define MUTEX_UNLOCK_BY_ID(mutex_index) smb_mutex_unlock_by_id(mutex_index, #mutex_index)
33 #define MUTEX_INIT(mutex, name) smb_mutex_init(mutex, #name)
34 #define MUTEX_DESTROY(mutex, name) smb_mutex_destroy(mutex, #name)
35 #define MUTEX_LOCK(mutex, name) smb_mutex_lock(mutex, #name)
36 #define MUTEX_UNLOCK(mutex, name) smb_mutex_unlock(mutex, #name)
37
38 #define RWLOCK_INIT(rwlock, name) smb_rwlock_init(rwlock, #name)
39 #define RWLOCK_DESTROY(rwlock, name) smb_rwlock_destroy(rwlock, #name)
40 #define RWLOCK_LOCK_WRITE(rwlock, name) smb_rwlock_lock_write(rwlock, #name)
41 #define RWLOCK_LOCK_READ(rwlock, name) smb_rwlock_lock_read(rwlock, #name)
42 #define RWLOCK_UNLOCK(rwlock, name) smb_rwlock_unlock(rwlock, #name)
43
44
45
46 /* this null typedef ensures we get the types right and avoids the
47    pitfalls of void* */
48 typedef struct smb_mutex {
49         void *mutex;
50 } smb_mutex_t;
51 typedef struct {
52         void *rwlock;
53 } smb_rwlock_t;
54
55 /* the mutex model operations structure - contains function pointers to 
56    the model-specific implementations of each operation */
57 struct mutex_ops {
58         int (*mutex_init)(smb_mutex_t *mutex, const char *name);
59         int (*mutex_lock)(smb_mutex_t *mutex, const char *name);
60         int (*mutex_unlock)(smb_mutex_t *mutex, const char *name);
61         int (*mutex_destroy)(smb_mutex_t *mutex, const char *name);
62         int (*rwlock_init)(smb_rwlock_t *rwlock, const char *name);
63         int (*rwlock_lock_write)(smb_rwlock_t *rwlock, const char *name);
64         int (*rwlock_lock_read)(smb_rwlock_t *rwlock, const char *name);
65         int (*rwlock_unlock)(smb_rwlock_t *rwlock, const char *name);
66         int (*rwlock_destroy)(smb_rwlock_t *rwlock, const char *name);
67 };
68
69 #endif /* endif _MUTEX_H_ */