ok, my latest added error checking and stuff this reverts uraeus's patch but should tell us what goes wrong with munmap

Original commit message from CVS:
ok, my latest added error checking and stuff
this reverts uraeus's patch but should tell us what goes wrong with munmap
This commit is contained in:
Thomas Vander Stichele 2002-06-27 22:17:17 +00:00
parent 7cc370b0bf
commit ef2f6e1fc4
3 changed files with 43 additions and 10 deletions

View file

@ -55,7 +55,7 @@ struct _cothread_context
static pthread_key_t _cothread_key = -1; static pthread_key_t _cothread_key = -1;
/* Disablig this define allows you to shut off a few checks in /* Disabling this define allows you to shut off a few checks in
* cothread_switch. This likely will speed things up fractionally */ * cothread_switch. This likely will speed things up fractionally */
#define COTHREAD_PARANOID #define COTHREAD_PARANOID
@ -265,9 +265,7 @@ cothread_destroy (cothread_state *thread)
g_free (thread); g_free (thread);
} }
else { else {
/* this doesn't seem to work very well */ int res;
/* munmap ((void *) thread, COTHREAD_STACKSIZE); */
int res = 0;
GST_DEBUG (GST_CAT_COTHREADS, GST_DEBUG (GST_CAT_COTHREADS,
"unmap cothread slot stack from %p to %p (size %ld)", "unmap cothread slot stack from %p to %p (size %ld)",
@ -275,7 +273,7 @@ cothread_destroy (cothread_state *thread)
(long) COTHREAD_STACKSIZE); (long) COTHREAD_STACKSIZE);
GST_DEBUG (GST_CAT_COTHREADS, "doing an munmap at %p of size %d\n", GST_DEBUG (GST_CAT_COTHREADS, "doing an munmap at %p of size %d\n",
thread, COTHREAD_STACKSIZE); thread, COTHREAD_STACKSIZE);
/* res = munmap ((void *) thread, COTHREAD_STACKSIZE); */ res = munmap ((void *) thread, COTHREAD_STACKSIZE);
if (res != 0) if (res != 0)
{ {
switch (res) switch (res)
@ -502,6 +500,8 @@ cothread_stackquery (void **stack, glong* stacksize)
*stacksize = 0; *stacksize = 0;
return FALSE; return FALSE;
} }
GST_DEBUG (GST_CAT_THREAD, "have posix_memalign at %p of size %d\n",
(void *) *stack, STACK_SIZE);
GST_DEBUG (GST_CAT_COTHREADS, GST_DEBUG (GST_CAT_COTHREADS,
"Got new cothread stack from %p to %p (size %ld)\n", "Got new cothread stack from %p to %p (size %ld)\n",
*stack, *stack + STACK_SIZE - 1, (long) STACK_SIZE); *stack, *stack + STACK_SIZE - 1, (long) STACK_SIZE);

View file

@ -2,7 +2,7 @@
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be> * 2000 Wim Taymans <wtay@chello.be>
* *
* gstschedulerr.h: Header for default schedulerr code * gstscheduler.h: Header for default scheduler code
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public

View file

@ -154,6 +154,8 @@ static void
gst_thread_dispose (GObject *object) gst_thread_dispose (GObject *object)
{ {
GstThread *thread = GST_THREAD (object); GstThread *thread = GST_THREAD (object);
void *stack;
long stacksize;
GST_DEBUG (GST_CAT_REFCOUNTING, "dispose"); GST_DEBUG (GST_CAT_REFCOUNTING, "dispose");
@ -162,6 +164,12 @@ gst_thread_dispose (GObject *object)
G_OBJECT_CLASS (parent_class)->dispose (object); G_OBJECT_CLASS (parent_class)->dispose (object);
GST_DEBUG (GST_CAT_THREAD, "Disposing of thread");
pthread_attr_getstack (&thread->attr, &stack, (size_t *) &stacksize);
GST_DEBUG (GST_CAT_THREAD, "undng posix_memalign at %p of size %ld\n",
stack, stacksize);
free (stack);
if (GST_ELEMENT_SCHED (thread)) { if (GST_ELEMENT_SCHED (thread)) {
gst_object_unref (GST_OBJECT (GST_ELEMENT_SCHED (thread))); gst_object_unref (GST_OBJECT (GST_ELEMENT_SCHED (thread)));
} }
@ -274,16 +282,27 @@ gst_thread_change_state (GstElement * element)
g_mutex_lock (thread->lock); g_mutex_lock (thread->lock);
pthread_attr_init (&thread->attr); if (pthread_attr_init (&thread->attr) != 0)
g_warning ("pthread_attr_init returned an error !");
if (gst_scheduler_get_prefered_stack (GST_ELEMENT_SCHED (element), &stack, &stacksize)) { if (gst_scheduler_get_prefered_stack (GST_ELEMENT_SCHED (element), &stack, &stacksize)) {
pthread_attr_setstack (&thread->attr, stack, stacksize); if (pthread_attr_setstack (&thread->attr, stack, stacksize) != 0)
g_warning ("pthread_attr_setstack failed !\n");
GST_DEBUG (GST_CAT_THREAD,
"pthread attr set stack at %p of size %ld",
stack, stacksize);
} }
else
g_warning ("_get_prefered_stack failed !\n");
/* create the thread */ /* create the thread */
THR_DEBUG ("going to pthread_create...");
if (pthread_create (&thread->thread_id, &thread->attr, gst_thread_main_loop, thread) != 0) { if (pthread_create (&thread->thread_id, &thread->attr, gst_thread_main_loop, thread) != 0) {
THR_DEBUG ("pthread create failed");
g_mutex_unlock (thread->lock); g_mutex_unlock (thread->lock);
THR_DEBUG ("could not create thread \"%s\"", GST_ELEMENT_NAME (element)); THR_DEBUG ("could not create thread \"%s\"", GST_ELEMENT_NAME (element));
return GST_STATE_FAILURE; return GST_STATE_FAILURE;
} }
THR_DEBUG ("pthread created");
/* wait for it to 'spin up' */ /* wait for it to 'spin up' */
THR_DEBUG ("waiting for child thread spinup"); THR_DEBUG ("waiting for child thread spinup");
@ -402,10 +421,22 @@ gst_thread_change_state (GstElement * element)
THR_DEBUG ("waiting for ack"); THR_DEBUG ("waiting for ack");
g_cond_wait (thread->cond, thread->lock); g_cond_wait (thread->cond, thread->lock);
THR_DEBUG ("got ack"); THR_DEBUG ("got ack");
pthread_join (thread->thread_id, NULL); if (pthread_join (thread->thread_id, NULL) != 0)
g_warning ("pthread_join has failed !\n");
if (pthread_attr_destroy (&thread->attr) != 0)
g_warning ("pthread_attr_destroy has failed !\n");
thread->thread_id = -1; thread->thread_id = -1;
g_mutex_unlock (thread->lock); g_mutex_unlock (thread->lock);
/*
* FIXME: we moved this code to the scheduler dispose function
pthread_attr_getstack (&thread->attr, &stack, (size_t *) &stacksize);
GST_DEBUG (GST_CAT_THREAD, "undng posix_memalign at %p of size %ld\n",
stack, stacksize);
stack, stacksize);
free (thread->stack);
thread->stack = 0;
*/
GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING); GST_FLAG_UNSET (thread, GST_THREAD_STATE_REAPING);
GST_FLAG_UNSET (thread, GST_THREAD_STATE_STARTED); GST_FLAG_UNSET (thread, GST_THREAD_STATE_STARTED);
GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING); GST_FLAG_UNSET (thread, GST_THREAD_STATE_SPINNING);
@ -440,9 +471,11 @@ gst_thread_change_state (GstElement * element)
static void * static void *
gst_thread_main_loop (void *arg) gst_thread_main_loop (void *arg)
{ {
GstThread *thread = GST_THREAD (arg); GstThread *thread = NULL;
gint stateset; gint stateset;
THR_DEBUG ("gst_thread_main_loop started");
thread = GST_THREAD (arg);
g_mutex_lock (thread->lock); g_mutex_lock (thread->lock);
gst_scheduler_setup (GST_ELEMENT_SCHED (thread)); gst_scheduler_setup (GST_ELEMENT_SCHED (thread));