if (!ids)
return;
+ _mesa_HashLockMutex(ctx->Shared->Programs);
+
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n);
/* Insert pointer to dummy program as placeholder */
for (i = 0; i < (GLuint) n; i++) {
- _mesa_HashInsert(ctx->Shared->Programs, first + i, &_mesa_DummyProgram);
+ _mesa_HashInsertLocked(ctx->Shared->Programs, first + i,
+ &_mesa_DummyProgram);
}
+ _mesa_HashUnlockMutex(ctx->Shared->Programs);
+
/* Return the program names */
for (i = 0; i < (GLuint) n; i++) {
ids[i] = first + i;
return 0;
}
+ _mesa_HashLockMutex(ctx->Shared->ATIShaders);
+
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->ATIShaders, range);
for (i = 0; i < range; i++) {
- _mesa_HashInsert(ctx->Shared->ATIShaders, first + i, &DummyShader);
+ _mesa_HashInsertLocked(ctx->Shared->ATIShaders, first + i, &DummyShader);
}
+ _mesa_HashUnlockMutex(ctx->Shared->ATIShaders);
+
return first;
}
struct gl_buffer_object *
_mesa_lookup_bufferobj_locked(struct gl_context *ctx, GLuint buffer)
{
- return (struct gl_buffer_object *)
- _mesa_HashLookupLocked(ctx->Shared->BufferObjects, buffer);
+ if (buffer == 0)
+ return NULL;
+ else
+ return (struct gl_buffer_object *)
+ _mesa_HashLookupLocked(ctx->Shared->BufferObjects, buffer);
}
/**
return;
}
- mtx_lock(&ctx->Shared->Mutex);
+ _mesa_HashLockMutex(ctx->Shared->BufferObjects);
for (i = 0; i < n; i++) {
- struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, ids[i]);
+ struct gl_buffer_object *bufObj =
+ _mesa_lookup_bufferobj_locked(ctx, ids[i]);
if (bufObj) {
struct gl_vertex_array_object *vao = ctx->Array.VAO;
GLuint j;
}
/* The ID is immediately freed for re-use */
- _mesa_HashRemove(ctx->Shared->BufferObjects, ids[i]);
+ _mesa_HashRemoveLocked(ctx->Shared->BufferObjects, ids[i]);
/* Make sure we do not run into the classic ABA problem on bind.
* We don't want to allow re-binding a buffer object that's been
* "deleted" by glDeleteBuffers().
}
}
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
/*
* This must be atomic (generation and allocation of buffer object IDs)
*/
- mtx_lock(&ctx->Shared->Mutex);
+ _mesa_HashLockMutex(ctx->Shared->BufferObjects);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n);
buf = ctx->Driver.NewBufferObject(ctx, buffers[i]);
if (!buf) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
return;
}
}
else
buf = &DummyBufferObject;
- _mesa_HashInsert(ctx->Shared->BufferObjects, buffers[i], buf);
+ _mesa_HashInsertLocked(ctx->Shared->BufferObjects, buffers[i], buf);
}
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
}
/**
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
- mtx_lock(&ctx->Shared->Mutex);
bufObj = _mesa_lookup_bufferobj(ctx, id);
- mtx_unlock(&ctx->Shared->Mutex);
return bufObj && bufObj != &DummyBufferObject;
}
/*
* Make this an atomic operation
*/
- mtx_lock(&ctx->Shared->Mutex);
+ _mesa_HashLockMutex(ctx->Shared->DisplayList);
base = _mesa_HashFindFreeKeyBlock(ctx->Shared->DisplayList, range);
if (base) {
/* reserve the list IDs by with empty/dummy lists */
GLint i;
for (i = 0; i < range; i++) {
- _mesa_HashInsert(ctx->Shared->DisplayList, base + i,
- make_list(base + i, 1));
+ _mesa_HashInsertLocked(ctx->Shared->DisplayList, base + i,
+ make_list(base + i, 1));
}
}
}
}
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->DisplayList);
return base;
}
static struct gl_renderbuffer *
-allocate_renderbuffer(struct gl_context *ctx, GLuint renderbuffer,
- const char *func)
+allocate_renderbuffer_locked(struct gl_context *ctx, GLuint renderbuffer,
+ const char *func)
{
struct gl_renderbuffer *newRb;
return NULL;
}
assert(newRb->AllocStorage);
- mtx_lock(&ctx->Shared->Mutex);
- _mesa_HashInsert(ctx->Shared->RenderBuffers, renderbuffer, newRb);
+ _mesa_HashInsertLocked(ctx->Shared->RenderBuffers, renderbuffer, newRb);
newRb->RefCount = 1; /* referenced by hash table */
- mtx_unlock(&ctx->Shared->Mutex);
return newRb;
}
}
if (!newRb) {
- newRb = allocate_renderbuffer(ctx, renderbuffer, "glBindRenderbufferEXT");
+ _mesa_HashLockMutex(ctx->Shared->RenderBuffers);
+ newRb = allocate_renderbuffer_locked(ctx, renderbuffer,
+ "glBindRenderbufferEXT");
+ _mesa_HashUnlockMutex(ctx->Shared->RenderBuffers);
}
}
else {
if (!renderbuffers)
return;
+ _mesa_HashLockMutex(ctx->Shared->RenderBuffers);
+
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->RenderBuffers, n);
for (i = 0; i < n; i++) {
renderbuffers[i] = name;
if (dsa) {
- allocate_renderbuffer(ctx, name, func);
+ allocate_renderbuffer_locked(ctx, name, func);
} else {
/* insert a dummy renderbuffer into the hash table */
- mtx_lock(&ctx->Shared->Mutex);
- _mesa_HashInsert(ctx->Shared->RenderBuffers, name, &DummyRenderbuffer);
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashInsertLocked(ctx->Shared->RenderBuffers, name,
+ &DummyRenderbuffer);
}
}
+
+ _mesa_HashUnlockMutex(ctx->Shared->RenderBuffers);
}
if (!framebuffers)
return;
+ _mesa_HashLockMutex(ctx->Shared->FrameBuffers);
+
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->FrameBuffers, n);
for (i = 0; i < n; i++) {
else
fb = &DummyFramebuffer;
- mtx_lock(&ctx->Shared->Mutex);
- _mesa_HashInsert(ctx->Shared->FrameBuffers, name, fb);
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashInsertLocked(ctx->Shared->FrameBuffers, name, fb);
}
+
+ _mesa_HashUnlockMutex(ctx->Shared->FrameBuffers);
}
_mesa_HashFindFreeKeyBlock(struct _mesa_HashTable *table, GLuint numKeys)
{
const GLuint maxKey = ~((GLuint) 0) - 1;
- mtx_lock(&table->Mutex);
if (maxKey - numKeys > table->MaxKey) {
/* the quick solution */
- mtx_unlock(&table->Mutex);
return table->MaxKey + 1;
}
else {
/* this key not in use, check if we've found enough */
freeCount++;
if (freeCount == numKeys) {
- mtx_unlock(&table->Mutex);
return freeStart;
}
}
}
/* cannot allocate a block of numKeys consecutive keys */
- mtx_unlock(&table->Mutex);
return 0;
}
}
_mesa_HashLookup(ctx->Shared->SamplerObjects, name);
}
+static struct gl_sampler_object *
+_mesa_lookup_samplerobj_locked(struct gl_context *ctx, GLuint name)
+{
+ if (name == 0)
+ return NULL;
+ else
+ return (struct gl_sampler_object *)
+ _mesa_HashLookupLocked(ctx->Shared->SamplerObjects, name);
+}
static inline void
begin_samplerobj_lookups(struct gl_context *ctx)
if (!samplers)
return;
+ _mesa_HashLockMutex(ctx->Shared->SamplerObjects);
+
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->SamplerObjects, count);
/* Insert the ID and pointer to new sampler object into hash table */
for (i = 0; i < count; i++) {
struct gl_sampler_object *sampObj =
ctx->Driver.NewSamplerObject(ctx, first + i);
- _mesa_HashInsert(ctx->Shared->SamplerObjects, first + i, sampObj);
+ _mesa_HashInsertLocked(ctx->Shared->SamplerObjects, first + i, sampObj);
samplers[i] = first + i;
}
+
+ _mesa_HashUnlockMutex(ctx->Shared->SamplerObjects);
}
void GLAPIENTRY
return;
}
- mtx_lock(&ctx->Shared->Mutex);
+ _mesa_HashLockMutex(ctx->Shared->SamplerObjects);
for (i = 0; i < count; i++) {
if (samplers[i]) {
GLuint j;
struct gl_sampler_object *sampObj =
- _mesa_lookup_samplerobj(ctx, samplers[i]);
+ _mesa_lookup_samplerobj_locked(ctx, samplers[i]);
if (sampObj) {
/* If the sampler is currently bound, unbind it. */
}
/* The ID is immediately freed for re-use */
- _mesa_HashRemove(ctx->Shared->SamplerObjects, samplers[i]);
+ _mesa_HashRemoveLocked(ctx->Shared->SamplerObjects, samplers[i]);
/* But the object exists until its reference count goes to zero */
_mesa_reference_sampler_object(ctx, &sampObj, NULL);
}
}
}
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->SamplerObjects);
}
return 0;
}
+ _mesa_HashLockMutex(ctx->Shared->ShaderObjects);
name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
sh = ctx->Driver.NewShader(ctx, name, type);
- _mesa_HashInsert(ctx->Shared->ShaderObjects, name, sh);
+ _mesa_HashInsertLocked(ctx->Shared->ShaderObjects, name, sh);
+ _mesa_HashUnlockMutex(ctx->Shared->ShaderObjects);
return name;
}
GLuint name;
struct gl_shader_program *shProg;
+ _mesa_HashLockMutex(ctx->Shared->ShaderObjects);
+
name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1);
shProg = _mesa_new_shader_program(name);
- _mesa_HashInsert(ctx->Shared->ShaderObjects, name, shProg);
+ _mesa_HashInsertLocked(ctx->Shared->ShaderObjects, name, shProg);
assert(shProg->RefCount == 1);
+ _mesa_HashUnlockMutex(ctx->Shared->ShaderObjects);
+
return name;
}
/*
* This must be atomic (generation and allocation of texture IDs)
*/
- mtx_lock(&ctx->Shared->Mutex);
+ _mesa_HashLockMutex(ctx->Shared->TexObjects);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
GLuint name = first + i;
texObj = ctx->Driver.NewTextureObject(ctx, name, target);
if (!texObj) {
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->TexObjects);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "gl%sTextures", caller);
return;
}
/* insert into hash table */
- _mesa_HashInsert(ctx->Shared->TexObjects, texObj->Name, texObj);
+ _mesa_HashInsertLocked(ctx->Shared->TexObjects, texObj->Name, texObj);
textures[i] = name;
}
- mtx_unlock(&ctx->Shared->Mutex);
+ _mesa_HashUnlockMutex(ctx->Shared->TexObjects);
}
/*@}*/
/* The texture _name_ is now free for re-use.
* Remove it from the hash table now.
*/
- mtx_lock(&ctx->Shared->Mutex);
_mesa_HashRemove(ctx->Shared->TexObjects, delObj->Name);
- mtx_unlock(&ctx->Shared->Mutex);
/* Unreference the texobj. If refcount hits zero, the texture
* will be deleted.
}
/* and insert it into hash table */
- mtx_lock(&ctx->Shared->Mutex);
_mesa_HashInsert(ctx->Shared->TexObjects, texName, newTexObj);
- mtx_unlock(&ctx->Shared->Mutex);
}
}