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.
19 #include "../global.h"
20 #include "sysdep/defines.h"
22 #define WAITFOREVER -1
24 #if defined(USE_INTERNAL_THREADS)
28 typedef struct _iMux {
29 struct _thread *holder;
31 struct _thread *muxWaiters;
35 struct _thread* cvWaiters;
39 #define MAX_MUTEXES 256
41 typedef struct _mutexHashEntry
43 java_objectheader *object;
45 struct _mutexHashEntry *next;
49 #define MUTEX_HASH_TRASH_BITS 3
50 #define MUTEX_HASH_SIGN_BITS 10
52 #define MUTEX_HASH_TABLE_SIZE 1024
53 #define MUTEX_OVERFLOW_TABLE_SIZE 1024
55 #define MAX_MUTEX_HASH_TABLE_SIZE 65536
59 #define MUTEX_USE_THRESHOLD 1024
62 extern long mutexHashMask;
63 extern int mutexHashTableSize;
64 extern mutexHashEntry *mutexHashTable;
66 extern mutexHashEntry *mutexOverflowTable;
67 extern int mutexOverflowTableSize;
68 extern mutexHashEntry *firstFreeOverflowEntry;
70 #define MUTEX_HASH_MASK ((MUTEX_HASH_TABLE_SIZE - 1) << 3)
73 #define MUTEX_HASH_VALUE(a) ((((long)(a)) & MUTEX_HASH_MASK) >> MUTEX_HASH_TRASH_BITS)
75 #define MUTEX_HASH_VALUE(a) (( (((long)(a)) ^ ((long)(a) >> MUTEX_HASH_SIGN_BITS)) & mutexHashMask) >> MUTEX_HASH_TRASH_BITS)
77 #define MUTEX_HASH_SUCCESSOR(h) (((h) + 7) & (mutexHashTableSize - 1))
79 typedef struct _conditionHashEntry
81 java_objectheader *object;
85 #define CONDITION_HASH_TABLE_SIZE 1024
87 #define CONDITION_HASH_VALUE(a) ((((long)(a)) & conditionHashMask) >> 3)
88 #define CONDITION_HASH_SUCCESSOR(h) (((h) + 7) & (conditionHashTableSize - 1))
93 java_objectheader *object;
98 extern void initLocks (void);
100 mutexHashEntry* conditionLockedMutexForObject (java_objectheader *object);
102 void reorderConditionHashTable (int begin);
103 iCv* conditionForObject (java_objectheader *object);
104 iCv* addConditionForObject (java_objectheader *object);
105 void removeConditionForObject (java_objectheader *object);
108 * use these functions only outside critical sections (intsEnable/intsRestore).
111 void signal_cond_for_object (java_objectheader *obj);
112 void broadcast_cond_for_object (java_objectheader *obj);
113 void wait_cond_for_object (java_objectheader *obj, s8 time);
114 void lock_mutex_for_object (java_objectheader *obj);
115 void unlock_mutex_for_object (java_objectheader *obj);
117 void lock_mutex (iMux*);
118 void unlock_mutex (iMux*);
119 void wait_cond (iMux*, iCv*, s8);
120 void signal_cond (iCv*);
121 void broadcast_cond (iCv*);
124 * use these internal functions only in critical sections. blockInts must be exactly
127 void internal_lock_mutex (iMux*);
128 void internal_unlock_mutex (iMux*);
129 void internal_wait_cond (iMux*, iCv*, s8);
130 void internal_signal_cond (iCv*);
131 void internal_broadcast_cond (iCv*);
133 void internal_lock_mutex_for_object (java_objectheader *obj);
134 void internal_unlock_mutex_for_object (java_objectheader *obj);
135 void internal_broadcast_cond_for_object (java_objectheader *obj);
139 #endif /* USE_THREADS */
141 #endif /* __locks_h */