use BCOPY macro on FreeBSD
[mesa.git] / src / mesa / main / hash.c
index 88e94e7884d19d2d764993746040dcaf8589e057..17bcd1c5f3e62eb605a66b3f13659d25090d319e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: hash.c,v 1.7 2000/01/31 23:11:39 brianp Exp $ */
+/* $Id: hash.c,v 1.9 2000/03/21 22:20:42 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -203,17 +203,21 @@ void _mesa_HashRemove(struct _mesa_HashTable *table, GLuint key)
 
 /*
  * 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;
 }
 
@@ -243,11 +247,13 @@ void _mesa_HashPrint(const struct _mesa_HashTable *table)
  *         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 {
@@ -265,11 +271,13 @@ GLuint _mesa_HashFindFreeKeyBlock(const struct _mesa_HashTable *table, GLuint nu
            /* 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;
    }
 }