From 5465f3adf93bd58b528bd6703b2367eb00c78c31 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Fri, 20 Mar 2009 15:45:00 +0100 Subject: stw: Use u_handle_table to maintain context list. --- .../state_trackers/wgl/shared/stw_context.c | 24 ++++++++-------------- src/gallium/state_trackers/wgl/shared/stw_device.c | 19 +++++++++++------ src/gallium/state_trackers/wgl/shared/stw_device.h | 8 ++------ 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c index 69f25d6187e..31cb025ac56 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.c +++ b/src/gallium/state_trackers/wgl/shared/stw_context.c @@ -135,17 +135,7 @@ stw_create_layer_context( pipe_mutex_lock( stw_dev->mutex ); { - UINT_PTR i; - - for (i = 0; i < STW_CONTEXT_MAX; i++) { - if (stw_dev->ctx_array[i].ctx == NULL) { - /* success: - */ - stw_dev->ctx_array[i].ctx = ctx; - hglrc = i + 1; - break; - } - } + hglrc = handle_table_add(stw_dev->ctx_table, ctx); } pipe_mutex_unlock( stw_dev->mutex ); @@ -195,12 +185,14 @@ stw_delete_context( if (WindowFromDC( ctx->hdc ) != NULL) ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc ); - st_destroy_context( ctx->st ); + pipe_mutex_lock(stw_dev->mutex); + { + st_destroy_context(ctx->st); + FREE(ctx); + handle_table_remove(stw_dev->ctx_table, hglrc); + } + pipe_mutex_unlock(stw_dev->mutex); - FREE( ctx ); - - stw_dev->ctx_array[hglrc - 1].ctx = NULL; - ret = TRUE; } diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c index 4bec036fe35..3c1eb1ad393 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.c +++ b/src/gallium/state_trackers/wgl/shared/stw_device.c @@ -94,6 +94,11 @@ st_init(const struct stw_winsys *stw_winsys) pipe_mutex_init( stw_dev->mutex ); + stw_dev->ctx_table = handle_table_create(); + if (!stw_dev->ctx_table) { + goto error1; + } + pixelformat_init(); return TRUE; @@ -135,9 +140,12 @@ st_cleanup(void) pipe_mutex_lock( stw_dev->mutex ); { /* Ensure all contexts are destroyed */ - for (i = 0; i < STW_CONTEXT_MAX; i++) - if (stw_dev->ctx_array[i].ctx) - stw_delete_context( i + 1 ); + i = handle_table_get_first_handle(stw_dev->ctx_table); + while (i) { + stw_delete_context(i); + i = handle_table_get_next_handle(stw_dev->ctx_table, i); + } + handle_table_destroy(stw_dev->ctx_table); } pipe_mutex_unlock( stw_dev->mutex ); @@ -163,13 +171,12 @@ st_cleanup(void) struct stw_context * stw_lookup_context( UINT_PTR dhglrc ) { - if (dhglrc == 0 || - dhglrc >= STW_CONTEXT_MAX) + if (dhglrc == 0) return NULL; if (stw_dev == NULL) return NULL; - return stw_dev->ctx_array[dhglrc - 1].ctx; + return (struct stw_context *) handle_table_get(stw_dev->ctx_table, dhglrc); } diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.h b/src/gallium/state_trackers/wgl/shared/stw_device.h index 80da14b84f4..6a9cee0d028 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.h +++ b/src/gallium/state_trackers/wgl/shared/stw_device.h @@ -31,9 +31,7 @@ #include "pipe/p_compiler.h" #include "pipe/p_thread.h" - - -#define STW_CONTEXT_MAX 32 +#include "util/u_handle_table.h" struct pipe_screen; @@ -45,9 +43,7 @@ struct stw_device pipe_mutex mutex; - struct { - struct stw_context *ctx; - } ctx_array[STW_CONTEXT_MAX]; + struct handle_table *ctx_table; #ifdef DEBUG unsigned long memdbg_no; -- cgit v1.2.3