| 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 3 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, see <http://www.gnu.org/licenses/>. | 
|---|
| 21 | */ | 
|---|
| 22 |  | 
|---|
| 23 | /** | 
|---|
| 24 | * @file | 
|---|
| 25 | * @brief Mutex operations | 
|---|
| 26 | */ | 
|---|
| 27 |  | 
|---|
| 28 | struct mutex_ops; | 
|---|
| 29 |  | 
|---|
| 30 | /* To add a new read/write lock, add it to enum rwlock_id | 
|---|
| 31 | */ | 
|---|
| 32 | enum rwlock_id { RWLOCK_SMBD,           /* global smbd lock */ | 
|---|
| 33 |  | 
|---|
| 34 | RWLOCK_MAX /* this MUST be kept last */ | 
|---|
| 35 | }; | 
|---|
| 36 |  | 
|---|
| 37 | #define MUTEX_LOCK_BY_ID(mutex_index) smb_mutex_lock_by_id(mutex_index, #mutex_index) | 
|---|
| 38 | #define MUTEX_UNLOCK_BY_ID(mutex_index) smb_mutex_unlock_by_id(mutex_index, #mutex_index) | 
|---|
| 39 | #define MUTEX_INIT(mutex, name) smb_mutex_init(mutex, #name) | 
|---|
| 40 | #define MUTEX_DESTROY(mutex, name) smb_mutex_destroy(mutex, #name) | 
|---|
| 41 | #define MUTEX_LOCK(mutex, name) smb_mutex_lock(mutex, #name) | 
|---|
| 42 | #define MUTEX_UNLOCK(mutex, name) smb_mutex_unlock(mutex, #name) | 
|---|
| 43 |  | 
|---|
| 44 | #define RWLOCK_INIT(rwlock, name) smb_rwlock_init(rwlock, #name) | 
|---|
| 45 | #define RWLOCK_DESTROY(rwlock, name) smb_rwlock_destroy(rwlock, #name) | 
|---|
| 46 | #define RWLOCK_LOCK_WRITE(rwlock, name) smb_rwlock_lock_write(rwlock, #name) | 
|---|
| 47 | #define RWLOCK_LOCK_READ(rwlock, name) smb_rwlock_lock_read(rwlock, #name) | 
|---|
| 48 | #define RWLOCK_UNLOCK(rwlock, name) smb_rwlock_unlock(rwlock, #name) | 
|---|
| 49 |  | 
|---|
| 50 |  | 
|---|
| 51 |  | 
|---|
| 52 | /* this null typedef ensures we get the types right and avoids the | 
|---|
| 53 | pitfalls of void* */ | 
|---|
| 54 | typedef struct smb_mutex { | 
|---|
| 55 | void *mutex; | 
|---|
| 56 | } smb_mutex_t; | 
|---|
| 57 | typedef struct { | 
|---|
| 58 | void *rwlock; | 
|---|
| 59 | } smb_rwlock_t; | 
|---|
| 60 |  | 
|---|
| 61 | /* the mutex model operations structure - contains function pointers to | 
|---|
| 62 | the model-specific implementations of each operation */ | 
|---|
| 63 | struct mutex_ops { | 
|---|
| 64 | int (*mutex_init)(smb_mutex_t *mutex, const char *name); | 
|---|
| 65 | int (*mutex_lock)(smb_mutex_t *mutex, const char *name); | 
|---|
| 66 | int (*mutex_unlock)(smb_mutex_t *mutex, const char *name); | 
|---|
| 67 | int (*mutex_destroy)(smb_mutex_t *mutex, const char *name); | 
|---|
| 68 | int (*rwlock_init)(smb_rwlock_t *rwlock, const char *name); | 
|---|
| 69 | int (*rwlock_lock_write)(smb_rwlock_t *rwlock, const char *name); | 
|---|
| 70 | int (*rwlock_lock_read)(smb_rwlock_t *rwlock, const char *name); | 
|---|
| 71 | int (*rwlock_unlock)(smb_rwlock_t *rwlock, const char *name); | 
|---|
| 72 | int (*rwlock_destroy)(smb_rwlock_t *rwlock, const char *name); | 
|---|
| 73 | }; | 
|---|
| 74 |  | 
|---|
| 75 | #endif /* endif _MUTEX_H_ */ | 
|---|