2 * Copyright (C) 1998, 1989 Transarc Corporation - All rights reserved
4 * (C) COPYRIGHT IBM CORPORATION 1987, 1988
5 * LICENSED MATERIALS - PROPERTY OF IBM
9 /* Copyright (C) 1994 Cazamar Systems, Inc. */
11 #ifndef _OSIBASEL_H_ENV_
12 #define _OSIBASEL_H_ENV_ 1
14 /* flags for osi_mutex_t and osi_rwlock_t flags fields. Some bits
15 * are used only in one structure or another.
17 #define OSI_LOCKFLAG_EXCL 1 /* exclusive locked (rwlock only) */
19 /* a mutex (pure exclusive lock). This structure has two forms. In the
20 * base type (type == 0), the d field is interpreted as an atomic counter,
21 * and all the other fields are used. In the other types, type specifies
22 * which operations to use (via the global osi_lockOps), and d.privateDatap
23 * points to the real data used by the mutex.
25 * For the base type, flags tells us if the lock is held, and if anyone else
26 * is waiting for the lock. The field d.atomicCount is used to implement a spin
27 * lock using an atomic increment operation.
29 typedef struct osi_mutex {
30 char type; /* for all types; type 0 uses atomic count */
31 char flags; /* flags for base type */
32 unsigned short atomicIndex; /* index of lock for low-level sync */
33 unsigned short waiters; /* waiters */
36 void *privateDatap; /* data pointer for non-zero types */
37 osi_turnstile_t turn; /* turnstile */
41 /* a read/write lock. This structure has two forms. In the
42 * base type (type == 0), the d field is interpreted as an atomic counter,
43 * and all the other fields are used. In the other types, type specifies
44 * which operations to use (via the global osi_lockOps), and d.privateDatap
45 * points to the real data used by the mutex.
47 * For the base type, flags tells us if the lock is held, and if anyone else
48 * is waiting for the lock. The field d.atomicCount is used to implement a spin
49 * lock using an atomic increment operation.
51 * This type of lock has N readers or one writer.
53 typedef struct osi_rwlock {
54 char type; /* for all types; type 0 uses atomic count */
55 char flags; /* flags for base type */
56 unsigned short atomicIndex; /* index into hash table for low-level sync */
57 unsigned short waiters; /* waiters */
58 unsigned short readers; /* readers */
60 void *privateDatap; /* data pointer for non-zero types */
61 osi_turnstile_t turn; /* turnstile */
65 extern void lock_ObtainRead (struct osi_rwlock *);
67 extern void lock_ObtainWrite (struct osi_rwlock *);
69 extern void lock_ReleaseRead (struct osi_rwlock *);
71 extern void lock_ReleaseWrite (struct osi_rwlock *);
73 extern void lock_ObtainMutex (struct osi_mutex *);
75 extern void lock_ReleaseMutex (struct osi_mutex *);
77 extern int lock_TryRead (struct osi_rwlock *);
79 extern int lock_TryWrite (struct osi_rwlock *);
81 extern int lock_TryMutex (struct osi_mutex *);
83 extern void osi_SleepR (long, struct osi_rwlock *);
85 extern void osi_SleepW (long, struct osi_rwlock *);
87 extern void osi_SleepM (long, struct osi_mutex *);
89 extern void osi_Sleep (long);
91 extern void osi_Wakeup (long);
93 extern void lock_FinalizeRWLock(struct osi_rwlock *);
95 extern void lock_FinalizeMutex(struct osi_mutex *);
97 extern CRITICAL_SECTION osi_baseAtomicCS[];
99 /* and define the functions that create basic locks and mutexes */
101 extern void lock_InitializeRWLock(struct osi_rwlock *, char *);
103 extern void lock_InitializeMutex(struct osi_mutex *, char *);
105 extern void osi_Init (void);
107 extern void lock_ConvertWToR(struct osi_rwlock *);
109 /* and stat functions */
111 extern int lock_GetRWLockState(struct osi_rwlock *);
113 extern int lock_GetMutexState(struct osi_mutex *);
117 extern void osi_BaseInit(void);
119 /* and friendly macros */
121 #define lock_AssertRead(x) osi_assert(lock_GetRWLockState(x) & OSI_RWLOCK_READHELD)
123 #define lock_AssertWrite(x) osi_assert(lock_GetRWLockState(x) & OSI_RWLOCK_WRITEHELD)
125 #define lock_AssertAny(x) osi_assert(lock_GetRWLockState(x) != 0)
127 #define lock_AssertMutex(x) osi_assert(lock_GetMutexState(x) & OSI_MUTEX_HELD)
129 #endif /*_OSIBASEL_H_ENV_ */