Mesa (master): r300g: fix a possible race when counting contexts
Marek Olšák
mareko at kemper.freedesktop.org
Fri Feb 18 23:18:23 UTC 2011
Module: Mesa
Branch: master
Commit: 0b436cf511316d4bf90246a39557900b4b566853
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=0b436cf511316d4bf90246a39557900b4b566853
Author: Marek Olšák <maraeo at gmail.com>
Date: Sat Feb 19 00:16:44 2011 +0100
r300g: fix a possible race when counting contexts
Atomics aren't sufficient here.
---
src/gallium/drivers/r300/r300_context.c | 6 ++++--
src/gallium/drivers/r300/r300_screen.c | 3 +++
src/gallium/drivers/r300/r300_screen.h | 1 +
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c
index a89bf7f..da6b0bb 100644
--- a/src/gallium/drivers/r300/r300_context.c
+++ b/src/gallium/drivers/r300/r300_context.c
@@ -38,19 +38,21 @@
static void r300_update_num_contexts(struct r300_screen *r300screen,
int diff)
{
+ pipe_mutex_lock(r300screen->num_contexts_mutex);
if (diff > 0) {
- p_atomic_inc(&r300screen->num_contexts);
+ r300screen->num_contexts++;
if (r300screen->num_contexts > 1)
util_slab_set_thread_safety(&r300screen->pool_buffers,
UTIL_SLAB_MULTITHREADED);
} else {
- p_atomic_dec(&r300screen->num_contexts);
+ r300screen->num_contexts--;
if (r300screen->num_contexts <= 1)
util_slab_set_thread_safety(&r300screen->pool_buffers,
UTIL_SLAB_SINGLETHREADED);
}
+ pipe_mutex_unlock(r300screen->num_contexts_mutex);
}
static void r300_release_referenced_objects(struct r300_context *r300)
diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c
index ed47315..77a9c6a 100644
--- a/src/gallium/drivers/r300/r300_screen.c
+++ b/src/gallium/drivers/r300/r300_screen.c
@@ -398,6 +398,7 @@ static void r300_destroy_screen(struct pipe_screen* pscreen)
struct r300_winsys_screen *rws = r300_winsys_screen(pscreen);
util_slab_destroy(&r300screen->pool_buffers);
+ pipe_mutex_destroy(r300screen->num_contexts_mutex);
if (rws)
rws->destroy(rws);
@@ -459,6 +460,8 @@ struct pipe_screen* r300_screen_create(struct r300_winsys_screen *rws)
r300screen->caps.is_r500 &&
rws->get_value(rws, R300_VID_DRM_2_3_0);
+ pipe_mutex_init(r300screen->num_contexts_mutex);
+
util_slab_create(&r300screen->pool_buffers,
sizeof(struct r300_resource), 64,
UTIL_SLAB_SINGLETHREADED);
diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h
index c935f55..576f9c1 100644
--- a/src/gallium/drivers/r300/r300_screen.h
+++ b/src/gallium/drivers/r300/r300_screen.h
@@ -52,6 +52,7 @@ struct r300_screen {
/* The number of created contexts to know whether we have multiple
* contexts or not. */
int num_contexts;
+ pipe_mutex num_contexts_mutex;
};
More information about the mesa-commit
mailing list