From b7bc06aee5eb46c71e57463e1c7e47e5b684f40d Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Wed, 26 Jun 2002 08:22:17 +0000 Subject: [PATCH] ok, this seems to be the right fix for the basic scheduler. Original commit message from CVS: ok, this seems to be the right fix for the basic scheduler. I'd appreciate it if : a) someone looks over these minimal changes and tells me if they're done in the right way (especially the alignment argument ;)) b) others run lots of pipes with basic and tell me if they still have issues If all goes well I want to revert to the basic scheduler and do a release --- gst/cothreads.c | 39 +++++++++++++++++++++++++++++-- gst/cothreads.h | 1 + gst/schedulers/cothreads_compat.h | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/gst/cothreads.c b/gst/cothreads.c index 4d9f60acdd..c96f17a36f 100644 --- a/gst/cothreads.c +++ b/gst/cothreads.c @@ -179,11 +179,18 @@ cothread_create (cothread_context *ctx) stack_end = (guchar *) ((gulong) sp & ~(STACK_SIZE - 1)); thread = (cothread_state *) (stack_end + ((slot - 1) * COTHREAD_STACKSIZE)); - GST_DEBUG (GST_CAT_COTHREADS, "new stack at %p", thread); + GST_DEBUG (GST_CAT_COTHREADS, + "new cothread slot stack from %p to %p (size %ld)", + thread, thread + COTHREAD_STACKSIZE - 1, + (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 */ + munmap ((void *) thread, COTHREAD_STACKSIZE); mmaped = mmap ((void *) thread, COTHREAD_STACKSIZE, - PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + 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"); @@ -446,6 +453,34 @@ cothread_context_get_data (cothread_state * thread, gchar * key) return g_hash_table_lookup (ctx->data, key); } +/** + * cothreads_stackquery: + * @stack: Will be set to point to the allocated stack location + * @stacksize: Will be set to the size of the allocated stack + * + * Returns: #TRUE on success, #FALSE otherwise. + */ +gboolean +cothread_stackquery (void **stack, glong* stacksize) +{ + /* wingo: use posix_memalign to allocate a 2M-aligned, 2M stack */ + + int retval = 0; + + retval = posix_memalign (stack, STACK_SIZE, STACK_SIZE); + if (retval != 0) + { + g_warning ("Could not posix_memalign stack !\n"); + *stacksize = 0; + return FALSE; + } + GST_DEBUG (GST_CAT_COTHREADS, + "Got new cothread stack from %p to %p (size %ld)\n", + *stack, *stack + STACK_SIZE - 1, (long) STACK_SIZE); + *stacksize = STACK_SIZE; + return TRUE; +} + /** * cothread_switch: * @thread: cothread state to switch to diff --git a/gst/cothreads.h b/gst/cothreads.h index 92cf0044b4..49c437d5cc 100644 --- a/gst/cothreads.h +++ b/gst/cothreads.h @@ -81,6 +81,7 @@ void cothread_setfunc (cothread_state *thread, cothread_func func, void cothread_stop (cothread_state *thread); void cothread_switch (cothread_state *thread); +gboolean cothread_stackquery (void **stack, glong* stacksize); void cothread_set_private (cothread_state *thread, gpointer data); gpointer cothread_get_private (cothread_state *thread); diff --git a/gst/schedulers/cothreads_compat.h b/gst/schedulers/cothreads_compat.h index e02d1c46bc..422665ab0d 100644 --- a/gst/schedulers/cothreads_compat.h +++ b/gst/schedulers/cothreads_compat.h @@ -40,7 +40,7 @@ typedef cothread_state cothread; */ #define do_cothreads_init(x) /* NOP */ -#define do_cothreads_stackquery(stack,size) FALSE +#define do_cothreads_stackquery(stack,size) cothread_stackquery(stack,size) #define do_cothread_switch(to) cothread_switch(to)