1 /* BLURB lgpl 2 3 Coda File System 4 Release 5 5 6 Copyright (c) 1987-1999 Carnegie Mellon University 7 Additional copyrights listed below 8 9 This code is distributed "AS IS" without warranty of any kind under 10 the terms of the GNU Library General Public Licence Version 2, as 11 shown in the file LICENSE. The technical and financial contributors to 12 Coda are listed in the file CREDITS. 13 14 Additional copyrights 15 16 #*/ 17 18 /* 19 IBM COPYRIGHT NOTICE 20 21 Copyright (C) 1986 22 International Business Machines Corporation 23 All Rights Reserved 24 25 This file contains some code identical to or derived from the 1986 26 version of the Andrew File System ("AFS"), which is owned by the IBM 27 Corporation. This code is provided "AS IS" and IBM does not warrant 28 that it is free of infringement of any intellectual rights of any 29 third party. IBM disclaims liability of any kind for any damages 30 whatsoever resulting directly or indirectly from use of this software 31 or of any derivative work. Carnegie Mellon University has obtained 32 permission to modify, distribute and sublicense this code, which is 33 based on Version 2 of AFS and does not contain the features and 34 enhancements that are part of Version 3 of AFS. Version 3 of AFS is 35 commercially available and supported by Transarc Corporation, 36 Pittsburgh, PA. 37 38 */ 39 40 #ifndef _LWP_LOCK_H_ 41 #define _LWP_LOCK_H_ 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 #include <lwp/lwp.h> 48 49 #define READ_LOCK 1 50 #define WRITE_LOCK 2 51 #define SHARED_LOCK 4 52 53 /* When compiling for pthreads, always compile with -D_REENTRANT (on glibc 54 * systems) or -D_THREAD_SAFE and -pthread/-kthread (on FreeBSD) */ 55 #if !defined(_REENTRANT) && !defined(_THREAD_SAFE) 56 57 /* all locks wait on excl_locked except for READ_LOCK, which waits on 58 * readers_reading */ 59 struct Lock { 60 unsigned char wait_states; /* type of lockers waiting */ 61 unsigned char excl_locked; /* anyone have boosted, shared or write lock? */ 62 unsigned char readers_reading;/* # readers actually with read locks */ 63 unsigned char num_waiting; /* probably need this soon */ 64 PROCESS excl_locker; 65 }; 66 67 /* next defines wait_states for which we wait on excl_locked */ 68 #define EXCL_LOCKS (WRITE_LOCK|SHARED_LOCK) 69 70 void Lock_Obtain (struct Lock*, int); 71 void Lock_ReleaseR (struct Lock *); 72 void Lock_ReleaseW (struct Lock *); 73 74 #else /* _REENTRANT || _THREAD_SAFE */ 75 #include <pthread.h> 76 77 struct Lock { 78 char initialized; 79 char readers; 80 PROCESS excl; 81 pthread_mutex_t _access; 82 pthread_cond_t wakeup; 83 }; 84 #endif /* _REENTRANT || _THREAD_SAFE */ 85 86 typedef struct Lock Lock; 87 88 /* extern definitions for lock manager routines */ 89 void ObtainReadLock(struct Lock *lock); 90 void ObtainWriteLock(struct Lock *lock); 91 void ObtainSharedLock(struct Lock *lock); 92 void ReleaseReadLock(struct Lock *lock); 93 void ReleaseWriteLock(struct Lock *lock); 94 void ReleaseSharedLock(struct Lock *lock); 95 int CheckLock(struct Lock *lock); 96 int WriteLocked(struct Lock *lock); 97 void Lock_Init (struct Lock *lock); 98 99 #ifdef __cplusplus 100 } 101 #endif 102 103 #endif /* _LWP_LOCK_H_ */ 104 105