From: David S. <dsc...@us...> - 2002-07-10 18:16:59
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Wed Jul 10 2002 11:16:57 PDT Log message: Fix GstBufferFlag so it's really an enum typedef, not a declaration. Modified files: gst : gstbuffer.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstbuffer.h.diff?r1=1.40&r2=1.41 ====Begin Diffs==== Index: gstbuffer.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstbuffer.h,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- gstbuffer.h 9 Jul 2002 11:08:01 -0000 1.40 +++ gstbuffer.h 10 Jul 2002 18:16:44 -0000 1.41 @@ -60,7 +60,7 @@ #define GST_BUFFER_BUFFERPOOL(buf) (GST_BUFFER(buf)->pool) #define GST_BUFFER_POOL_PRIVATE(buf) (GST_BUFFER(buf)->pool_private) -enum { +typedef enum { GST_BUFFER_READONLY = GST_DATA_FLAG_LAST, GST_BUFFER_SUBBUFFER, GST_BUFFER_ORIGINAL, |
From: David S. <dsc...@us...> - 2002-09-22 04:28:46
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Sat Sep 21 2002 21:28:45 PDT Log message: Got tired of FOURCCs being printed backwards on big-endian machines. Modified files: gst : gstprops.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstprops.c.diff?r1=1.63&r2=1.64 ====Begin Diffs==== Index: gstprops.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstprops.c,v retrieving revision 1.63 retrieving revision 1.64 diff -u -d -r1.63 -r1.64 --- gstprops.c 17 Sep 2002 23:46:52 -0000 1.63 +++ gstprops.c 22 Sep 2002 04:28:33 -0000 1.64 @@ -131,7 +131,11 @@ GST_DEBUG (GST_CAT_PROPERTIES, "%s: float %f", name, entry->data.float_data); break; case GST_PROPS_FOURCC_TYPE: - GST_DEBUG (GST_CAT_PROPERTIES, "%s: fourcc %4.4s", name, (gchar*)&entry->data.fourcc_data); + GST_DEBUG (GST_CAT_PROPERTIES, "%s: fourcc %c%c%c%c", name, + (entry->data.fourcc_data>>0)&0xff, + (entry->data.fourcc_data>>8)&0xff, + (entry->data.fourcc_data>>16)&0xff, + (entry->data.fourcc_data>>24)&0xff); break; case GST_PROPS_BOOL_TYPE: GST_DEBUG (GST_CAT_PROPERTIES, "%s: bool %d", name, entry->data.bool_data); @@ -1334,8 +1338,15 @@ switch (entry2->propstype) { /* b <---> a */ case GST_PROPS_FOURCC_TYPE: - GST_DEBUG(GST_CAT_PROPERTIES,"\"%4.4s\" <--> \"%4.4s\" ?", - (char*) &entry2->data.fourcc_data, (char*) &entry1->data.fourcc_data); + GST_DEBUG(GST_CAT_PROPERTIES,"\"%c%c%c%c\" <--> \"%c%c%c%c\" ?", + (entry2->data.fourcc_data>>0)&0xff, + (entry2->data.fourcc_data>>8)&0xff, + (entry2->data.fourcc_data>>16)&0xff, + (entry2->data.fourcc_data>>24)&0xff, + (entry1->data.fourcc_data>>0)&0xff, + (entry1->data.fourcc_data>>8)&0xff, + (entry1->data.fourcc_data>>16)&0xff, + (entry1->data.fourcc_data>>24)&0xff); return (entry2->data.fourcc_data == entry1->data.fourcc_data); default: break; @@ -1891,7 +1902,11 @@ g_free(str); break; case GST_PROPS_FOURCC_TYPE: - str = g_strdup_printf ("%4.4s", (gchar *)&entry->data.fourcc_data); + str = g_strdup_printf ("%c%c%c%c", + (entry->data.fourcc_data>>0)&0xff, + (entry->data.fourcc_data>>8)&0xff, + (entry->data.fourcc_data>>16)&0xff, + (entry->data.fourcc_data>>24)&0xff); xmlAddChild (parent, xmlNewComment (str)); g_free(str); subtree = xmlNewChild (parent, NULL, "fourcc", NULL); |
From: David S. <dsc...@us...> - 2002-10-17 00:53:26
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Wed Oct 16 2002 17:53:25 PDT Log message: After the third time of calling GST_PROPS_FLOAT with an integer and wondering why it didn't work, I add an explicit cast. Modified files: gst : gstprops.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstprops.h.diff?r1=1.33&r2=1.34 ====Begin Diffs==== Index: gstprops.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstprops.h,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- gstprops.h 17 Sep 2002 23:46:52 -0000 1.33 +++ gstprops.h 17 Oct 2002 00:53:13 -0000 1.34 @@ -63,8 +63,8 @@ #define GST_PROPS_GLIST(a) GST_PROPS_GLIST_TYPE,(a) #define GST_PROPS_INT(a) GST_PROPS_INT_TYPE,(a) #define GST_PROPS_INT_RANGE(a,b) GST_PROPS_INT_RANGE_TYPE,(a),(b) -#define GST_PROPS_FLOAT(a) GST_PROPS_FLOAT_TYPE,(a) -#define GST_PROPS_FLOAT_RANGE(a,b) GST_PROPS_FLOAT_RANGE_TYPE,(a),(b) +#define GST_PROPS_FLOAT(a) GST_PROPS_FLOAT_TYPE,((float)(a)) +#define GST_PROPS_FLOAT_RANGE(a,b) GST_PROPS_FLOAT_RANGE_TYPE,((float)(a)),((float)(b)) #define GST_PROPS_FOURCC(a) GST_PROPS_FOURCC_TYPE,(a) #define GST_PROPS_BOOLEAN(a) GST_PROPS_BOOL_TYPE,(a) #define GST_PROPS_STRING(a) GST_PROPS_STRING_TYPE,(a) |
From: David S. <dsc...@us...> - 2002-10-17 23:03:14
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Thu Oct 17 2002 16:03:12 PDT Log message: Fix for HPPA asm code Modified files: gst : gstarch.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstarch.h.diff?r1=1.14&r2=1.15 ====Begin Diffs==== Index: gstarch.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstarch.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- gstarch.h 18 Dec 2001 16:50:05 -0000 1.14 +++ gstarch.h 17 Oct 2002 23:02:59 -0000 1.15 @@ -152,7 +152,7 @@ __asm__("copy %0,%%sp\n\t" : : "r"(stackpointer)); #define GST_ARCH_CALL(target) \ - __asm__("copy $1,%%r22\n\t" /* set call address */ \ + __asm__("copy %0,%%r22\n\t" /* set call address */ \ ".CALL\n\t" /* call pseudo insn (why?) */ \ "bl $$dyncall,%%r31\n\t" : : "r"(target)); |
From: David S. <dsc...@us...> - 2002-11-01 21:38:53
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Fri Nov 01 2002 13:38:52 PST Log message: Change from pthreads to GThreads Modified files: gst : cothreads.c gstinfo.c gstqueue.c gstthread.c gstthread.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.82&r2=1.83 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstinfo.c.diff?r1=1.40&r2=1.41 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstqueue.c.diff?r1=1.54&r2=1.55 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstthread.c.diff?r1=1.95&r2=1.96 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstthread.h.diff?r1=1.17&r2=1.18 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.82 retrieving revision 1.83 diff -u -d -r1.82 -r1.83 --- cothreads.c 12 Sep 2002 18:56:30 -0000 1.82 +++ cothreads.c 1 Nov 2002 21:38:39 -0000 1.83 @@ -20,7 +20,8 @@ * Boston, MA 02111-1307, USA. */ -#include <pthread.h> +#include <glib.h> + #include <stdio.h> #include <stdlib.h> #include <signal.h> @@ -59,12 +60,12 @@ }; -/* this _cothread_ctx_key is used as a pthread key to the thread's context - * a pthread key is a "pointer" to memory space that is/can be different +/* 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 * (ie. private) for each thread. The key itself is shared among threads, * so it only needs to be initialized once. */ -static pthread_key_t _cothread_ctx_key = -1; +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 */ @@ -83,7 +84,14 @@ /* * initalize the whole of the cothreads context */ - cothread_context *ctx = (cothread_context *) g_malloc (sizeof (cothread_context)); + cothread_context *ctx; + + /* if there already is a cotread context for this thread, + * just return it */ + ctx = g_private_get (_cothread_ctx_key); + if(ctx) return ctx; + + ctx = (cothread_context *) g_malloc (sizeof (cothread_context)); /* we consider the initiating process to be cothread 0 */ ctx->ncothreads = 1; @@ -92,16 +100,18 @@ GST_INFO (GST_CAT_COTHREADS, "initializing cothreads"); - /* initialize the cothread key (for pthread space) if not done yet */ - if (_cothread_ctx_key == (pthread_key_t) -1) { - if (pthread_key_create (&_cothread_ctx_key, NULL) != 0) { - perror ("pthread_key_create"); + /* initialize the cothread key (for GThread space) if not done yet */ + /* FIXME this should be done in cothread_init() */ + if (_cothread_ctx_key == NULL) { + _cothread_ctx_key = g_private_new (NULL); + if (_cothread_ctx_key == NULL) { + perror ("g_private_new"); return NULL; } } /* set this thread's context pointer */ - pthread_setspecific (_cothread_ctx_key, ctx); + g_private_set (_cothread_ctx_key, ctx); /* clear the cothread data */ @@ -189,6 +199,7 @@ GST_DEBUG (GST_CAT_COTHREADS, "Found free cothread slot %d", slot); sp = CURRENT_STACK_FRAME; +printf("stack pointer %p\n",sp); /* FIXME this may not be 64bit clean * could use casts to uintptr_t from inttypes.h * if only all platforms had inttypes.h @@ -392,14 +403,14 @@ /** * cothread_current_main: * - * Get the main thread in the current pthread. + * Get the main thread in the current GThread. * - * Returns: the #cothread_state of the main (0th) thread in the current pthread + * Returns: the #cothread_state of the main (0th) thread in the current GThread */ cothread_state * cothread_current_main (void) { - cothread_context *ctx = pthread_getspecific (_cothread_ctx_key); + cothread_context *ctx = g_private_get (_cothread_ctx_key); return ctx->cothreads[0]; } @@ -414,7 +425,7 @@ cothread_state * cothread_current (void) { - cothread_context *ctx = pthread_getspecific (_cothread_ctx_key); + cothread_context *ctx = g_private_get (_cothread_ctx_key); return ctx->cothreads[ctx->current]; } @@ -422,7 +433,7 @@ static void cothread_stub (void) { - cothread_context *ctx = pthread_getspecific (_cothread_ctx_key); + cothread_context *ctx = g_private_get (_cothread_ctx_key); register cothread_state *thread = ctx->cothreads[ctx->current]; GST_DEBUG_ENTER (""); @@ -448,7 +459,7 @@ int cothread_getcurrent (void) { - cothread_context *ctx = pthread_getspecific (_cothread_ctx_key); + cothread_context *ctx = g_private_get (_cothread_ctx_key); if (!ctx) return -1; @@ -479,7 +490,7 @@ void cothread_context_set_data (cothread_state *thread, gchar *key, gpointer data) { - cothread_context *ctx = pthread_getspecific (_cothread_ctx_key); + cothread_context *ctx = g_private_get (_cothread_ctx_key); g_hash_table_insert (ctx->data, key, data); } @@ -510,7 +521,7 @@ gpointer cothread_context_get_data (cothread_state * thread, gchar * key) { - cothread_context *ctx = pthread_getspecific (_cothread_ctx_key); + cothread_context *ctx = g_private_get (_cothread_ctx_key); return g_hash_table_lookup (ctx->data, key); } Index: gstinfo.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstinfo.c,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- gstinfo.c 11 Apr 2002 20:35:14 -0000 1.40 +++ gstinfo.c 1 Nov 2002 21:38:39 -0000 1.41 @@ -188,10 +188,10 @@ { gchar *empty = ""; gchar *elementname = empty,*location = empty; - int pthread_id = getpid(); + int pid = getpid(); int cothread_id = 0; /*FIXME*/ #ifdef GST_DEBUG_COLOR - int pthread_color = pthread_id%6 + 31; + int pid_color = pid%6 + 31; int cothread_color = (cothread_id < 0) ? 37 : (cothread_id%6 + 31); #endif @@ -208,11 +208,11 @@ #ifdef GST_DEBUG_COLOR fprintf(stderr,"DEBUG(\033[00;%dm%5d\033[00m:\033[00;%dm%2d\033[00m)\033[" "%s;%sm%s%s\033[00m %s\n", - pthread_color,pthread_id,cothread_color,cothread_id,incore?"00":"01", + pid_color,pid,cothread_color,cothread_id,incore?"00":"01", _gst_category_colors[category],location,elementname,string); #else fprintf(stderr,"DEBUG(%5d:%2d)%s%s %s\n", - pthread_id,cothread_id,location,elementname,string); + pid,cothread_id,location,elementname,string); #endif /* GST_DEBUG_COLOR */ if (location != empty) g_free(location); @@ -300,10 +300,10 @@ { gchar *empty = ""; gchar *elementname = empty,*location = empty; - int pthread_id = getpid(); + int pid = getpid(); int cothread_id = 0; /*FIXME*/ #ifdef GST_DEBUG_COLOR - int pthread_color = pthread_id%6 + 31; + int pid_color = pid%6 + 31; int cothread_color = (cothread_id < 0) ? 37 : (cothread_id%6 + 31); #endif @@ -319,11 +319,11 @@ #ifdef GST_DEBUG_COLOR fprintf(stderr,"\033[01mINFO\033[00m (\033[00;%dm%5d\033[00m:\033[00;%dm%2d\033[00m)\033[" GST_DEBUG_CHAR_MODE ";%sm%s%s\033[00m %s\n", - pthread_color,pthread_id,cothread_color,cothread_id, + pid_color,pid,cothread_color,cothread_id, _gst_category_colors[category],location,elementname,string); #else fprintf(stderr,"INFO (%5d:%2d)%s%s %s\n", - pthread_id,cothread_id,location,elementname,string); + pid,cothread_id,location,elementname,string); #endif /* GST_DEBUG_COLOR */ /* #else Index: gstqueue.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstqueue.c,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- gstqueue.c 25 Oct 2002 19:14:57 -0000 1.54 +++ gstqueue.c 1 Nov 2002 21:38:39 -0000 1.55 @@ -29,7 +29,6 @@ #define STATUS(A) #endif -#include <pthread.h> #include "config.h" #include "gst_private.h" @@ -320,9 +319,9 @@ restart: /* we have to lock the queue since we span threads */ - GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%ld", pthread_self ()); + GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%p", g_thread_self ()); g_mutex_lock (queue->qlock); - GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%ld", pthread_self ()); + GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%p", g_thread_self ()); /* assume don't need to flush this buffer when the queue is filled */ queue->flush = FALSE; @@ -472,9 +471,9 @@ restart: /* have to lock for thread-safety */ - GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%ld", pthread_self ()); + GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locking t:%p", g_thread_self ()); g_mutex_lock (queue->qlock); - GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%ld %p", pthread_self (), queue->not_empty); + GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "locked t:%p %p", g_thread_self (), queue->not_empty); GST_DEBUG_ELEMENT (GST_CAT_DATAFLOW, queue, "pre empty wait, level:%d/%d", queue->level_buffers, queue->size_buffers); while (queue->level_buffers == 0) { Index: gstthread.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstthread.c,v retrieving revision 1.95 retrieving revision 1.96 diff -u -d -r1.95 -r1.96 --- gstthread.c 29 Sep 2002 18:12:50 -0000 1.95 +++ gstthread.c 1 Nov 2002 21:38:39 -0000 1.96 @@ -30,6 +30,10 @@ #include "gstscheduler.h" #include "gstqueue.h" +#define STACK_SIZE 0x200000 + +#define g_thread_equal(a,b) ((a) == (b)) + GstElementDetails gst_thread_details = { "Threaded container", "Generic/Bin", @@ -84,9 +88,10 @@ gst_thread_schedpolicy_get_type(void) { static GType thread_schedpolicy_type = 0; static GEnumValue thread_schedpolicy[] = { - {SCHED_OTHER, "SCHED_OTHER", "Normal Scheduling"}, - {SCHED_FIFO, "SCHED_FIFO", "FIFO Scheduling (requires root)"}, - {SCHED_RR, "SCHED_RR", "Round-Robin Scheduling (requires root)"}, + {G_THREAD_PRIORITY_LOW, "LOW", "Low Priority Scheduling"}, + {G_THREAD_PRIORITY_NORMAL, "NORMAL", "Normal Scheduling"}, + {G_THREAD_PRIORITY_HIGH, "HIGH", "High Priority Scheduling"}, + {G_THREAD_PRIORITY_URGENT, "URGENT", "Urgent Scheduling"}, {0, NULL, NULL}, }; if (!thread_schedpolicy_type) { @@ -137,7 +142,7 @@ g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_SCHEDPOLICY, g_param_spec_enum("schedpolicy", "Scheduling Policy", "The scheduling policy of the thread", - GST_TYPE_THREAD_SCHEDPOLICY, SCHED_OTHER, G_PARAM_READWRITE)); + GST_TYPE_THREAD_SCHEDPOLICY, G_THREAD_PRIORITY_NORMAL, G_PARAM_READWRITE)); g_object_class_install_property(G_OBJECT_CLASS (klass), ARG_PRIORITY, g_param_spec_int("priority", "Scheduling Priority", "The scheduling priority of the thread", 0, 99, 0, G_PARAM_READWRITE)); @@ -179,8 +184,8 @@ thread->cond = g_cond_new (); thread->ppid = getpid (); - thread->thread_id = (pthread_t) -1; - thread->sched_policy = SCHED_OTHER; + thread->thread_id = (GThread *) NULL; + thread->sched_policy = G_THREAD_PRIORITY_NORMAL; thread->priority = 0; thread->stack = NULL; } @@ -309,8 +314,8 @@ GstThread *thread; gboolean stateset = GST_STATE_SUCCESS; gint transition; - pthread_t self = pthread_self (); - glong stacksize; + GThread * self = g_thread_self (); + GError * error = NULL; g_return_val_if_fail (GST_IS_THREAD (element), GST_STATE_FAILURE); g_return_val_if_fail (gst_has_threads (), GST_STATE_FAILURE); @@ -323,7 +328,7 @@ gst_element_state_get_name (GST_STATE (element)), gst_element_state_get_name (GST_STATE_PENDING (element))); - if (pthread_equal (self, thread->thread_id)) { + if (g_thread_equal (self, thread->thread_id)) { GST_DEBUG (GST_CAT_THREAD, "no sync(" GST_DEBUG_THREAD_FORMAT "): setting own thread's state to spinning", GST_DEBUG_THREAD_ARGS (thread->pid)); @@ -337,70 +342,29 @@ THR_DEBUG ("creating thread \"%s\"", GST_ELEMENT_NAME (element)); - /* this bit of code handles creation of pthreads + /* this bit of code handles creation of GThreads * this is therefor tricky code * compare it with the block of code that handles the destruction * in GST_STATE_READY_TO_NULL below */ g_mutex_lock (thread->lock); - /* create attribute struct for pthread - * and assign stack pointer and size to it - * - * the default state of a pthread is PTHREAD_CREATE_JOINABLE - * (see man pthread_attr_init) - * - other thread can sync on termination - * - thread resources are kept allocated until other thread performs - * pthread_join - */ - - if (pthread_attr_init (&thread->attr) != 0) - g_warning ("pthread_attr_init returned an error !"); - - /* this function should return a newly allocated stack - * (using whatever method) - * which we can initiate the pthreads with - * the stack should be freed in - */ - if (gst_scheduler_get_preferred_stack (GST_ELEMENT_SCHED (element), - &thread->stack, &stacksize)) { -#ifdef HAVE_PTHREAD_ATTR_SETSTACK - if (pthread_attr_setstack (&thread->attr, - thread->stack, stacksize) != 0) { - g_warning ("pthread_attr_setstack failed\n"); - return GST_STATE_FAILURE; - } -#else - if (pthread_attr_setstackaddr (&thread->attr, thread->stack) != 0) { - g_warning ("pthread_attr_setstackaddr failed\n"); - return GST_STATE_FAILURE; - } - if (pthread_attr_setstacksize (&thread->attr, stacksize) != 0) { - g_warning ("pthread_attr_setstacksize failed\n"); - return GST_STATE_FAILURE; - } -#endif - GST_DEBUG (GST_CAT_THREAD, "pthread attr set stack at %p of size %ld", - thread->stack, stacksize); - } - else { - g_warning ("scheduler did not return a preferred stack"); - } - - /* create a new pthread + /* create a new GThread * use the specified attributes * make it execute gst_thread_main_loop (thread) */ - GST_DEBUG (GST_CAT_THREAD, "going to pthread_create..."); - if (pthread_create (&thread->thread_id, &thread->attr, - gst_thread_main_loop, thread) != 0) { - GST_DEBUG (GST_CAT_THREAD, "pthread_create failed"); + GST_DEBUG (GST_CAT_THREAD, "going to g_thread_create_full..."); + thread->thread_id = g_thread_create_full(gst_thread_main_loop, + thread, STACK_SIZE, TRUE, TRUE, G_THREAD_PRIORITY_NORMAL, + &error); + if (!thread->thread_id){ + GST_DEBUG (GST_CAT_THREAD, "g_thread_create_full failed"); g_mutex_unlock (thread->lock); GST_DEBUG (GST_CAT_THREAD, "could not create thread \"%s\"", GST_ELEMENT_NAME (element)); return GST_STATE_FAILURE; } - GST_DEBUG (GST_CAT_THREAD, "pthread created"); + GST_DEBUG (GST_CAT_THREAD, "GThread created"); /* wait for it to 'spin up' */ THR_DEBUG ("waiting for child thread spinup"); @@ -530,17 +494,10 @@ * compare this block to the block */ - - /* in glibc 2.2.5, pthread_attr_destroy does nothing more - * than return 0 */ - if (pthread_attr_destroy (&thread->attr) != 0) - g_warning ("pthread_attr_destroy has failed !"); - - GST_DEBUG (GST_CAT_THREAD, "joining pthread %ld", thread->thread_id); - if (pthread_join (thread->thread_id, NULL) != 0) - g_warning ("pthread_join has failed !\n"); + GST_DEBUG (GST_CAT_THREAD, "joining GThread %p", thread->thread_id); + g_thread_join (thread->thread_id); - thread->thread_id = -1; + thread->thread_id = NULL; /* the stack was allocated when we created the thread * using scheduler->get_preferred_stack */ @@ -590,32 +547,35 @@ { GstThread *thread = NULL; gint stateset; + glong page_size; + gpointer stack_pointer; + gulong stack_offset; GST_DEBUG (GST_CAT_THREAD, "gst_thread_main_loop started"); thread = GST_THREAD (arg); g_mutex_lock (thread->lock); - /* handle scheduler policy; do stuff if not the normal scheduler */ - if (thread->sched_policy != SCHED_OTHER) { - struct sched_param sched_param; - - memset (&sched_param, 0, sizeof (sched_param)); - if (thread->priority == 0) { - thread->priority = sched_get_priority_max (thread->sched_policy); - } - sched_param.sched_priority = thread->priority; - - if (sched_setscheduler (0, thread->sched_policy, &sched_param) != 0) { - GST_DEBUG (GST_CAT_THREAD, "not running with real-time priority"); - } - } - /* set up the element's scheduler */ gst_scheduler_setup (GST_ELEMENT_SCHED (thread)); GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING); thread->pid = getpid(); THR_INFO_MAIN ("thread is running"); + + page_size = sysconf(_SC_PAGESIZE); + stack_pointer = (gpointer) &stack_pointer; + + if(((gulong)stack_pointer & (page_size-1)) < (page_size>>1)){ + /* stack grows up, I think */ + /* FIXME this is probably not true for the main thread */ + stack_offset = (gulong)stack_pointer & (page_size - 1); + }else{ + /* stack grows down, I think */ + stack_offset = STACK_SIZE - ((gulong)stack_pointer & (page_size - 1)); + } + /* note the subtlety with pointer arithmetic */ + thread->stack = stack_pointer - stack_offset; + thread->stack_size = STACK_SIZE; /* first we need to change the state of all the children */ if (GST_ELEMENT_CLASS (parent_class)->change_state) { Index: gstthread.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstthread.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- gstthread.h 9 Jul 2002 10:27:21 -0000 1.17 +++ gstthread.h 1 Nov 2002 21:38:39 -0000 1.18 @@ -24,8 +24,7 @@ #ifndef __GST_THREAD_H__ #define __GST_THREAD_H__ -#include <unistd.h> -#include <pthread.h> +#include <glib.h> #include <gst/gstbin.h> @@ -62,11 +61,11 @@ struct _GstThread { GstBin bin; - pthread_t thread_id; /* id of the thread, if any */ - pthread_attr_t attr; /* attributes for the stack space */ + GThread *thread_id; /* id of the thread, if any */ int sched_policy; int priority; - void *stack; /* set with gst_scheduler_get_preferred_stack */ + gpointer *stack; /* set with gst_scheduler_get_preferred_stack */ + guint stack_size; /* stack size */ gint pid; /* the pid of the thread */ gint ppid; /* the pid of the thread's parent process */ GMutex *lock; /* thread lock/condititon pair ... */ |
From: David S. <dsc...@us...> - 2002-11-02 00:41:26
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Fri Nov 01 2002 16:41:24 PST Log message: remove debugging message Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.83&r2=1.84 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.83 retrieving revision 1.84 diff -u -d -r1.83 -r1.84 --- cothreads.c 1 Nov 2002 21:38:39 -0000 1.83 +++ cothreads.c 2 Nov 2002 00:41:11 -0000 1.84 @@ -199,7 +199,6 @@ GST_DEBUG (GST_CAT_COTHREADS, "Found free cothread slot %d", slot); sp = CURRENT_STACK_FRAME; -printf("stack pointer %p\n",sp); /* FIXME this may not be 64bit clean * could use casts to uintptr_t from inttypes.h * if only all platforms had inttypes.h |
From: David S. <dsc...@us...> - 2002-11-14 11:15:05
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Thu Nov 14 2002 03:15:04 PST Log message: Fix up allocation of stack space for a cothread. Previous code did not allow for the underlying threading model to insert an unmapped guard page. Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.85&r2=1.86 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.85 retrieving revision 1.86 diff -u -d -r1.85 -r1.86 --- cothreads.c 2 Nov 2002 13:15:10 -0000 1.85 +++ cothreads.c 14 Nov 2002 11:14:52 -0000 1.86 @@ -175,8 +175,7 @@ { cothread_state *cothread; void *sp; - void *mmaped = 0; - guchar *stack_end; + unsigned long stack_top; gint slot = 0; g_return_val_if_fail (ctx != NULL, NULL); @@ -204,32 +203,16 @@ * could use casts to uintptr_t from inttypes.h * if only all platforms had inttypes.h */ - /* FIXME: a little explanation on what this REALLY means would be nice ;) */ - stack_end = (guchar *) ((gulong) sp & ~(STACK_SIZE - 1)); + /* stack_top is the address of th first byte past our stack segment. */ + /* FIXME: an assumption is made that the stack segment is STACK_SIZE + * aligned. */ + stack_top = ((gulong) sp | (STACK_SIZE - 1)) + 1; + GST_DEBUG(GST_CAT_COTHREADS, "stack top is %lu", stack_top); /* cothread stack space of the thread is mapped in reverse, with cothread 0 * stack space at the top */ - cothread = (cothread_state *) (stack_end + ((slot - 1) * COTHREAD_STACKSIZE)); - GST_DEBUG (GST_CAT_COTHREADS, - "mmap cothread slot stack from %p to %p (size 0x%lx)", - cothread, cothread + COTHREAD_STACKSIZE, - (long) COTHREAD_STACKSIZE); - - GST_DEBUG (GST_CAT_COTHREADS, "going into mmap"); - /* the mmap is used to reserve part of the stack - * ie. we state explicitly that we are going to use it */ - mmaped = mmap ((void *) cothread, COTHREAD_STACKSIZE, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - GST_DEBUG (GST_CAT_COTHREADS, "coming out of mmap"); - if (mmaped == MAP_FAILED) { - perror ("mmap'ing cothread stack space"); - return NULL; - } - if (mmaped != cothread) { - g_warning ("could not mmap requested memory for cothread"); - return NULL; - } + cothread = (cothread_state *) (stack_top - (slot + 1) * COTHREAD_STACKSIZE); + GST_DEBUG(GST_CAT_COTHREADS, "cothread pointer is %p", cothread); cothread->magic_number = COTHREAD_MAGIC_NUMBER; GST_DEBUG (GST_CAT_COTHREADS, "create cothread %d with magic number 0x%x", |
From: David S. <dsc...@us...> - 2002-11-15 09:52:26
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Fri Nov 15 2002 01:51:53 PST Log message: Move stack_top code from cothread_create() to cothread_context_init(), since we only need to calculate it once. Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.87&r2=1.88 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.87 retrieving revision 1.88 diff -u -d -r1.87 -r1.88 --- cothreads.c 14 Nov 2002 13:35:13 -0000 1.87 +++ cothreads.c 15 Nov 2002 09:51:41 -0000 1.88 @@ -56,6 +56,7 @@ cothread_state *cothreads[COTHREAD_MAXTHREADS]; /* array of cothread states */ int ncothreads; int current; + unsigned long stack_top; GHashTable *data; }; @@ -82,6 +83,7 @@ cothread_context_init (void) { cothread_context *ctx; + void *sp; /* if there already is a cotread context for this thread, * just return it */ @@ -118,6 +120,17 @@ memset (ctx->cothreads, 0, sizeof (ctx->cothreads)); + sp = CURRENT_STACK_FRAME; + /* FIXME this may not be 64bit clean + * could use casts to uintptr_t from inttypes.h + * if only all platforms had inttypes.h + */ + /* stack_top is the address of the first byte past our stack segment. */ + /* FIXME: an assumption is made that the stack segment is STACK_SIZE + * aligned. */ + ctx->stack_top = ((gulong) sp | (STACK_SIZE - 1)) + 1; + GST_DEBUG (GST_CAT_COTHREADS, "stack top is %lu", ctx->stack_top); + /* * initialize the 0th cothread */ @@ -174,8 +187,8 @@ cothread_create (cothread_context *ctx) { cothread_state *cothread; - void *sp; - unsigned long stack_top; + //void *sp; + //unsigned long stack_top; void *mmaped = 0; gint slot = 0; @@ -200,6 +213,7 @@ GST_DEBUG (GST_CAT_COTHREADS, "Found free cothread slot %d", slot); +#if 0 sp = CURRENT_STACK_FRAME; /* FIXME this may not be 64bit clean * could use casts to uintptr_t from inttypes.h @@ -210,10 +224,11 @@ * aligned. */ stack_top = ((gulong) sp | (STACK_SIZE - 1)) + 1; GST_DEBUG (GST_CAT_COTHREADS, "stack top is %lu", stack_top); +#endif /* cothread stack space of the thread is mapped in reverse, with cothread 0 * stack space at the top */ - cothread = (cothread_state *) (stack_top - (slot + 1) * COTHREAD_STACKSIZE); + cothread = (cothread_state *) (ctx->stack_top - (slot + 1) * COTHREAD_STACKSIZE); GST_DEBUG (GST_CAT_COTHREADS, "mmap cothread slot stack from %p to 0x%lx (size 0x%lx)", |
From: David S. <dsc...@us...> - 2002-11-19 02:26:07
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Nov 18 2002 18:26:05 PST Log message: Cleaned up cothread_create(), added comments, added code to unmap a guard page. Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.89&r2=1.90 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.89 retrieving revision 1.90 diff -u -d -r1.89 -r1.90 --- cothreads.c 18 Nov 2002 22:44:47 -0000 1.89 +++ cothreads.c 19 Nov 2002 02:25:52 -0000 1.90 @@ -133,7 +133,7 @@ /* FIXME: an assumption is made that the stack segment is STACK_SIZE * aligned. */ ctx->stack_top = ((gulong) sp | (STACK_SIZE - 1)) + 1; - GST_DEBUG (GST_CAT_COTHREADS, "stack top is %lu", ctx->stack_top); + GST_DEBUG (GST_CAT_COTHREADS, "stack top is 0x%08lx", ctx->stack_top); /* * initialize the 0th cothread @@ -193,11 +193,9 @@ cothread_create (cothread_context *ctx) { cothread_state *cothread; - //void *sp; - //unsigned long stack_top; void *mmaped = 0; - gint slot = 0; + unsigned long page_size; g_return_val_if_fail (ctx != NULL, NULL); @@ -219,35 +217,28 @@ GST_DEBUG (GST_CAT_COTHREADS, "Found free cothread slot %d", slot); -#if 0 - sp = CURRENT_STACK_FRAME; - /* FIXME this may not be 64bit clean - * could use casts to uintptr_t from inttypes.h - * if only all platforms had inttypes.h - */ - /* stack_top is the address of the first byte past our stack segment. */ - /* FIXME: an assumption is made that the stack segment is STACK_SIZE - * aligned. */ - stack_top = ((gulong) sp | (STACK_SIZE - 1)) + 1; - GST_DEBUG (GST_CAT_COTHREADS, "stack top is 0x%lx", stack_top); -#endif - /* cothread stack space of the thread is mapped in reverse, with cothread 0 * stack space at the top */ cothread = (cothread_state *) (ctx->stack_top - (slot + 1) * COTHREAD_STACKSIZE); + GST_DEBUG (GST_CAT_COTHREADS, "cothread pointer is %p", cothread); - GST_DEBUG (GST_CAT_COTHREADS, - "mmap cothread slot stack from %p to 0x%lx (size 0x%lx)", - cothread, (unsigned long) cothread + COTHREAD_STACKSIZE, - (long) COTHREAD_STACKSIZE); +#if 0 + /* This tests to see whether or not we can grow down the stack */ + { + unsigned long ptr; + for(ptr=ctx->stack_top - 4096; ptr > (unsigned long)cothread; ptr -= 4096){ + GST_DEBUG (GST_CAT_COTHREADS, "touching location 0x%08lx", ptr); + *(volatile unsigned int *)ptr = *(volatile unsigned int *)ptr; + GST_DEBUG (GST_CAT_COTHREADS, "ok (0x%08x)", *(unsigned int *)ptr); + } + } +#endif - GST_DEBUG (GST_CAT_COTHREADS, "going into mmap"); - /* the mmap is used to reserve part of the stack - * ie. we state explicitly that we are going to use it */ - /* FIXME: maybe we should map slightly less than COTHREAD_STACKSIZE, - * so that stack overruns possibly could segfault ? */ - mmaped = mmap ((void *) (cothread), - COTHREAD_STACKSIZE, + /* The mmap is necessary on Linux/i386, and possibly others, since the + * kernel is picky about when we can expand our stack. */ + GST_DEBUG (GST_CAT_COTHREADS, "mmaping %p, size 0x%08x", cothread, + COTHREAD_STACKSIZE); + mmaped = mmap ((void *) cothread, COTHREAD_STACKSIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); GST_DEBUG (GST_CAT_COTHREADS, "coming out of mmap"); @@ -260,6 +251,16 @@ return NULL; } +#ifdef _SC_PAGESIZE + page_size = sysconf(_SC_PAGESIZE); +#else + page_size = getpagesize(); +#endif + /* Unmap a guard page. This decreases our stack size by 8 kB (for + * 4 kB pages) and also wastes almost 4 kB for the cothreads + * structure */ + munmap((void *)cothread + page_size, page_size); + cothread->magic_number = COTHREAD_MAGIC_NUMBER; GST_DEBUG (GST_CAT_COTHREADS, "create cothread %d with magic number 0x%x", slot, cothread->magic_number); @@ -268,6 +269,7 @@ cothread->flags = 0; cothread->priv = NULL; cothread->sp = ((guchar *) cothread + COTHREAD_STACKSIZE); + cothread->sp -= 16; /* necessary for PowerPC */ cothread->top_sp = cothread->sp; /* for debugging purposes to detect stack overruns */ |
From: David S. <dsc...@us...> - 2002-11-19 02:28:22
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Nov 18 2002 18:28:21 PST Log message: Added atomic code for PowerPC Modified files: gst : gstatomic.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstatomic.h.diff?r1=1.4&r2=1.5 ====Begin Diffs==== Index: gstatomic.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstatomic.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- gstatomic.h 5 Sep 2002 22:21:45 -0000 1.4 +++ gstatomic.h 19 Nov 2002 02:28:09 -0000 1.5 @@ -163,6 +163,42 @@ : "ecx", "ebx"); \ } G_STMT_END +#elif defined (__powerpc__) && defined (__GNUC__) && __GNUC__ >= 2 + +#define _GST_ATOMIC_SWAP_INIT(swap,val) \ +G_STMT_START { \ + (swap)->value = (gpointer)(val); \ + (swap)->cnt = 0; \ +} G_STMT_END + +#define _GST_ATOMIC_SWAP(swap, val) \ +G_STMT_START { \ + __asm__ __volatile__ ("1:" \ + " lwarx %0, 0, %2 \n" \ + " stwcx. %3, 0, %2 \n" \ + " bne- 1b \n" \ + : "=&r", \ + "=m" (*swap) \ + : "r" (swap), \ + "r" (val), \ + "m" (*swap) \ + : "cc", "memory"); \ +} G_STMT_END + +#define _GST_ATOMIC_SWAP_GET(swap, val, res) \ +G_STMT_START { \ + __asm__ __volatile__ ("1:" \ + " lwarx %0, 0, %2 \n" \ + " stwcx. %3, 0, %2 \n" \ + " bne- 1b \n" \ + : "=&r" (*(res)), \ + "=m" (*swap) \ + : "r" (swap), \ + "r" (val), \ + "m" (*swap) \ + : "cc", "memory"); \ +} G_STMT_END + #else #define _GST_ATOMIC_SWAP_INIT(swap,val) \ |
From: David S. <dsc...@us...> - 2002-11-19 02:29:30
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Nov 18 2002 18:29:30 PST Log message: Added gst_data_needs_copy_on_write() Modified files: gst : gstdata.c gstdata.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstdata.c.diff?r1=1.6&r2=1.7 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstdata.h.diff?r1=1.6&r2=1.7 ====Begin Diffs==== Index: gstdata.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstdata.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- gstdata.c 15 Sep 2002 13:45:26 -0000 1.6 +++ gstdata.c 19 Nov 2002 02:29:18 -0000 1.7 @@ -93,6 +93,26 @@ } /** + * gst_data_needs_copy_on_write: + * @data: a #GstData to copy + * + * Returns: TRUE if the given #GstData is potentially shared and needs to + * be copied before it can be modified safely. + */ +gboolean +gst_data_needs_copy_on_write (GstData *data) +{ + gint refcount; + + GST_ATOMIC_INT_READ (&data->refcount, &refcount); + + if (refcount == 1 && !GST_DATA_FLAG_IS_SET (data, GST_DATA_READONLY)) + return FALSE; + + return TRUE; +} + +/** * gst_data_copy_on_write: * @data: a #GstData to copy * Index: gstdata.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstdata.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- gstdata.h 24 Oct 2002 09:00:12 -0000 1.6 +++ gstdata.h 19 Nov 2002 02:29:18 -0000 1.7 @@ -87,6 +87,7 @@ /* basic operations on data */ GstData* gst_data_copy (const GstData *data); +gboolean gst_data_needs_copy_on_write (GstData *data); GstData* gst_data_copy_on_write (GstData *data); void gst_data_free (GstData *data); |
From: David S. <dsc...@us...> - 2002-11-19 02:30:58
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Nov 18 2002 18:30:58 PST Log message: Added gst_buffer[_pool]_needs_copy_on_write() Modified files: gst : gstbuffer.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstbuffer.h.diff?r1=1.47&r2=1.48 ====Begin Diffs==== Index: gstbuffer.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstbuffer.h,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- gstbuffer.h 2 Nov 2002 13:15:55 -0000 1.47 +++ gstbuffer.h 19 Nov 2002 02:30:45 -0000 1.48 @@ -135,6 +135,7 @@ #define gst_buffer_unref(buf) gst_data_unref (GST_DATA (buf)) /* copy buffer */ #define gst_buffer_copy(buf) GST_BUFFER (gst_data_copy (GST_DATA (buf))) +#define gst_buffer_needs_copy_on_write(buf) GST_BUFFER (gst_data_needs_copy_on_write (GST_DATA (buf))) #define gst_buffer_copy_on_write(buf) GST_BUFFER (gst_data_copy_on_write (GST_DATA (buf))) #define gst_buffer_free(buf) gst_data_free (GST_DATA (buf)) @@ -167,6 +168,7 @@ /* bufferpool operations */ #define gst_buffer_pool_copy(pool) GST_BUFFER_POOL (gst_data_copy (GST_DATA (pool))) +#define gst_buffer_pool_needs_copy_on_write(pool) GST_BUFFER_POOL (gst_data_needs_copy_on_write (GST_DATA (pool))) #define gst_buffer_pool_copy_on_write(pool) GST_BUFFER_POOL (gst_data_copy_on_write (GST_DATA (pool))) #define gst_buffer_pool_free(pool) gst_data_free (GST_DATA (pool)) |
From: David S. <dsc...@us...> - 2002-11-21 00:54:45
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Wed Nov 20 2002 16:54:44 PST Log message: Add assertion to make sure that we're in the thread containing the cothread we're trying to switch to. Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.90&r2=1.91 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.90 retrieving revision 1.91 diff -u -d -r1.90 -r1.91 --- cothreads.c 19 Nov 2002 02:25:52 -0000 1.90 +++ cothreads.c 21 Nov 2002 00:54:32 -0000 1.91 @@ -110,10 +110,7 @@ /* FIXME this should be done in cothread_init() */ if (_cothread_ctx_key == NULL) { _cothread_ctx_key = g_private_new (NULL); - if (_cothread_ctx_key == NULL) { - perror ("g_private_new"); - return NULL; - } + g_assert (_cothread_ctx_key); } /* set this thread's context pointer */ @@ -147,6 +144,7 @@ ctx->cothreads[0]->priv = NULL; ctx->cothreads[0]->flags = COTHREAD_STARTED; ctx->cothreads[0]->sp = (void *) CURRENT_STACK_FRAME; + ctx->cothreads[0]->top_sp = ctx->cothreads[0]->sp; ctx->cothreads[0]->pc = 0; GST_INFO (GST_CAT_COTHREADS, "0th cothread is %p at sp:%p", @@ -619,6 +617,7 @@ cothread_switch (cothread_state * thread) { cothread_context *ctx; + cothread_context *current_ctx; cothread_state *current; int enter; @@ -627,6 +626,11 @@ goto nothread; #endif ctx = thread->ctx; + + /* paranoia check to make sure we're in the right thread */ + current_ctx = g_private_get(_cothread_ctx_key); + g_assert (ctx == current_ctx); + #ifdef COTHREAD_PARANOID if (ctx == NULL) goto nocontext; |
From: David S. <dsc...@us...> - 2002-12-02 19:10:02
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Dec 02 2002 11:10:00 PST Log message: Patch from Gerhard Tonn <Ger...@ga...> for s390 Modified files: gst : gstarch.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstarch.h.diff?r1=1.15&r2=1.16 ====Begin Diffs==== Index: gstarch.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstarch.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- gstarch.h 17 Oct 2002 23:02:59 -0000 1.15 +++ gstarch.h 2 Dec 2002 19:09:47 -0000 1.16 @@ -159,6 +159,25 @@ /* assume stackframe is 16 bytes */ #define GST_ARCH_SETUP_STACK(sp) sp -= 4 +/***** S/390 *****/ +#elif defined(HAVE_CPU_S390) + +#define GST_ARCH_SET_SP(stackpointer) \ + __asm__("lr 15,%0" : : "r"(stackpointer)) + +#define GST_ARCH_CALL(target) \ + __asm__( "basr 14,%0" : : "a"(target) ); + +struct minimal_s390_stackframe { + unsigned long back_chain; + unsigned long reserved; + unsigned long greg[14]; + double freg[4]; +}; + +#define GST_ARCH_SETUP_STACK(sp) \ + sp = ((unsigned long *)(sp)) - 24; \ + ((struct minimal_s390_stackframe *)sp)->back_chain = 0; #else |
From: David S. <dsc...@us...> - 2002-12-03 21:03:10
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Tue Dec 03 2002 13:03:09 PST Log message: Add assertion in cothread_get_context() Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.93&r2=1.94 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.93 retrieving revision 1.94 diff -u -d -r1.93 -r1.94 --- cothreads.c 29 Nov 2002 18:10:21 -0000 1.93 +++ cothreads.c 3 Dec 2002 21:02:55 -0000 1.94 @@ -58,8 +58,13 @@ 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 @@ -68,9 +73,23 @@ */ 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: @@ -103,6 +122,7 @@ 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"); @@ -443,7 +463,7 @@ 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]; } @@ -458,7 +478,7 @@ 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]; } @@ -466,7 +486,7 @@ 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 (""); @@ -493,7 +513,7 @@ int cothread_getcurrent (void) { - cothread_context *ctx = g_private_get (_cothread_ctx_key); + cothread_context *ctx = cothread_get_current_context(); if (!ctx) return -1; @@ -524,7 +544,7 @@ 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); } @@ -555,7 +575,7 @@ 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); } @@ -632,7 +652,7 @@ 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 |
From: David S. <dsc...@us...> - 2002-12-03 22:45:04
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Tue Dec 03 2002 14:45:02 PST Log message: Change GPrivate usage to GStaticPrivate, assuming it's more trustworthy Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.94&r2=1.95 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.94 retrieving revision 1.95 diff -u -d -r1.94 -r1.95 --- cothreads.c 3 Dec 2002 21:02:55 -0000 1.94 +++ cothreads.c 3 Dec 2002 22:44:49 -0000 1.95 @@ -71,7 +71,7 @@ * (ie. private) for each thread. The key itself is shared among threads, * so it only needs to be initialized once. */ -static GPrivate *_cothread_ctx_key; +static GStaticPrivate _cothread_ctx_key = G_STATIC_PRIVATE_INIT; /* * This should only after context init, since we do checking. @@ -81,7 +81,7 @@ { cothread_context *ctx; - ctx = g_private_get (_cothread_ctx_key); + ctx = g_static_private_get (&_cothread_ctx_key); g_assert(ctx); #ifdef COTHREAD_PARANOID @@ -106,7 +106,7 @@ /* if there already is a cotread context for this thread, * just return it */ - ctx = g_private_get (_cothread_ctx_key); + ctx = g_static_private_get (&_cothread_ctx_key); if (ctx) { GST_INFO (GST_CAT_COTHREADS, "returning private _cothread_ctx_key %p", ctx); @@ -126,17 +126,19 @@ GST_INFO (GST_CAT_COTHREADS, "initializing cothreads"); +#if 0 /* initialize the cothread key (for GThread space) if not done yet */ /* FIXME this should be done in cothread_init() */ if (_cothread_ctx_key == NULL) { _cothread_ctx_key = g_private_new (NULL); g_assert (_cothread_ctx_key); } +#endif /* set this thread's context pointer */ GST_INFO (GST_CAT_COTHREADS, "setting private _cothread_ctx_key to %p", ctx); - g_private_set (_cothread_ctx_key, ctx); + g_static_private_set (&_cothread_ctx_key, ctx, NULL); /* clear the cothread data */ memset (ctx->cothreads, 0, sizeof (ctx->cothreads)); @@ -195,7 +197,7 @@ } g_hash_table_destroy (ctx->data); /* make sure we free the private key for cothread context */ - g_private_set (_cothread_ctx_key, NULL); + g_static_private_set (&_cothread_ctx_key, NULL, NULL); g_free (ctx); } |
From: David S. <dsc...@us...> - 2002-12-04 00:07:26
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Tue Dec 03 2002 16:07:25 PST Log message: Add some assertions to check that we're running inside the correct thread when playing with that thread's cothreads Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.95&r2=1.96 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.95 retrieving revision 1.96 diff -u -d -r1.95 -r1.96 --- cothreads.c 3 Dec 2002 22:44:49 -0000 1.95 +++ cothreads.c 4 Dec 2002 00:07:13 -0000 1.96 @@ -58,7 +58,7 @@ int current; unsigned long stack_top; GHashTable *data; - int pid; + GThread *thread; }; /* Disabling this define allows you to shut off a few checks in @@ -85,7 +85,7 @@ g_assert(ctx); #ifdef COTHREAD_PARANOID - g_assert (ctx->pid == getpid()); + g_assert (ctx->thread == g_thread_self()); #endif return ctx; @@ -122,7 +122,7 @@ ctx->ncothreads = 1; ctx->current = 0; 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"); @@ -187,6 +187,7 @@ gint i; g_return_if_fail (ctx != NULL); + g_assert (ctx->thread == g_thread_self()); GST_INFO (GST_CAT_COTHREADS, "free cothread context"); @@ -218,6 +219,7 @@ unsigned long page_size; g_return_val_if_fail (ctx != NULL, NULL); + g_assert (ctx->thread == g_thread_self()); if (ctx->ncothreads == COTHREAD_MAXTHREADS) { /* this is pretty fatal */ @@ -334,6 +336,7 @@ cothreadnum = cothread->cothreadnum; ctx = cothread->ctx; + g_assert (ctx->thread == g_thread_self()); GST_INFO (GST_CAT_COTHREADS, "destroy cothread %d %p %d", cothreadnum, cothread, ctx->current); @@ -643,7 +646,6 @@ cothread_switch (cothread_state * thread) { cothread_context *ctx; - cothread_context *current_ctx; cothread_state *current; int enter; @@ -654,8 +656,7 @@ ctx = thread->ctx; /* paranoia check to make sure we're in the right thread */ - current_ctx = cothread_get_current_context(); - g_assert (ctx == current_ctx); + g_assert (ctx->thread == g_thread_self()); #ifdef COTHREAD_PARANOID if (ctx == NULL) |
From: David S. <dsc...@us...> - 2002-12-05 01:50:44
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Wed Dec 04 2002 17:50:43 PST Log message: refactor cothread stack mmap code. Add makecontext() as an option for initial stack preparation. Modified files: gst : cothreads.c cothreads.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.96&r2=1.97 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.h.diff?r1=1.26&r2=1.27 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.96 retrieving revision 1.97 diff -u -d -r1.96 -r1.97 --- cothreads.c 4 Dec 2002 00:07:13 -0000 1.96 +++ cothreads.c 5 Dec 2002 01:50:30 -0000 1.97 @@ -166,8 +166,6 @@ ctx->cothreads[0]->priv = NULL; ctx->cothreads[0]->flags = COTHREAD_STARTED; ctx->cothreads[0]->sp = (void *) CURRENT_STACK_FRAME; - ctx->cothreads[0]->top_sp = ctx->cothreads[0]->sp; - ctx->cothreads[0]->pc = 0; GST_INFO (GST_CAT_COTHREADS, "0th cothread is %p at sp:%p", ctx->cothreads[0], ctx->cothreads[0]->sp); @@ -256,11 +254,25 @@ } #endif +#ifdef _SC_PAGESIZE + page_size = sysconf(_SC_PAGESIZE); +#else + page_size = getpagesize(); +#endif + /* The mmap is necessary on Linux/i386, and possibly others, since the * kernel is picky about when we can expand our stack. */ GST_DEBUG (GST_CAT_COTHREADS, "mmaping %p, size 0x%08x", cothread, COTHREAD_STACKSIZE); - mmaped = mmap ((void *) cothread, COTHREAD_STACKSIZE, + /* Remap with a guard page. This decreases our stack size by 8 kB (for + * 4 kB pages) and also wastes almost 4 kB for the cothreads + * structure */ + munmap((void *)cothread, COTHREAD_STACKSIZE); + mmaped = mmap ((void *) cothread, page_size, + PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + mmaped = mmap (((void *) cothread) + page_size * 2, + COTHREAD_STACKSIZE - page_size * 2, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); GST_DEBUG (GST_CAT_COTHREADS, "coming out of mmap"); @@ -268,21 +280,11 @@ perror ("mmap'ing cothread stack space"); return NULL; } - if (mmaped != cothread) { + if (mmaped != (void *)cothread + page_size * 2) { g_warning ("could not mmap requested memory for cothread"); return NULL; } -#ifdef _SC_PAGESIZE - page_size = sysconf(_SC_PAGESIZE); -#else - page_size = getpagesize(); -#endif - /* Unmap a guard page. This decreases our stack size by 8 kB (for - * 4 kB pages) and also wastes almost 4 kB for the cothreads - * structure */ - munmap((void *)cothread + page_size, page_size); - cothread->magic_number = COTHREAD_MAGIC_NUMBER; GST_DEBUG (GST_CAT_COTHREADS, "create cothread %d with magic number 0x%x", slot, cothread->magic_number); @@ -291,9 +293,8 @@ cothread->flags = 0; cothread->priv = NULL; cothread->sp = ((guchar *) cothread + COTHREAD_STACKSIZE); - cothread->sp -= 16; /* necessary for PowerPC */ - cothread->top_sp = cothread->sp; /* for debugging purposes - to detect stack overruns */ + cothread->stack_size = COTHREAD_STACKSIZE - page_size * 2; + cothread->stack_base = (void *)cothread + 2 * page_size; GST_INFO (GST_CAT_COTHREADS, "created cothread #%d in slot %d: %p at sp:%p", @@ -425,7 +426,6 @@ thread->func = func; thread->argc = argc; thread->argv = argv; - thread->pc = (void *) func; } /** @@ -438,8 +438,6 @@ cothread_stop (cothread_state * thread) { thread->flags &= ~COTHREAD_STARTED; - thread->pc = 0; - thread->sp = thread->top_sp; } /** @@ -496,6 +494,8 @@ GST_DEBUG_ENTER (""); + GST_DEBUG (GST_CAT_COTHREADS, "stack addr %p\n", &ctx); + thread->flags |= COTHREAD_STARTED; while (TRUE) { @@ -685,14 +685,12 @@ enter = setjmp (current->jmp); if (enter != 0) { GST_DEBUG (GST_CAT_COTHREADS, - "enter cothread #%d %d %p<->%p (%d) %p", - current->cothreadnum, enter, current->sp, current->top_sp, - (char*) current->top_sp - (char*) current->sp, current->jmp); + "enter cothread #%d %d sp=%p jmpbuf=%p", + current->cothreadnum, enter, current->sp, current->jmp); return; } - GST_DEBUG (GST_CAT_COTHREADS, "exit cothread #%d %d %p<->%p (%d) %p", - current->cothreadnum, enter, current->sp, current->top_sp, - (char *) current->top_sp - (char *) current->sp, current->jmp); + GST_DEBUG (GST_CAT_COTHREADS, "exit cothread #%d %d sp=%p jmpbuf=%p", + current->cothreadnum, enter, current->sp, current->jmp); enter = 1; if (current->flags & COTHREAD_DESTROYED) { @@ -702,15 +700,30 @@ GST_DEBUG (GST_CAT_COTHREADS, "set stack to %p", thread->sp); /* restore stack pointer and other stuff of new cothread */ if (thread->flags & COTHREAD_STARTED) { - GST_DEBUG (GST_CAT_COTHREADS, "in thread %p", thread->jmp); + GST_DEBUG (GST_CAT_COTHREADS, "via longjmp() jmpbuf %p", thread->jmp); /* switch to it */ longjmp (thread->jmp, 1); } else { +#ifdef HAVE_MAKECONTEXT + ucontext_t ucp; + + GST_DEBUG (GST_CAT_COTHREADS, "making context"); + + g_assert(thread != cothread_main(ctx)); + + getcontext(&ucp); + ucp.uc_stack.ss_sp = (void *)thread->stack_base; + ucp.uc_stack.ss_size = thread->stack_size; + makecontext(&ucp, cothread_stub, 0); + setcontext(&ucp); +#else GST_ARCH_SETUP_STACK ((char*)thread->sp); GST_ARCH_SET_SP (thread->sp); /* start it */ GST_ARCH_CALL (cothread_stub); +#endif + GST_DEBUG (GST_CAT_COTHREADS, "exit thread "); ctx->current = 0; } Index: cothreads.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.h,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- cothreads.h 12 Sep 2002 18:56:30 -0000 1.26 +++ cothreads.h 5 Dec 2002 01:50:31 -0000 1.27 @@ -51,9 +51,8 @@ int flags; void *sp; jmp_buf jmp; - /* is this needed any more? */ - void *top_sp; - void *pc; + void *stack_base; + unsigned long stack_size; int magic_number; }; |
From: David S. <dsc...@us...> - 2002-12-09 01:32:50
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Sun Dec 08 2002 17:32:50 PST Log message: Fix the powerpc atomix swap Modified files: gst : gstatomic.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstatomic.h.diff?r1=1.6&r2=1.7 ====Begin Diffs==== Index: gstatomic.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstatomic.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- gstatomic.h 29 Nov 2002 18:34:32 -0000 1.6 +++ gstatomic.h 9 Dec 2002 01:32:37 -0000 1.7 @@ -173,16 +173,17 @@ #define _GST_ATOMIC_SWAP(swap, val) \ G_STMT_START { \ + int tmp; \ __asm__ __volatile__ ("1:" \ " lwarx %0, 0, %2 \n" \ " stwcx. %3, 0, %2 \n" \ " bne- 1b \n" \ - : "=&r", \ + : "=&r" (tmp), \ "=m" (*swap) \ : "r" (swap), \ "r" (val), \ - "m" (*swap) \ - : "cc", "memory"); \ + "m" (* swap) \ + : "9", "cc"); \ } G_STMT_END #define _GST_ATOMIC_SWAP_GET(swap, val, res) \ @@ -196,7 +197,7 @@ : "r" (swap), \ "r" (val), \ "m" (*swap) \ - : "cc", "memory"); \ + : "cc"); \ } G_STMT_END #else |
From: David S. <dsc...@us...> - 2002-12-09 01:41:19
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Sun Dec 08 2002 17:41:17 PST Log message: Use makecontext() as a generic implementation Modified files: gst : gstarch.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstarch.h.diff?r1=1.16&r2=1.17 ====Begin Diffs==== Index: gstarch.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstarch.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- gstarch.h 2 Dec 2002 19:09:47 -0000 1.16 +++ gstarch.h 9 Dec 2002 01:41:05 -0000 1.17 @@ -180,6 +180,10 @@ ((struct minimal_s390_stackframe *)sp)->back_chain = 0; +#elif defined(HAVE_MAKECONTEXT) + +/* If we have makecontext(), we'll be using that. */ + #else #error Need to know about this architecture, or have a generic implementation #endif |
From: David S. <dsc...@us...> - 2002-12-10 03:45:16
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Dec 09 2002 19:45:15 PST Log message: Partially revert last change, since it breaks things. wtay: FIXME! Modified files: gst : gstpipeline.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstpipeline.c.diff?r1=1.68&r2=1.69 ====Begin Diffs==== Index: gstpipeline.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstpipeline.c,v retrieving revision 1.68 retrieving revision 1.69 diff -u -d -r1.68 -r1.69 --- gstpipeline.c 3 Dec 2002 21:33:29 -0000 1.68 +++ gstpipeline.c 10 Dec 2002 03:45:03 -0000 1.69 @@ -154,9 +154,13 @@ case GST_STATE_PAUSED_TO_READY: break; case GST_STATE_READY_TO_NULL: + /* FIXME: calling gst_scheduler_reset() here is bad, since we + * might not be in cothread 0 */ +#if 0 if (GST_ELEMENT_SCHED (element)) { gst_scheduler_reset (GST_ELEMENT_SCHED (element)); } +#endif break; } |
From: David S. <dsc...@us...> - 2002-12-10 03:48:28
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Dec 09 2002 19:48:27 PST Log message: Added thread-loval variable for cothread index. Modified files: gst : gstinfo.c gstinfo.h Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstinfo.c.diff?r1=1.47&r2=1.48 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/gstinfo.h.diff?r1=1.33&r2=1.34 ====Begin Diffs==== Index: gstinfo.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstinfo.c,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- gstinfo.c 7 Dec 2002 14:13:50 -0000 1.47 +++ gstinfo.c 10 Dec 2002 03:48:15 -0000 1.48 @@ -50,6 +50,8 @@ extern gchar *_gst_progname; +GStaticPrivate _gst_debug_cothread_index = G_STATIC_PRIVATE_INIT; + /***** Categories and colorization *****/ /* be careful with these, make them match the enum */ @@ -193,7 +195,7 @@ gchar *empty = ""; gchar *elementname = empty,*location = empty; int pid = getpid(); - int cothread_id = 0; /*FIXME*/ + int cothread_id = (int) g_static_private_get(&_gst_debug_cothread_index); #ifdef GST_DEBUG_COLOR int pid_color = pid%6 + 31; int cothread_color = (cothread_id < 0) ? 37 : (cothread_id%6 + 31); @@ -305,7 +307,7 @@ gchar *empty = ""; gchar *elementname = empty,*location = empty; int pid = getpid(); - int cothread_id = 0; /*FIXME*/ + int cothread_id = (int) g_static_private_get(&_gst_debug_cothread_index); #ifdef GST_DEBUG_COLOR int pid_color = pid%6 + 31; int cothread_color = (cothread_id < 0) ? 37 : (cothread_id%6 + 31); Index: gstinfo.h =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/gstinfo.h,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- gstinfo.h 8 Dec 2002 20:06:04 -0000 1.33 +++ gstinfo.h 10 Dec 2002 03:48:15 -0000 1.34 @@ -95,6 +95,7 @@ extern const gchar *_gst_category_colors[32]; +extern GStaticPrivate _gst_debug_cothread_index; /********************************************************************** |
From: David S. <dsc...@us...> - 2002-12-10 03:59:28
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Dec 09 2002 19:59:27 PST Log message: Added setting of _gst_debug_cothread_index for debugging Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.99&r2=1.100 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.99 retrieving revision 1.100 diff -u -d -r1.99 -r1.100 --- cothreads.c 6 Dec 2002 23:05:25 -0000 1.99 +++ cothreads.c 10 Dec 2002 03:59:15 -0000 1.100 @@ -618,6 +618,8 @@ ctx->current, thread->cothreadnum); ctx->current = thread->cothreadnum; + g_static_private_set (&_gst_debug_cothread_index, (void *)ctx->current, NULL); + /* save the current stack pointer, frame pointer, and pc */ #ifdef GST_ARCH_PRESETJMP GST_ARCH_PRESETJMP (); |
From: David S. <dsc...@us...> - 2002-12-10 04:01:25
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Dec 09 2002 20:01:22 PST Log message: Lots of new assertions and debugging Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.100&r2=1.101 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.100 retrieving revision 1.101 diff -u -d -r1.100 -r1.101 --- cothreads.c 10 Dec 2002 03:59:15 -0000 1.100 +++ cothreads.c 10 Dec 2002 04:01:09 -0000 1.101 @@ -127,10 +127,12 @@ GST_INFO (GST_CAT_COTHREADS, "initializing cothreads"); /* set this thread's context pointer */ - GST_INFO (GST_CAT_COTHREADS, "setting private _cothread_ctx_key to %p", - ctx); + GST_INFO (GST_CAT_COTHREADS, "setting private _cothread_ctx_key to %p in thread %p", + ctx,g_thread_self()); g_static_private_set (&_cothread_ctx_key, ctx, NULL); + g_assert(ctx == cothread_get_current_context()); + /* clear the cothread data */ memset (ctx->cothreads, 0, sizeof (ctx->cothreads)); @@ -177,6 +179,7 @@ g_return_if_fail (ctx != NULL); g_assert (ctx->thread == g_thread_self()); + g_assert (ctx->current == 0); GST_INFO (GST_CAT_COTHREADS, "free cothread context"); @@ -187,6 +190,8 @@ } g_hash_table_destroy (ctx->data); /* make sure we free the private key for cothread context */ + GST_INFO (GST_CAT_COTHREADS, "setting private _cothread_ctx_key to NULL in thread %p", + g_thread_self()); g_static_private_set (&_cothread_ctx_key, NULL, NULL); g_free (ctx); } @@ -329,10 +334,14 @@ cothreadnum = cothread->cothreadnum; ctx = cothread->ctx; g_assert (ctx->thread == g_thread_self()); + g_assert (ctx == cothread_get_current_context()); GST_INFO (GST_CAT_COTHREADS, "destroy cothread %d %p %d", cothreadnum, cothread, ctx->current); + /* cothread 0 needs to be destroyed specially */ + g_assert(cothreadnum != 0); + /* we have to unlock here because we might be switched out * with the lock held */ cothread_unlock (cothread); @@ -442,6 +451,8 @@ cothread_state * cothread_main (cothread_context * ctx) { + g_assert (ctx->thread == g_thread_self()); + GST_DEBUG (GST_CAT_COTHREADS, "returning %p, the 0th cothread", ctx->cothreads[0]); return ctx->cothreads[0]; @@ -491,6 +502,15 @@ while (TRUE) { thread->func (thread->argc, thread->argv); + + GST_DEBUG (GST_CAT_COTHREADS, "cothread[%d] thread->func exited",ctx->current); + + GST_DEBUG (GST_CAT_COTHREADS, "sp=%p",CURRENT_STACK_FRAME); + GST_DEBUG (GST_CAT_COTHREADS, "ctx=%p current=%p",ctx,cothread_get_current_context()); + g_assert(ctx == cothread_get_current_context()); + + g_assert(ctx->current != 0); + /* we do this to avoid ever returning, we just switch to 0th thread */ cothread_switch (cothread_main (ctx)); } |
From: David S. <dsc...@us...> - 2002-12-10 04:05:27
|
CVS Root: /cvsroot/gstreamer Module: gstreamer Changes by: dschleef Date: Mon Dec 09 2002 20:05:27 PST Log message: Clean up cothread destruction code Modified files: gst : cothreads.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gstreamer/gst/cothreads.c.diff?r1=1.101&r2=1.102 ====Begin Diffs==== Index: cothreads.c =================================================================== RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v retrieving revision 1.101 retrieving revision 1.102 diff -u -d -r1.101 -r1.102 --- cothreads.c 10 Dec 2002 04:01:09 -0000 1.101 +++ cothreads.c 10 Dec 2002 04:05:14 -0000 1.102 @@ -183,15 +183,19 @@ GST_INFO (GST_CAT_COTHREADS, "free cothread context"); - for (i = 0; i < COTHREAD_MAXTHREADS; i++) { + for (i = 1; i < COTHREAD_MAXTHREADS; i++) { if (ctx->cothreads[i]) { cothread_destroy (ctx->cothreads[i]); } } + if (ctx->cothreads[0]) { + g_free(ctx->cothreads[0]); + ctx->cothreads[0] = NULL; + } g_hash_table_destroy (ctx->data); /* make sure we free the private key for cothread context */ GST_INFO (GST_CAT_COTHREADS, "setting private _cothread_ctx_key to NULL in thread %p", - g_thread_self()); + g_thread_self()); g_static_private_set (&_cothread_ctx_key, NULL, NULL); g_free (ctx); } @@ -346,66 +350,14 @@ * with the lock held */ cothread_unlock (cothread); - if (cothreadnum == 0) - { - GST_INFO (GST_CAT_COTHREADS, - "trying to destroy cothread 0 with %d cothreads left", - ctx->ncothreads); - if (ctx->ncothreads > 1) - { - /* we're trying to destroy cothread 0 when there are still cothreads - * active, so kill those first */ - int i; - - for (i = 1; i < COTHREAD_MAXTHREADS; ++i) - { - if (ctx->cothreads[i] != NULL) - { - cothread_destroy (ctx->cothreads[i]); - GST_INFO (GST_CAT_COTHREADS, - "destroyed cothread %d, %d cothreads left", - i, ctx->ncothreads); - } - } - } - g_assert (ctx->ncothreads == 1); - GST_INFO (GST_CAT_COTHREADS, "freeing 0th cothread"); - g_free (cothread); - } - else { - /* int res; - * Replaced with version below until cothreads issues solved */ - int res = 0; - - /* doing cleanups of the cothread create */ - GST_DEBUG (GST_CAT_COTHREADS, "destroy cothread %d with magic number 0x%x", - cothreadnum, cothread->magic_number); - g_assert (cothread->magic_number == COTHREAD_MAGIC_NUMBER); + /* doing cleanups of the cothread create */ + GST_DEBUG (GST_CAT_COTHREADS, "destroy cothread %d with magic number 0x%x", + cothreadnum, cothread->magic_number); + g_assert (cothread->magic_number == COTHREAD_MAGIC_NUMBER); - g_assert (cothread->priv == NULL); + g_assert (cothread->priv == NULL); - GST_DEBUG (GST_CAT_COTHREADS, - "munmap cothread slot stack from %p to %p (size 0x%lx)", - cothread, cothread + COTHREAD_STACKSIZE, - (long) COTHREAD_STACKSIZE); -/* res = munmap (thread, COTHREAD_STACKSIZE); - * Commented out waiting for resolution for cothread issue */ - if (res != 0) - { - switch (res) - { - case EINVAL: - g_warning ("munmap doesn't like start %p or length %d\n", - cothread, COTHREAD_STACKSIZE); - break; - default: - g_warning ("Thomas was too lazy to check for all errors, " - "so I can't tell you what is wrong.\n"); - break; - } - } - } - GST_DEBUG (GST_CAT_COTHREADS, "munmap done"); + memset(cothread,0,sizeof(*cothread)); ctx->cothreads[cothreadnum] = NULL; ctx->ncothreads--; @@ -492,7 +444,7 @@ cothread_stub (void) { cothread_context *ctx = cothread_get_current_context(); - register cothread_state *thread = ctx->cothreads[ctx->current]; + cothread_state *thread = ctx->cothreads[ctx->current]; GST_DEBUG_ENTER (""); |