aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/hash.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
committermarha <marha@users.sourceforge.net>2010-04-12 09:53:17 +0000
commit29b86f9852b2b7ecc31cdfee56679537e40bc6e2 (patch)
tree1e6ec8ccf2dbf773260a1953b8e13c49f9b7c5f5 /mesalib/src/mesa/main/hash.c
parent529236591df7366479a6fac30b387667678fd1ba (diff)
downloadvcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.gz
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.tar.bz2
vcxsrv-29b86f9852b2b7ecc31cdfee56679537e40bc6e2.zip
svn merge -r524:HEAD "^/branches/released" .
Diffstat (limited to 'mesalib/src/mesa/main/hash.c')
-rw-r--r--mesalib/src/mesa/main/hash.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/mesalib/src/mesa/main/hash.c b/mesalib/src/mesa/main/hash.c
index 08c64568c..b624e6eca 100644
--- a/mesalib/src/mesa/main/hash.c
+++ b/mesalib/src/mesa/main/hash.c
@@ -108,27 +108,23 @@ _mesa_DeleteHashTable(struct _mesa_HashTable *table)
_mesa_problem(NULL,
"In _mesa_DeleteHashTable, found non-freed data");
}
- _mesa_free(entry);
+ free(entry);
entry = next;
}
}
_glthread_DESTROY_MUTEX(table->Mutex);
_glthread_DESTROY_MUTEX(table->WalkMutex);
- _mesa_free(table);
+ free(table);
}
/**
- * Lookup an entry in the hash table.
- *
- * \param table the hash table.
- * \param key the key.
- *
- * \return pointer to user's data or NULL if key not in table
+ * Lookup an entry in the hash table, without locking.
+ * \sa _mesa_HashLookup
*/
-void *
-_mesa_HashLookup(const struct _mesa_HashTable *table, GLuint key)
+static INLINE void *
+_mesa_HashLookup_unlocked(struct _mesa_HashTable *table, GLuint key)
{
GLuint pos;
const struct HashEntry *entry;
@@ -140,7 +136,7 @@ _mesa_HashLookup(const struct _mesa_HashTable *table, GLuint key)
entry = table->Table[pos];
while (entry) {
if (entry->Key == key) {
- return entry->Data;
+ return entry->Data;
}
entry = entry->Next;
}
@@ -148,6 +144,25 @@ _mesa_HashLookup(const struct _mesa_HashTable *table, GLuint key)
}
+/**
+ * Lookup an entry in the hash table.
+ *
+ * \param table the hash table.
+ * \param key the key.
+ *
+ * \return pointer to user's data or NULL if key not in table
+ */
+void *
+_mesa_HashLookup(struct _mesa_HashTable *table, GLuint key)
+{
+ void *res;
+ assert(table);
+ _glthread_LOCK_MUTEX(table->Mutex);
+ res = _mesa_HashLookup_unlocked(table, key);
+ _glthread_UNLOCK_MUTEX(table->Mutex);
+ return res;
+}
+
/**
* Insert a key/pointer pair into the hash table.
@@ -191,10 +206,12 @@ _mesa_HashInsert(struct _mesa_HashTable *table, GLuint key, void *data)
/* alloc and insert new table entry */
entry = MALLOC_STRUCT(HashEntry);
- entry->Key = key;
- entry->Data = data;
- entry->Next = table->Table[pos];
- table->Table[pos] = entry;
+ if (entry) {
+ entry->Key = key;
+ entry->Data = data;
+ entry->Next = table->Table[pos];
+ table->Table[pos] = entry;
+ }
_glthread_UNLOCK_MUTEX(table->Mutex);
}
@@ -240,7 +257,7 @@ _mesa_HashRemove(struct _mesa_HashTable *table, GLuint key)
else {
table->Table[pos] = entry->Next;
}
- _mesa_free(entry);
+ free(entry);
_glthread_UNLOCK_MUTEX(table->Mutex);
return;
}
@@ -277,7 +294,7 @@ _mesa_HashDeleteAll(struct _mesa_HashTable *table,
for (entry = table->Table[pos]; entry; entry = next) {
callback(entry->Key, entry->Data, userData);
next = entry->Next;
- _mesa_free(entry);
+ free(entry);
}
table->Table[pos] = NULL;
}
@@ -442,7 +459,7 @@ _mesa_HashFindFreeKeyBlock(struct _mesa_HashTable *table, GLuint numKeys)
GLuint freeStart = 1;
GLuint key;
for (key = 1; key != maxKey; key++) {
- if (_mesa_HashLookup(table, key)) {
+ if (_mesa_HashLookup_unlocked(table, key)) {
/* darn, this key is already in use */
freeCount = 0;
freeStart = key+1;