Add some assertions to check that we're running inside the correct thread when playing with that thread's cothreads

Original commit message from CVS:
Add some assertions to check that we're running inside the correct
thread when playing with that thread's cothreads
This commit is contained in:
David Schleef 2002-12-04 00:07:13 +00:00
parent 61a64d7910
commit 89994cf808

View file

@ -58,7 +58,7 @@ struct _cothread_context
int current; int current;
unsigned long stack_top; unsigned long stack_top;
GHashTable *data; GHashTable *data;
int pid; GThread *thread;
}; };
/* Disabling this define allows you to shut off a few checks in /* Disabling this define allows you to shut off a few checks in
@ -85,7 +85,7 @@ cothread_get_current_context (void)
g_assert(ctx); g_assert(ctx);
#ifdef COTHREAD_PARANOID #ifdef COTHREAD_PARANOID
g_assert (ctx->pid == getpid()); g_assert (ctx->thread == g_thread_self());
#endif #endif
return ctx; return ctx;
@ -122,7 +122,7 @@ cothread_context_init (void)
ctx->ncothreads = 1; ctx->ncothreads = 1;
ctx->current = 0; ctx->current = 0;
ctx->data = g_hash_table_new (g_str_hash, g_str_equal); ctx->data = g_hash_table_new (g_str_hash, g_str_equal);
ctx->pid = getpid(); ctx->thread = g_thread_self();
GST_INFO (GST_CAT_COTHREADS, "initializing cothreads"); GST_INFO (GST_CAT_COTHREADS, "initializing cothreads");
@ -187,6 +187,7 @@ cothread_context_free (cothread_context *ctx)
gint i; gint i;
g_return_if_fail (ctx != NULL); g_return_if_fail (ctx != NULL);
g_assert (ctx->thread == g_thread_self());
GST_INFO (GST_CAT_COTHREADS, "free cothread context"); GST_INFO (GST_CAT_COTHREADS, "free cothread context");
@ -218,6 +219,7 @@ cothread_create (cothread_context *ctx)
unsigned long page_size; unsigned long page_size;
g_return_val_if_fail (ctx != NULL, NULL); g_return_val_if_fail (ctx != NULL, NULL);
g_assert (ctx->thread == g_thread_self());
if (ctx->ncothreads == COTHREAD_MAXTHREADS) { if (ctx->ncothreads == COTHREAD_MAXTHREADS) {
/* this is pretty fatal */ /* this is pretty fatal */
@ -334,6 +336,7 @@ cothread_destroy (cothread_state *cothread)
cothreadnum = cothread->cothreadnum; cothreadnum = cothread->cothreadnum;
ctx = cothread->ctx; ctx = cothread->ctx;
g_assert (ctx->thread == g_thread_self());
GST_INFO (GST_CAT_COTHREADS, "destroy cothread %d %p %d", GST_INFO (GST_CAT_COTHREADS, "destroy cothread %d %p %d",
cothreadnum, cothread, ctx->current); cothreadnum, cothread, ctx->current);
@ -643,7 +646,6 @@ void
cothread_switch (cothread_state * thread) cothread_switch (cothread_state * thread)
{ {
cothread_context *ctx; cothread_context *ctx;
cothread_context *current_ctx;
cothread_state *current; cothread_state *current;
int enter; int enter;
@ -654,8 +656,7 @@ cothread_switch (cothread_state * thread)
ctx = thread->ctx; ctx = thread->ctx;
/* paranoia check to make sure we're in the right thread */ /* paranoia check to make sure we're in the right thread */
current_ctx = cothread_get_current_context(); g_assert (ctx->thread == g_thread_self());
g_assert (ctx == current_ctx);
#ifdef COTHREAD_PARANOID #ifdef COTHREAD_PARANOID
if (ctx == NULL) if (ctx == NULL)