int current;
unsigned long stack_top;
GHashTable *data;
+ int pid;
};
+/* Disabling this define allows you to shut off a few checks in
+ * cothread_switch. This likely will speed things up fractionally */
+#define COTHREAD_PARANOID
+
/* this _cothread_ctx_key is used as a GThread key to the thread's context
* a GThread key is a "pointer" to memory space that is/can be different
*/
static GPrivate *_cothread_ctx_key;
-/* Disabling this define allows you to shut off a few checks in
- * cothread_switch. This likely will speed things up fractionally */
-/* #define COTHREAD_PARANOID */
+/*
+ * This should only after context init, since we do checking.
+ */
+static cothread_context *
+cothread_get_current_context (void)
+{
+ cothread_context *ctx;
+
+ ctx = g_private_get (_cothread_ctx_key);
+ g_assert(ctx);
+
+#ifdef COTHREAD_PARANOID
+ g_assert (ctx->pid == getpid());
+#endif
+
+ return ctx;
+}
/**
* cothread_context_init:
ctx->ncothreads = 1;
ctx->current = 0;
ctx->data = g_hash_table_new (g_str_hash, g_str_equal);
+ ctx->pid = getpid();
GST_INFO (GST_CAT_COTHREADS, "initializing cothreads");
cothread_state *
cothread_current_main (void)
{
- cothread_context *ctx = g_private_get (_cothread_ctx_key);
+ cothread_context *ctx = cothread_get_current_context();
return ctx->cothreads[0];
}
cothread_state *
cothread_current (void)
{
- cothread_context *ctx = g_private_get (_cothread_ctx_key);
+ cothread_context *ctx = cothread_get_current_context();
return ctx->cothreads[ctx->current];
}
static void
cothread_stub (void)
{
- cothread_context *ctx = g_private_get (_cothread_ctx_key);
+ cothread_context *ctx = cothread_get_current_context();
register cothread_state *thread = ctx->cothreads[ctx->current];
GST_DEBUG_ENTER ("");
int
cothread_getcurrent (void)
{
- cothread_context *ctx = g_private_get (_cothread_ctx_key);
+ cothread_context *ctx = cothread_get_current_context();
if (!ctx)
return -1;
void
cothread_context_set_data (cothread_state *thread, gchar *key, gpointer data)
{
- cothread_context *ctx = g_private_get (_cothread_ctx_key);
+ cothread_context *ctx = cothread_get_current_context();
g_hash_table_insert (ctx->data, key, data);
}
gpointer
cothread_context_get_data (cothread_state * thread, gchar * key)
{
- cothread_context *ctx = g_private_get (_cothread_ctx_key);
+ cothread_context *ctx = cothread_get_current_context();
return g_hash_table_lookup (ctx->data, key);
}
ctx = thread->ctx;
/* paranoia check to make sure we're in the right thread */
- current_ctx = g_private_get(_cothread_ctx_key);
+ current_ctx = cothread_get_current_context();
g_assert (ctx == current_ctx);
#ifdef COTHREAD_PARANOID