From: David I. Lehn Date: Wed, 16 May 2001 07:16:47 +0000 (+0000) Subject: - Fix cothread pointers and allocation so full 2M stack space available: X-Git-Tag: BRANCH-INCSCHED1-200105231-ROOT~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=18adcf5a3f78dce2a67882331ae639c22f398413;p=platform%2Fupstream%2Fgstreamer.git - Fix cothread pointers and allocation so full 2M stack space available: Original commit message from CVS: - Fix cothread pointers and allocation so full 2M stack space available: - Double maximums to use full stack space: - COTHREAD_STACKSIZE = 16k - COTHREAD_MAXTHREADS = 128 - cothread changes only verified on x86 - cothread_create returns NULL if nthreads == MAXTHREADS though not yet handled by gstschedule caller --- diff --git a/gst/cothreads.c b/gst/cothreads.c index 108fd87..2de2b3e 100644 --- a/gst/cothreads.c +++ b/gst/cothreads.c @@ -36,8 +36,8 @@ #include "gstarch.h" -#define COTHREAD_STACKSIZE 8192 -#define COTHREAD_MAXTHREADS 64 +#define COTHREAD_STACKSIZE 16384 +#define COTHREAD_MAXTHREADS 128 #define STACK_SIZE 0x200000 @@ -86,7 +86,7 @@ cothread_init (void) ctx->threads[0]->argc = 0; ctx->threads[0]->argv = NULL; ctx->threads[0]->flags = COTHREAD_STARTED; - ctx->threads[0]->sp = (int *)CURRENT_STACK_FRAME; + ctx->threads[0]->sp = (void *)CURRENT_STACK_FRAME; ctx->threads[0]->pc = 0; GST_INFO (GST_CAT_COTHREADS,"0th thread is %p at sp:%p",ctx->threads[0], ctx->threads[0]->sp); @@ -105,26 +105,32 @@ cothread_init (void) * * Create a new cothread state in the given context * - * Returns: the new cothread state + * Returns: the new cothread state or NULL on error */ cothread_state* cothread_create (cothread_context *ctx) { cothread_state *s; + if (ctx->nthreads == COTHREAD_MAXTHREADS) { + GST_DEBUG (0, "attempt to create > COTHREAD_MAXTHREADS\n"); + return NULL; + } GST_DEBUG (0,"pthread_self() %ld\n",pthread_self()); //if (0) { if (pthread_self() == 0) { - s = (cothread_state *)malloc(sizeof(int) * COTHREAD_STACKSIZE); + s = (cothread_state *)malloc(COTHREAD_STACKSIZE); GST_DEBUG (0,"new stack (case 1) at %p\n",s); } else { - char *sp = CURRENT_STACK_FRAME; - unsigned long *stack_end = (unsigned long *)((unsigned long)sp & - ~(STACK_SIZE - 1)); + void *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 + void *stack_end = (void *)((unsigned long)sp & ~(STACK_SIZE - 1)); s = (cothread_state *)(stack_end + ((ctx->nthreads - 1) * COTHREAD_STACKSIZE)); GST_DEBUG (0,"new stack (case 2) at %p\n",s); - if (mmap((char *)s,COTHREAD_STACKSIZE*(sizeof(int)), + if (mmap((void *)s,COTHREAD_STACKSIZE, PROT_READ|PROT_WRITE|PROT_EXEC,MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1,0) < 0) { perror("mmap'ing cothread stack space"); @@ -135,7 +141,7 @@ cothread_create (cothread_context *ctx) s->ctx = ctx; s->threadnum = ctx->nthreads; s->flags = 0; - s->sp = ((int *)s + COTHREAD_STACKSIZE); + s->sp = ((void *)s + COTHREAD_STACKSIZE); // is this needed anymore? s->top_sp = s->sp; @@ -164,7 +170,7 @@ cothread_setfunc (cothread_state *thread, thread->func = func; thread->argc = argc; thread->argv = argv; - thread->pc = (int *)func; + thread->pc = (void *)func; } /** diff --git a/gst/gstscheduler.c b/gst/gstscheduler.c index cc6fe46..e4e1d79 100644 --- a/gst/gstscheduler.c +++ b/gst/gstscheduler.c @@ -277,6 +277,7 @@ gst_schedule_cothreaded_chain (GstBin *bin, _GstBinChain *chain) { // need to set up the cothread now if (wrapper_function != NULL) { if (element->threadstate == NULL) { + // FIXME handle cothread_create returning NULL element->threadstate = cothread_create (bin->threadcontext); GST_DEBUG (0,"created cothread %p for '%s'\n",element->threadstate,GST_ELEMENT_NAME(element)); }