stw: Use u_handle_table to maintain context list.

This commit is contained in:
Michal Krol 2009-03-20 15:45:00 +01:00
parent 36e985e96e
commit 5465f3adf9
3 changed files with 23 additions and 28 deletions

View File

@ -135,17 +135,7 @@ stw_create_layer_context(
pipe_mutex_lock( stw_dev->mutex ); pipe_mutex_lock( stw_dev->mutex );
{ {
UINT_PTR i; hglrc = handle_table_add(stw_dev->ctx_table, ctx);
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;
}
}
} }
pipe_mutex_unlock( stw_dev->mutex ); pipe_mutex_unlock( stw_dev->mutex );
@ -195,12 +185,14 @@ stw_delete_context(
if (WindowFromDC( ctx->hdc ) != NULL) if (WindowFromDC( ctx->hdc ) != NULL)
ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc ); 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; ret = TRUE;
} }

View File

@ -94,6 +94,11 @@ st_init(const struct stw_winsys *stw_winsys)
pipe_mutex_init( stw_dev->mutex ); pipe_mutex_init( stw_dev->mutex );
stw_dev->ctx_table = handle_table_create();
if (!stw_dev->ctx_table) {
goto error1;
}
pixelformat_init(); pixelformat_init();
return TRUE; return TRUE;
@ -135,9 +140,12 @@ st_cleanup(void)
pipe_mutex_lock( stw_dev->mutex ); pipe_mutex_lock( stw_dev->mutex );
{ {
/* Ensure all contexts are destroyed */ /* Ensure all contexts are destroyed */
for (i = 0; i < STW_CONTEXT_MAX; i++) i = handle_table_get_first_handle(stw_dev->ctx_table);
if (stw_dev->ctx_array[i].ctx) while (i) {
stw_delete_context( i + 1 ); 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 ); pipe_mutex_unlock( stw_dev->mutex );
@ -163,13 +171,12 @@ st_cleanup(void)
struct stw_context * struct stw_context *
stw_lookup_context( UINT_PTR dhglrc ) stw_lookup_context( UINT_PTR dhglrc )
{ {
if (dhglrc == 0 || if (dhglrc == 0)
dhglrc >= STW_CONTEXT_MAX)
return NULL; return NULL;
if (stw_dev == NULL) if (stw_dev == NULL)
return NULL; return NULL;
return stw_dev->ctx_array[dhglrc - 1].ctx; return (struct stw_context *) handle_table_get(stw_dev->ctx_table, dhglrc);
} }

View File

@ -31,9 +31,7 @@
#include "pipe/p_compiler.h" #include "pipe/p_compiler.h"
#include "pipe/p_thread.h" #include "pipe/p_thread.h"
#include "util/u_handle_table.h"
#define STW_CONTEXT_MAX 32
struct pipe_screen; struct pipe_screen;
@ -45,9 +43,7 @@ struct stw_device
pipe_mutex mutex; pipe_mutex mutex;
struct { struct handle_table *ctx_table;
struct stw_context *ctx;
} ctx_array[STW_CONTEXT_MAX];
#ifdef DEBUG #ifdef DEBUG
unsigned long memdbg_no; unsigned long memdbg_no;