Commit 90cd8b07 authored by Jan Sikorski's avatar Jan Sikorski Committed by Alexandre Julliard

wined3d: Make reference count decrementing functions thread safe.

parent b905ea81
...@@ -708,8 +708,10 @@ ULONG CDECL wined3d_buffer_decref(struct wined3d_buffer *buffer) ...@@ -708,8 +708,10 @@ ULONG CDECL wined3d_buffer_decref(struct wined3d_buffer *buffer)
if (!refcount) if (!refcount)
{ {
wined3d_mutex_lock();
buffer->resource.parent_ops->wined3d_object_destroyed(buffer->resource.parent); buffer->resource.parent_ops->wined3d_object_destroyed(buffer->resource.parent);
buffer->resource.device->adapter->adapter_ops->adapter_destroy_buffer(buffer); buffer->resource.device->adapter->adapter_ops->adapter_destroy_buffer(buffer);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -99,7 +99,6 @@ ULONG CDECL wined3d_command_list_decref(struct wined3d_command_list *list) ...@@ -99,7 +99,6 @@ ULONG CDECL wined3d_command_list_decref(struct wined3d_command_list *list)
{ {
SIZE_T i; SIZE_T i;
wined3d_mutex_lock();
for (i = 0; i < list->command_list_count; ++i) for (i = 0; i < list->command_list_count; ++i)
wined3d_command_list_decref(list->command_lists[i]); wined3d_command_list_decref(list->command_lists[i]);
for (i = 0; i < list->resource_count; ++i) for (i = 0; i < list->resource_count; ++i)
...@@ -109,6 +108,7 @@ ULONG CDECL wined3d_command_list_decref(struct wined3d_command_list *list) ...@@ -109,6 +108,7 @@ ULONG CDECL wined3d_command_list_decref(struct wined3d_command_list *list)
for (i = 0; i < list->query_count; ++i) for (i = 0; i < list->query_count; ++i)
wined3d_query_decref(list->queries[i].query); wined3d_query_decref(list->queries[i].query);
wined3d_mutex_lock();
wined3d_cs_destroy_object(device->cs, wined3d_command_list_destroy_object, list); wined3d_cs_destroy_object(device->cs, wined3d_command_list_destroy_object, list);
wined3d_mutex_unlock(); wined3d_mutex_unlock();
} }
......
...@@ -263,8 +263,10 @@ ULONG CDECL wined3d_device_decref(struct wined3d_device *device) ...@@ -263,8 +263,10 @@ ULONG CDECL wined3d_device_decref(struct wined3d_device *device)
if (!refcount) if (!refcount)
{ {
wined3d_mutex_lock();
device->adapter->adapter_ops->adapter_destroy_device(device); device->adapter->adapter_ops->adapter_destroy_device(device);
TRACE("Destroyed device %p.\n", device); TRACE("Destroyed device %p.\n", device);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -187,6 +187,7 @@ ULONG CDECL wined3d_decref(struct wined3d *wined3d) ...@@ -187,6 +187,7 @@ ULONG CDECL wined3d_decref(struct wined3d *wined3d)
{ {
unsigned int i; unsigned int i;
wined3d_mutex_lock();
for (i = 0; i < wined3d->adapter_count; ++i) for (i = 0; i < wined3d->adapter_count; ++i)
{ {
struct wined3d_adapter *adapter = wined3d->adapters[i]; struct wined3d_adapter *adapter = wined3d->adapters[i];
...@@ -194,6 +195,7 @@ ULONG CDECL wined3d_decref(struct wined3d *wined3d) ...@@ -194,6 +195,7 @@ ULONG CDECL wined3d_decref(struct wined3d *wined3d)
adapter->adapter_ops->adapter_destroy(adapter); adapter->adapter_ops->adapter_destroy(adapter);
} }
heap_free(wined3d); heap_free(wined3d);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -47,7 +47,11 @@ ULONG CDECL wined3d_palette_decref(struct wined3d_palette *palette) ...@@ -47,7 +47,11 @@ ULONG CDECL wined3d_palette_decref(struct wined3d_palette *palette)
TRACE("%p decreasing refcount to %u.\n", palette, refcount); TRACE("%p decreasing refcount to %u.\n", palette, refcount);
if (!refcount) if (!refcount)
{
wined3d_mutex_lock();
wined3d_cs_destroy_object(palette->device->cs, wined3d_palette_destroy_object, palette); wined3d_cs_destroy_object(palette->device->cs, wined3d_palette_destroy_object, palette);
wined3d_mutex_unlock();
}
return refcount; return refcount;
} }
......
...@@ -444,9 +444,11 @@ ULONG CDECL wined3d_query_decref(struct wined3d_query *query) ...@@ -444,9 +444,11 @@ ULONG CDECL wined3d_query_decref(struct wined3d_query *query)
{ {
struct wined3d_device *device = query->device; struct wined3d_device *device = query->device;
wined3d_mutex_lock();
query->parent_ops->wined3d_object_destroyed(query->parent); query->parent_ops->wined3d_object_destroyed(query->parent);
wined3d_cs_destroy_object(device->cs, wined3d_query_destroy_object, query); wined3d_cs_destroy_object(device->cs, wined3d_query_destroy_object, query);
device->adapter->adapter_ops->adapter_destroy_query(query); device->adapter->adapter_ops->adapter_destroy_query(query);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -41,8 +41,10 @@ ULONG CDECL wined3d_sampler_decref(struct wined3d_sampler *sampler) ...@@ -41,8 +41,10 @@ ULONG CDECL wined3d_sampler_decref(struct wined3d_sampler *sampler)
if (!refcount) if (!refcount)
{ {
wined3d_mutex_lock();
sampler->parent_ops->wined3d_object_destroyed(sampler->parent); sampler->parent_ops->wined3d_object_destroyed(sampler->parent);
sampler->device->adapter->adapter_ops->adapter_destroy_sampler(sampler); sampler->device->adapter->adapter_ops->adapter_destroy_sampler(sampler);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -3439,8 +3439,10 @@ ULONG CDECL wined3d_shader_decref(struct wined3d_shader *shader) ...@@ -3439,8 +3439,10 @@ ULONG CDECL wined3d_shader_decref(struct wined3d_shader *shader)
if (!refcount) if (!refcount)
{ {
wined3d_mutex_lock();
shader->parent_ops->wined3d_object_destroyed(shader->parent); shader->parent_ops->wined3d_object_destroyed(shader->parent);
wined3d_cs_destroy_object(shader->device->cs, wined3d_shader_destroy_object, shader); wined3d_cs_destroy_object(shader->device->cs, wined3d_shader_destroy_object, shader);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -62,8 +62,10 @@ ULONG CDECL wined3d_blend_state_decref(struct wined3d_blend_state *state) ...@@ -62,8 +62,10 @@ ULONG CDECL wined3d_blend_state_decref(struct wined3d_blend_state *state)
if (!refcount) if (!refcount)
{ {
wined3d_mutex_lock();
state->parent_ops->wined3d_object_destroyed(state->parent); state->parent_ops->wined3d_object_destroyed(state->parent);
wined3d_cs_destroy_object(device->cs, wined3d_blend_state_destroy_object, state); wined3d_cs_destroy_object(device->cs, wined3d_blend_state_destroy_object, state);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
...@@ -136,8 +138,10 @@ ULONG CDECL wined3d_depth_stencil_state_decref(struct wined3d_depth_stencil_stat ...@@ -136,8 +138,10 @@ ULONG CDECL wined3d_depth_stencil_state_decref(struct wined3d_depth_stencil_stat
if (!refcount) if (!refcount)
{ {
wined3d_mutex_lock();
state->parent_ops->wined3d_object_destroyed(state->parent); state->parent_ops->wined3d_object_destroyed(state->parent);
wined3d_cs_destroy_object(device->cs, wined3d_depth_stencil_state_destroy_object, state); wined3d_cs_destroy_object(device->cs, wined3d_depth_stencil_state_destroy_object, state);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
...@@ -199,8 +203,10 @@ ULONG CDECL wined3d_rasterizer_state_decref(struct wined3d_rasterizer_state *sta ...@@ -199,8 +203,10 @@ ULONG CDECL wined3d_rasterizer_state_decref(struct wined3d_rasterizer_state *sta
if (!refcount) if (!refcount)
{ {
wined3d_mutex_lock();
state->parent_ops->wined3d_object_destroyed(state->parent); state->parent_ops->wined3d_object_destroyed(state->parent);
wined3d_cs_destroy_object(device->cs, wined3d_rasterizer_state_destroy_object, state); wined3d_cs_destroy_object(device->cs, wined3d_rasterizer_state_destroy_object, state);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -585,8 +585,10 @@ ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock) ...@@ -585,8 +585,10 @@ ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
if (!refcount) if (!refcount)
{ {
wined3d_mutex_lock();
wined3d_stateblock_state_cleanup(&stateblock->stateblock_state); wined3d_stateblock_state_cleanup(&stateblock->stateblock_state);
heap_free(stateblock); heap_free(stateblock);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -1536,6 +1536,11 @@ ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture) ...@@ -1536,6 +1536,11 @@ ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture)
if (!refcount) if (!refcount)
{ {
bool in_cs_thread = GetCurrentThreadId() == texture->resource.device->cs->thread_id;
/* This is called from the CS thread to destroy temporary textures. */
if (!in_cs_thread)
wined3d_mutex_lock();
/* Wait for the texture to become idle if it's using user memory, /* Wait for the texture to become idle if it's using user memory,
* since the application is allowed to free that memory once the * since the application is allowed to free that memory once the
* texture is destroyed. Note that this implies that * texture is destroyed. Note that this implies that
...@@ -1550,6 +1555,8 @@ ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture) ...@@ -1550,6 +1555,8 @@ ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture)
} }
} }
texture->resource.device->adapter->adapter_ops->adapter_destroy_texture(texture); texture->resource.device->adapter->adapter_ops->adapter_destroy_texture(texture);
if (!in_cs_thread)
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -68,9 +68,11 @@ ULONG CDECL wined3d_vertex_declaration_decref(struct wined3d_vertex_declaration ...@@ -68,9 +68,11 @@ ULONG CDECL wined3d_vertex_declaration_decref(struct wined3d_vertex_declaration
if (!refcount) if (!refcount)
{ {
wined3d_mutex_lock();
declaration->parent_ops->wined3d_object_destroyed(declaration->parent); declaration->parent_ops->wined3d_object_destroyed(declaration->parent);
wined3d_cs_destroy_object(declaration->device->cs, wined3d_cs_destroy_object(declaration->device->cs,
wined3d_vertex_declaration_destroy_object, declaration); wined3d_vertex_declaration_destroy_object, declaration);
wined3d_mutex_unlock();
} }
return refcount; return refcount;
......
...@@ -376,7 +376,11 @@ ULONG CDECL wined3d_rendertarget_view_decref(struct wined3d_rendertarget_view *v ...@@ -376,7 +376,11 @@ ULONG CDECL wined3d_rendertarget_view_decref(struct wined3d_rendertarget_view *v
TRACE("%p decreasing refcount to %u.\n", view, refcount); TRACE("%p decreasing refcount to %u.\n", view, refcount);
if (!refcount) if (!refcount)
{
wined3d_mutex_lock();
view->resource->device->adapter->adapter_ops->adapter_destroy_rendertarget_view(view); view->resource->device->adapter->adapter_ops->adapter_destroy_rendertarget_view(view);
wined3d_mutex_unlock();
}
return refcount; return refcount;
} }
...@@ -923,7 +927,11 @@ ULONG CDECL wined3d_shader_resource_view_decref(struct wined3d_shader_resource_v ...@@ -923,7 +927,11 @@ ULONG CDECL wined3d_shader_resource_view_decref(struct wined3d_shader_resource_v
TRACE("%p decreasing refcount to %u.\n", view, refcount); TRACE("%p decreasing refcount to %u.\n", view, refcount);
if (!refcount) if (!refcount)
{
wined3d_mutex_lock();
view->resource->device->adapter->adapter_ops->adapter_destroy_shader_resource_view(view); view->resource->device->adapter->adapter_ops->adapter_destroy_shader_resource_view(view);
wined3d_mutex_unlock();
}
return refcount; return refcount;
} }
...@@ -1441,7 +1449,11 @@ ULONG CDECL wined3d_unordered_access_view_decref(struct wined3d_unordered_access ...@@ -1441,7 +1449,11 @@ ULONG CDECL wined3d_unordered_access_view_decref(struct wined3d_unordered_access
TRACE("%p decreasing refcount to %u.\n", view, refcount); TRACE("%p decreasing refcount to %u.\n", view, refcount);
if (!refcount) if (!refcount)
{
wined3d_mutex_lock();
view->resource->device->adapter->adapter_ops->adapter_destroy_unordered_access_view(view); view->resource->device->adapter->adapter_ops->adapter_destroy_unordered_access_view(view);
wined3d_mutex_unlock();
}
return refcount; return refcount;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment