-/* $Id: hash.c,v 1.6 2000/01/24 16:19:54 brianp Exp $ */
+/* $Id: hash.c,v 1.9 2000/03/21 22:20:42 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "all.h"
#else
#include "glheader.h"
+#include "glthread.h"
#include "hash.h"
#include "mem.h"
#endif
struct _mesa_HashTable {
struct HashEntry *Table[TABLE_SIZE];
GLuint MaxKey;
+ _glthread_Mutex Mutex;
};
assert(table);
assert(key);
+ _glthread_LOCK_MUTEX(table->Mutex);
+
if (key > table->MaxKey)
table->MaxKey = key;
if (entry->Key == key) {
/* replace entry's data */
entry->Data = data;
+ _glthread_UNLOCK_MUTEX(table->Mutex);
return;
}
entry = entry->Next;
entry->Data = data;
entry->Next = table->Table[pos];
table->Table[pos] = entry;
+
+ _glthread_UNLOCK_MUTEX(table->Mutex);
}
assert(table);
assert(key);
+ _glthread_LOCK_MUTEX(table->Mutex);
+
pos = key & (TABLE_SIZE-1);
prev = NULL;
entry = table->Table[pos];
table->Table[pos] = entry->Next;
}
FREE(entry);
+ _glthread_UNLOCK_MUTEX(table->Mutex);
return;
}
prev = entry;
entry = entry->Next;
}
+
+ _glthread_UNLOCK_MUTEX(table->Mutex);
}
/*
* Return the key of the "first" entry in the hash table.
- * By calling this function until zero is returned we can get
- * the keys of all entries in the table.
+ * This is used in the course of deleting all display lists when
+ * a context is destroyed.
*/
-GLuint _mesa_HashFirstEntry(const struct _mesa_HashTable *table)
+GLuint _mesa_HashFirstEntry(struct _mesa_HashTable *table)
{
GLuint pos;
assert(table);
+ _glthread_LOCK_MUTEX(table->Mutex);
for (pos=0; pos < TABLE_SIZE; pos++) {
- if (table->Table[pos])
+ if (table->Table[pos]) {
+ _glthread_UNLOCK_MUTEX(table->Mutex);
return table->Table[pos]->Key;
+ }
}
+ _glthread_UNLOCK_MUTEX(table->Mutex);
return 0;
}
* numKeys - number of keys needed
* Return: starting key of free block or 0 if failure
*/
-GLuint _mesa_HashFindFreeKeyBlock(const struct _mesa_HashTable *table, GLuint numKeys)
+GLuint _mesa_HashFindFreeKeyBlock(struct _mesa_HashTable *table, GLuint numKeys)
{
GLuint maxKey = ~((GLuint) 0);
+ _glthread_LOCK_MUTEX(table->Mutex);
if (maxKey - numKeys > table->MaxKey) {
/* the quick solution */
+ _glthread_UNLOCK_MUTEX(table->Mutex);
return table->MaxKey + 1;
}
else {
/* this key not in use, check if we've found enough */
freeCount++;
if (freeCount == numKeys) {
+ _glthread_UNLOCK_MUTEX(table->Mutex);
return freeStart;
}
}
}
/* cannot allocate a block of numKeys consecutive keys */
+ _glthread_UNLOCK_MUTEX(table->Mutex);
return 0;
}
}