Coda Distributed File System
lock.h
Go to the documentation of this file.
1/* BLURB lgpl
2
3 Coda File System
4 Release 6
5
6 Copyright (c) 1987-2018 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU Library General Public Licence Version 2, as
11shown in the file LICENSE. The technical and financial contributors to
12Coda 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
25This file contains some code identical to or derived from the 1986
26version of the Andrew File System ("AFS"), which is owned by the IBM
27Corporation. This code is provided "AS IS" and IBM does not warrant
28that it is free of infringement of any intellectual rights of any
29third party. IBM disclaims liability of any kind for any damages
30whatsoever resulting directly or indirectly from use of this software
31or of any derivative work. Carnegie Mellon University has obtained
32permission to modify, distribute and sublicense this code, which is
33based on Version 2 of AFS and does not contain the features and
34enhancements that are part of Version 3 of AFS. Version 3 of AFS is
35commercially available and supported by Transarc Corporation,
36Pittsburgh, PA.
37
38*/
39
40#ifndef _LWP_LOCK_H_
41#define _LWP_LOCK_H_
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47#include <lwp/lwp.h>
48
53{
56 SHARED_LOCK = 4
57};
58
59/* When compiling for pthreads, always compile with -D_REENTRANT (on glibc
60 * systems) or -D_THREAD_SAFE and -pthread/-kthread (on FreeBSD) */
61#if !defined(_REENTRANT) && !defined(_THREAD_SAFE)
62
63/* all locks wait on excl_locked except for READ_LOCK, which waits on
64 * readers_reading */
68struct Lock {
69 unsigned char wait_states;
70 unsigned char excl_locked;
71 unsigned char readers_reading;
72 unsigned char num_waiting;
74};
75
76/* next defines wait_states for which we wait on excl_locked */
77#define EXCL_LOCKS (WRITE_LOCK | SHARED_LOCK)
78
85void Lock_Obtain(struct Lock *lock, int how);
86
92void Lock_ReleaseR(struct Lock *lock);
93
99void Lock_ReleaseW(struct Lock *lock);
100
101#else /* _REENTRANT || _THREAD_SAFE */
102#include <pthread.h>
103
104struct Lock {
105 char initialized;
106 char readers;
107 PROCESS excl;
108 pthread_mutex_t _access;
109 pthread_cond_t wakeup;
110};
111#endif /* _REENTRANT || _THREAD_SAFE */
112
113typedef struct Lock Lock;
114
115/* extern definitions for lock manager routines */
121void ObtainReadLock(struct Lock *lock);
122
128void ObtainWriteLock(struct Lock *lock);
129
135void ObtainSharedLock(struct Lock *lock);
136
142void ReleaseReadLock(struct Lock *lock);
143
149void ReleaseWriteLock(struct Lock *lock);
150
156void ReleaseSharedLock(struct Lock *lock);
157
167int CheckLock(struct Lock *lock);
168
177int WriteLocked(struct Lock *lock);
178
184void Lock_Init(struct Lock *lock);
185
194void ObtainDualLock(struct Lock *lock_1, enum lock_how how_1,
195 struct Lock *lock_2, enum lock_how how_2);
196
205void ReleaseDualLock(struct Lock *lock_1, enum lock_how how_1,
206 struct Lock *lock_2, enum lock_how how_2);
207
208#ifdef __cplusplus
209}
210#endif
211
212#endif /* _LWP_LOCK_H_ */
void ObtainDualLock(struct Lock *lock_1, enum lock_how how_1, struct Lock *lock_2, enum lock_how how_2)
Definition: lock.c:114
void ReleaseWriteLock(struct Lock *lock)
Definition: lock_pt.c:135
int WriteLocked(struct Lock *lock)
Definition: lock_pt.c:163
lock_how
Definition: lock.h:53
@ SHARED_LOCK
Definition: lock.h:56
@ READ_LOCK
Definition: lock.h:54
@ WRITE_LOCK
Definition: lock.h:55
void Lock_ReleaseR(struct Lock *lock)
Definition: lock.c:191
void ReleaseReadLock(struct Lock *lock)
Definition: lock_pt.c:130
void Lock_Init(struct Lock *lock)
Definition: lock_pt.c:44
void ReleaseDualLock(struct Lock *lock_1, enum lock_how how_1, struct Lock *lock_2, enum lock_how how_2)
Definition: lock.c:158
void Lock_Obtain(struct Lock *lock, int how)
Definition: lock.c:58
int CheckLock(struct Lock *lock)
Definition: lock_pt.c:149
void ObtainReadLock(struct Lock *lock)
Definition: lock_pt.c:115
void Lock_ReleaseW(struct Lock *lock)
Definition: lock.c:210
void ObtainSharedLock(struct Lock *lock)
Definition: lock_pt.c:125
void ObtainWriteLock(struct Lock *lock)
Definition: lock_pt.c:120
void ReleaseSharedLock(struct Lock *lock)
Definition: lock_pt.c:140
Definition: lock.h:68
unsigned char num_waiting
Definition: lock.h:72
unsigned char readers_reading
Definition: lock.h:71
PROCESS excl_locker
Definition: lock.h:73
unsigned char wait_states
Definition: lock.h:69
unsigned char excl_locked
Definition: lock.h:70
Definition: lwp.private_pt.h:33