📄 lock.h
字号:
/* BLURB lgpl Coda File System Release 5 Copyright (c) 1987-1999 Carnegie Mellon University Additional copyrights listed belowThis code is distributed "AS IS" without warranty of any kind underthe terms of the GNU Library General Public Licence Version 2, asshown in the file LICENSE. The technical and financial contributors toCoda are listed in the file CREDITS. Additional copyrights#*//* IBM COPYRIGHT NOTICE Copyright (C) 1986 International Business Machines Corporation All Rights ReservedThis file contains some code identical to or derived from the 1986version of the Andrew File System ("AFS"), which is owned by the IBMCorporation. This code is provided "AS IS" and IBM does not warrantthat it is free of infringement of any intellectual rights of anythird party. IBM disclaims liability of any kind for any damageswhatsoever resulting directly or indirectly from use of this softwareor of any derivative work. Carnegie Mellon University has obtainedpermission to modify, distribute and sublicense this code, which isbased on Version 2 of AFS and does not contain the features andenhancements that are part of Version 3 of AFS. Version 3 of AFS iscommercially available and supported by Transarc Corporation,Pittsburgh, PA.*/#ifndef _LWP_LOCK_H_#define _LWP_LOCK_H_#ifdef __cplusplusextern "C" {#endif#include <lwp/lwp.h>#define READ_LOCK 1#define WRITE_LOCK 2#define SHARED_LOCK 4/* When compiling for pthreads, always compile with -D_REENTRANT (on glibc * systems) or -D_THREAD_SAFE and -pthread/-kthread (on FreeBSD) */#if !defined(_REENTRANT) && !defined(_THREAD_SAFE)/* all locks wait on excl_locked except for READ_LOCK, which waits on * readers_reading */struct Lock { unsigned char wait_states; /* type of lockers waiting */ unsigned char excl_locked; /* anyone have boosted, shared or write lock? */ unsigned char readers_reading;/* # readers actually with read locks */ unsigned char num_waiting; /* probably need this soon */ PROCESS excl_locker;};/* next defines wait_states for which we wait on excl_locked */#define EXCL_LOCKS (WRITE_LOCK|SHARED_LOCK)void Lock_Obtain (struct Lock*, int);void Lock_ReleaseR (struct Lock *);void Lock_ReleaseW (struct Lock *);#else /* _REENTRANT || _THREAD_SAFE */#include <pthread.h>struct Lock { char initialized; char readers; PROCESS excl; pthread_mutex_t _access; pthread_cond_t wakeup;};#endif /* _REENTRANT || _THREAD_SAFE */typedef struct Lock Lock;/* extern definitions for lock manager routines */void ObtainReadLock(struct Lock *lock);void ObtainWriteLock(struct Lock *lock);void ObtainSharedLock(struct Lock *lock);void ReleaseReadLock(struct Lock *lock);void ReleaseWriteLock(struct Lock *lock);void ReleaseSharedLock(struct Lock *lock);int CheckLock(struct Lock *lock);int WriteLocked(struct Lock *lock);void Lock_Init (struct Lock *lock);#ifdef __cplusplus}#endif#endif /* _LWP_LOCK_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -