3 * Manage locking system
4 * This include the mutex's and cv's.
6 * Copyright (c) 1996 T. J. Wilkinson & Associates, London, UK.
8 * See the file "license.terms" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * Written by Tim Wilkinson <tim@tjwassoc.demon.co.uk>, 1996.
21 #define WAITFOREVER -1
25 typedef struct _iMux {
26 struct _thread *holder;
28 struct _thread *muxWaiters;
32 struct _thread* cvWaiters;
36 #define MAX_MUTEXES 256
38 typedef struct _mutexHashEntry
40 java_objectheader *object;
42 struct _mutexHashEntry *next;
46 #define MUTEX_HASH_TRASH_BITS 3
47 #define MUTEX_HASH_SIGN_BITS 10
49 #define MUTEX_HASH_TABLE_SIZE 1024
50 #define MUTEX_OVERFLOW_TABLE_SIZE 1024
52 #define MAX_MUTEX_HASH_TABLE_SIZE 65536
56 #define MUTEX_USE_THRESHOLD 1024
59 extern long mutexHashMask;
60 extern int mutexHashTableSize;
61 extern mutexHashEntry *mutexHashTable;
63 extern mutexHashEntry *mutexOverflowTable;
64 extern int mutexOverflowTableSize;
65 extern mutexHashEntry *firstFreeOverflowEntry;
67 #define MUTEX_HASH_MASK ((MUTEX_HASH_TABLE_SIZE - 1) << 3)
70 #define MUTEX_HASH_VALUE(a) ((((long)(a)) & MUTEX_HASH_MASK) >> MUTEX_HASH_TRASH_BITS)
72 #define MUTEX_HASH_VALUE(a) (( (((long)(a)) ^ ((long)(a) >> MUTEX_HASH_SIGN_BITS)) & mutexHashMask) >> MUTEX_HASH_TRASH_BITS)
74 #define MUTEX_HASH_SUCCESSOR(h) (((h) + 7) & (mutexHashTableSize - 1))
76 typedef struct _conditionHashEntry
78 java_objectheader *object;
82 #define CONDITION_HASH_TABLE_SIZE 1024
84 #define CONDITION_HASH_VALUE(a) ((((long)(a)) & conditionHashMask) >> 3)
85 #define CONDITION_HASH_SUCCESSOR(h) (((h) + 7) & (conditionHashTableSize - 1))
90 java_objectheader *object;
95 extern void initLocks (void);
97 mutexHashEntry* conditionLockedMutexForObject (java_objectheader *object);
99 void reorderConditionHashTable (int begin);
100 iCv* conditionForObject (java_objectheader *object);
101 iCv* addConditionForObject (java_objectheader *object);
102 void removeConditionForObject (java_objectheader *object);
105 * use these functions only outside critical sections (intsEnable/intsRestore).
108 void signal_cond_for_object (java_objectheader *obj);
109 void broadcast_cond_for_object (java_objectheader *obj);
110 void wait_cond_for_object (java_objectheader *obj, s8 time);
111 void lock_mutex_for_object (java_objectheader *obj);
112 void unlock_mutex_for_object (java_objectheader *obj);
114 void lock_mutex (iMux*);
115 void unlock_mutex (iMux*);
116 void wait_cond (iMux*, iCv*, s8);
117 void signal_cond (iCv*);
118 void broadcast_cond (iCv*);
121 * use these internal functions only in critical sections. blockInts must be exactly
124 void internal_lock_mutex (iMux*);
125 void internal_unlock_mutex (iMux*);
126 void internal_wait_cond (iMux*, iCv*, s8);
127 void internal_signal_cond (iCv*);
128 void internal_broadcast_cond (iCv*);
130 void internal_lock_mutex_for_object (java_objectheader *obj);
131 void internal_unlock_mutex_for_object (java_objectheader *obj);
132 void internal_broadcast_cond_for_object (java_objectheader *obj);
134 #endif /* USE_THREADS */
136 #endif /* __locks_h */