added more locking
authorBrian Paul <brian.paul@tungstengraphics.com>
Tue, 21 Mar 2000 17:42:27 +0000 (17:42 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Tue, 21 Mar 2000 17:42:27 +0000 (17:42 +0000)
src/mesa/main/dlist.c
src/mesa/main/hash.c
src/mesa/main/texobj.c

index 995e413..13976d8 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: dlist.c,v 1.35 2000/03/19 01:10:11 brianp Exp $ */
+/* $Id: dlist.c,v 1.36 2000/03/21 17:42:27 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -3957,6 +3957,11 @@ _mesa_GenLists(GLsizei range )
       return 0;
    }
 
+   /*
+    * Make this an atomic operation
+    */
+   _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
+
    base = _mesa_HashFindFreeKeyBlock(ctx->Shared->DisplayList, range);
    if (base) {
       /* reserve the list IDs by with empty/dummy lists */
@@ -3965,6 +3970,9 @@ _mesa_GenLists(GLsizei range )
          _mesa_HashInsert(ctx->Shared->DisplayList, base+i, make_empty_list());
       }
    }
+
+   _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
+
    return base;
 }
 
index 88e94e7..cbd7f55 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.8 2000/03/21 17:42:27 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 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;
 }
 
@@ -246,8 +250,10 @@ void _mesa_HashPrint(const struct _mesa_HashTable *table)
 GLuint _mesa_HashFindFreeKeyBlock(const 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;
    }
 }
index f782212..02de5a3 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: texobj.c,v 1.14 2000/02/12 01:59:19 brianp Exp $ */
+/* $Id: texobj.c,v 1.15 2000/03/21 17:42:27 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -325,6 +325,8 @@ void gl_test_texture_object_completeness( const GLcontext *ctx, struct gl_textur
 }
 
 
+_glthread_DECLARE_STATIC_MUTEX(GenTexturesLock);
+
 
 /*
  * Execute glGenTextures
@@ -342,6 +344,12 @@ _mesa_GenTextures( GLsizei n, GLuint *texName )
       return;
    }
 
+
+   /*
+    * This must be atomic (generation and allocation of texture IDs)
+    */
+   _glthread_LOCK_MUTEX(GenTexturesLock);
+
    first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
 
    /* Return the texture names */
@@ -355,6 +363,8 @@ _mesa_GenTextures( GLsizei n, GLuint *texName )
       GLuint dims = 0;
       (void) gl_alloc_texture_object(ctx->Shared, name, dims);
    }
+
+   _glthread_UNLOCK_MUTEX(GenTexturesLock);
 }