From aab54fcd54e131c78ab2490427257b7fe3e7e54c Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 7 Dec 2005 19:15:37 +0000 Subject: [PATCH] (lwpProc, lwpSem): Declare as incomplete type in include/lwp.h. Move complete declaration to src/lib/lwp/lwpint.h. (lwpQueue): Move to src/lib/lwp/lwpint.h. (empth_main, empth_flags): New. (empth_init): Initialize them. (empth_create, empth_exit): Use them instead of lwpProc members. --- include/lwp.h | 39 ++------------------------------------- src/lib/empthread/lwp.c | 15 +++++++++++---- src/lib/lwp/lwpint.h | 38 ++++++++++++++++++++++++++++++++++++++ src/lib/lwp/status.c | 1 + 4 files changed, 52 insertions(+), 41 deletions(-) diff --git a/include/lwp.h b/include/lwp.h index 146adf25..9c89414d 100644 --- a/include/lwp.h +++ b/include/lwp.h @@ -32,43 +32,8 @@ #define LWP_STACKCHECK 0x1 #define LWP_PRINT 0x2 -/* process control block. do *not* change the position of context */ -struct lwpProc { -#ifdef UCONTEXT - ucontext_t context; /* context structure */ -#else /* !UCONTEXT */ - jmp_buf context; /* processor context area */ -#endif /* !UCONTEXT */ - void *sbtm; /* bottom of stack attached to it */ - int size; /* size of stack */ - void (*entry)(void *); /* entry point */ - int dead; /* whether the process can be rescheduled */ - int pri; /* which scheduling queue we're on */ - long runtime; /* time at which process is restarted */ - int fd; /* fd we're blocking on */ - int argc; /* initial arguments */ - char **argv; - void *ud; /* user data */ - void *lowmark; /* start of low buffer around stack */ - void *himark; /* start of upper buffer around stack */ - char *name; /* process name and description */ - char *desc; - int flags; - struct lwpProc *next; -}; - -/* queue */ -struct lwpQueue { - struct lwpProc *head; - struct lwpProc *tail; -}; - -/* semaphore */ -struct lwpSem { - int count; - struct lwpQueue q; - char *name; -}; +struct lwpProc; +struct lwpSem; #define LWP_FD_READ 0x1 #define LWP_FD_WRITE 0x2 diff --git a/src/lib/empthread/lwp.c b/src/lib/empthread/lwp.c index c1aea95d..0663c5b9 100644 --- a/src/lib/empthread/lwp.c +++ b/src/lib/empthread/lwp.c @@ -37,10 +37,18 @@ #ifdef _EMPTH_LWP +/* The thread `created' by lwpInitSystem() */ +static empth_t *empth_main; + +/* Flags that were passed to empth_init() */ +static int empth_flags; + + int empth_init(void **ctx, int flags) { - lwpInitSystem(PP_MAIN, (char **)ctx, flags); + empth_flags = flags; + empth_main = lwpInitSystem(PP_MAIN, (char **)ctx, flags); return 0; } @@ -49,9 +57,8 @@ empth_t * empth_create(int prio, void (*entry)(void *), int size, int flags, char *name, char *desc, void *ud) { - /* inherit flags */ if (!flags) - flags = LwpCurrent->flags; + flags = empth_flags; return lwpCreate(prio, entry, size, flags, name, desc, 0, 0, ud); } @@ -68,7 +75,7 @@ empth_exit(void) /* We want to leave the main thread around forever, until it's time for it to die for real (in a shutdown) */ - if (!strcmp(LwpCurrent->name, "Main")) { + if (LwpCurrent == empth_main) { while (1) { time(&now); lwpSleepUntil(now + 60); diff --git a/src/lib/lwp/lwpint.h b/src/lib/lwp/lwpint.h index 4e3e64cd..d6c4965c 100644 --- a/src/lib/lwp/lwpint.h +++ b/src/lib/lwp/lwpint.h @@ -29,6 +29,44 @@ /* more inefficient the context switch time */ #define LCOUNT -1 +/* process control block. do *not* change the position of context */ +struct lwpProc { +#ifdef UCONTEXT + ucontext_t context; /* context structure */ +#else /* !UCONTEXT */ + jmp_buf context; /* processor context area */ +#endif /* !UCONTEXT */ + void *sbtm; /* bottom of stack attached to it */ + int size; /* size of stack */ + void (*entry)(void *); /* entry point */ + int dead; /* whether the process can be rescheduled */ + int pri; /* which scheduling queue we're on */ + long runtime; /* time at which process is restarted */ + int fd; /* fd we're blocking on */ + int argc; /* initial arguments */ + char **argv; + void *ud; /* user data */ + void *lowmark; /* start of low buffer around stack */ + void *himark; /* start of upper buffer around stack */ + char *name; /* process name and description */ + char *desc; + int flags; + struct lwpProc *next; +}; + +/* queue */ +struct lwpQueue { + struct lwpProc *head; + struct lwpProc *tail; +}; + +/* semaphore */ +struct lwpSem { + int count; + struct lwpQueue q; + char *name; +}; + #ifdef UCONTEXT void lwpInitContext(struct lwpProc *, stack_t *); #define lwpSave(x) getcontext(&(x)) diff --git a/src/lib/lwp/status.c b/src/lib/lwp/status.c index f8634820..23950f8c 100644 --- a/src/lib/lwp/status.c +++ b/src/lib/lwp/status.c @@ -34,6 +34,7 @@ #include #include #include "lwp.h" +#include "lwpint.h" #if defined(_EMPTH_LWP)