(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.
This commit is contained in:
parent
f958d3d683
commit
aab54fcd54
4 changed files with 52 additions and 41 deletions
|
@ -32,43 +32,8 @@
|
||||||
#define LWP_STACKCHECK 0x1
|
#define LWP_STACKCHECK 0x1
|
||||||
#define LWP_PRINT 0x2
|
#define LWP_PRINT 0x2
|
||||||
|
|
||||||
/* process control block. do *not* change the position of context */
|
struct lwpProc;
|
||||||
struct lwpProc {
|
struct lwpSem;
|
||||||
#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;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define LWP_FD_READ 0x1
|
#define LWP_FD_READ 0x1
|
||||||
#define LWP_FD_WRITE 0x2
|
#define LWP_FD_WRITE 0x2
|
||||||
|
|
|
@ -37,10 +37,18 @@
|
||||||
|
|
||||||
#ifdef _EMPTH_LWP
|
#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
|
int
|
||||||
empth_init(void **ctx, int flags)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +57,8 @@ empth_t *
|
||||||
empth_create(int prio, void (*entry)(void *), int size, int flags,
|
empth_create(int prio, void (*entry)(void *), int size, int flags,
|
||||||
char *name, char *desc, void *ud)
|
char *name, char *desc, void *ud)
|
||||||
{
|
{
|
||||||
/* inherit flags */
|
|
||||||
if (!flags)
|
if (!flags)
|
||||||
flags = LwpCurrent->flags;
|
flags = empth_flags;
|
||||||
return lwpCreate(prio, entry, size, flags, name, desc, 0, 0, ud);
|
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
|
/* We want to leave the main thread around forever, until it's time
|
||||||
for it to die for real (in a shutdown) */
|
for it to die for real (in a shutdown) */
|
||||||
if (!strcmp(LwpCurrent->name, "Main")) {
|
if (LwpCurrent == empth_main) {
|
||||||
while (1) {
|
while (1) {
|
||||||
time(&now);
|
time(&now);
|
||||||
lwpSleepUntil(now + 60);
|
lwpSleepUntil(now + 60);
|
||||||
|
|
|
@ -29,6 +29,44 @@
|
||||||
/* more inefficient the context switch time */
|
/* more inefficient the context switch time */
|
||||||
#define LCOUNT -1
|
#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
|
#ifdef UCONTEXT
|
||||||
void lwpInitContext(struct lwpProc *, stack_t *);
|
void lwpInitContext(struct lwpProc *, stack_t *);
|
||||||
#define lwpSave(x) getcontext(&(x))
|
#define lwpSave(x) getcontext(&(x))
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "lwp.h"
|
#include "lwp.h"
|
||||||
|
#include "lwpint.h"
|
||||||
|
|
||||||
#if defined(_EMPTH_LWP)
|
#if defined(_EMPTH_LWP)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue