summaryrefslogtreecommitdiff
path: root/source4/include/mutex.h
blob: c3e146d41552a5fb04c6e642b728f4a255253a2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef _MUTEX_H_
#define _MUTEX_H_
/* 
   Unix SMB/CIFS implementation.
   Samba mutex functions
   Copyright (C) Andrew Tridgell 2003
   Copyright (C) James J Myers 2003
   
   This program 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 of the License, or
   (at your option) any later version.
   
   This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/* To add a new mutex, add it to enum mutex_id
 */
enum mutex_id { MUTEX_SMBD, 		/* global smbd lock */
		MUTEX_TALLOC, 		/* global talloc.c lock */
		MUTEX_DEBUG,		/* global debug.c lock */
		MUTEX_TANK,		/* vfs_tank lock */

		MUTEX_MAX /* this MUST be kept last */
};

/* To add a new read/write lock, add it to enum rwlock_id
 */
enum rwlock_id { RWLOCK_SMBD, 		/* global smbd lock */

		RWLOCK_MAX /* this MUST be kept last */
};

#define MUTEX_LOCK_BY_ID(mutex_index) mutex_lock_by_id(mutex_index, #mutex_index)
#define MUTEX_UNLOCK_BY_ID(mutex_index) mutex_unlock_by_id(mutex_index, #mutex_index)
#define MUTEX_INIT(mutex, name) mutex_init(mutex, #name)
#define MUTEX_DESTROY(mutex, name) mutex_destroy(mutex, #name)
#define MUTEX_LOCK(mutex, name) mutex_lock(mutex, #name)
#define MUTEX_UNLOCK(mutex, name) mutex_unlock(mutex, #name)

#define RWLOCK_INIT(rwlock, name) rwlock_init(rwlock, #name)
#define RWLOCK_DESTROY(rwlock, name) rwlock_destroy(rwlock, #name)
#define RWLOCK_LOCK_WRITE(rwlock, name) rwlock_lock_write(rwlock, #name)
#define RWLOCK_LOCK_READ(rwlock, name) rwlock_lock_read(rwlock, #name)
#define RWLOCK_UNLOCK(rwlock, name) rwlock_unlock(rwlock, #name)



/* this null typedef ensures we get the types right and avoids the
   pitfalls of void* */
typedef struct {
	void *mutex;
} mutex_t;
typedef struct {
	void *rwlock;
} rwlock_t;

/* the mutex model operations structure - contains function pointers to 
   the model-specific implementations of each operation */
struct mutex_ops {
	int (*mutex_init)(mutex_t *mutex, const char *name);
	int (*mutex_lock)(mutex_t *mutex, const char *name);
	int (*mutex_unlock)(mutex_t *mutex, const char *name);
	int (*mutex_destroy)(mutex_t *mutex, const char *name);
	int (*rwlock_init)(rwlock_t *rwlock, const char *name);
	int (*rwlock_lock_write)(rwlock_t *rwlock, const char *name);
	int (*rwlock_lock_read)(rwlock_t *rwlock, const char *name);
	int (*rwlock_unlock)(rwlock_t *rwlock, const char *name);
	int (*rwlock_destroy)(rwlock_t *rwlock, const char *name);
};

#endif /* ndef _MUTEX_H_ */