diff --git a/gst/cothreads.c b/gst/cothreads.c index b10dece445..2f9a73d6fc 100644 --- a/gst/cothreads.c +++ b/gst/cothreads.c @@ -155,7 +155,7 @@ cothread_init (void) cothread_state* cothread_main(cothread_context *ctx) { - DEBUG(stderr,"returning %p, the 0th cothread\n",ctx->threads[0]); + DEBUG("returning %p, the 0th cothread\n",ctx->threads[0]); return ctx->threads[0]; } @@ -173,7 +173,18 @@ cothread_stub (void) thread->pc = 0; thread->sp = thread->top_sp; DEBUG("cothread: cothread_stub() exit\n"); - //printf("uh, yeah, we shouldn't be here, but we should deal anyway\n"); +// printf("uh, yeah, we shouldn't be here, but we should deal anyway\n"); +} + +/** + * cothread_getcurrent: + * + * Returns: the current cothread id + */ +int cothread_getcurrent(void) { + cothread_context *ctx = pthread_getspecific(_cothread_key); + if (!ctx) return -1; + return ctx->current; } /** diff --git a/gst/cothreads.h b/gst/cothreads.h index 7e33cd3d30..95fe6420c2 100644 --- a/gst/cothreads.h +++ b/gst/cothreads.h @@ -65,6 +65,7 @@ cothread_context* cothread_init(); cothread_state* cothread_create (cothread_context *ctx); void cothread_setfunc (cothread_state *thread, cothread_func func, int argc, char **argv); +int cothread_getcurrent (void); void cothread_switch (cothread_state *thread); void cothread_set_data (cothread_state *thread, gchar *key, gpointer data); gpointer cothread_get_data (cothread_state *thread, gchar *key); diff --git a/gst/gst.h b/gst/gst.h index 15db53e9c1..88e3665048 100644 --- a/gst/gst.h +++ b/gst/gst.h @@ -48,6 +48,8 @@ #include +#include + /* initialize GST */ void gst_init(int *argc,char **argv[]); @@ -57,7 +59,7 @@ void gst_main_quit (void); /* debugging */ #ifndef DEBUG #ifdef DEBUG_ENABLED -#define DEBUG(format, args...) g_print("DEBUG:(%d) " format, getpid() , ##args) +#define DEBUG(format, args...) g_print("DEBUG:(%d:%d) " format, getpid() , cothread_getcurrent() , ##args) #else #define DEBUG(format, args...) #endif