/* 
 * Copyright (c) 1993,1991,1990,1996  Arizona Board of Regents
 *
 * $RCSfile: scout_thread.h,v $
 *
 * HISTORY
 * $Log: scout_thread.h,v $
 * Revision 1.1  1997/04/29 22:45:15  rrp
 * Initial revision
 *
 * Revision 1.4  1996/09/07 20:49:25  davidm
 * (tSelf): Don't use (0, x) to create rvalue since some compilers generate
 * 	warning about "useless expression".
 * (threadName): Make inline function.
 *
 * Revision 1.3  1996/05/28 20:17:26  davidm
 * ThreadPrio: moved into thread_prio.h.
 * ThreadScheduler: New type.
 * struct Thread: Removed unused member "magic".
 * threadIdleCount: Removed.
 * threadRegisterScheduler: New function.
 *
 * Add include of <scout/threadd_p.h>
 *
 */
#ifndef __thread_h__
#define __thread_h__

typedef enum {
    THREAD_PRIO_MAX = 0,
    THREAD_PRIO_STD = 1,
    THREAD_PRIO_MIN = 2
} ThreadPrio;

typedef void			(*ThreadFunc)(void * arg);

typedef struct ThreadStack *	ThreadStack;

typedef struct Thread *		Thread;
typedef struct ThreadOptions *	ThreadOptions;

struct ThreadOptions {
    char *		name;		/* thread name */
    void *		arg;		/* argument to be passed to FUN */
    unsigned int	priority;	/* sched.-dependent thread priority */
};

struct Thread {
    Thread			next;		/* linked list of threads */
    long			running   : 1;	/* has thread been started? */
    ThreadStack			stack;
    ThreadFunc			func;
    struct ThreadOptions	option;
};

extern bool			threadInitialized;
extern const ThreadOptions	threadDefaultOptions;
extern Thread			threadSelf;

#define tSelf			(threadSelf + 0)
#define threadSetContFunc(t,f)	{(t)->func = (f);}
#define threadSetContArg(t,a)	{(t)->option.arg = (a);}

extern const char * threadName (Thread t);
extern void	threadInit (ThreadFunc init, void * arg);
extern Thread	threadCreate (ThreadFunc func, const ThreadOptions opt);
extern void	threadStop (void);
extern void	threadSuspend (void);
extern void	threadSuspendWithContinuation (void);
extern void	threadWakeup (Thread t);
extern void	threadYield (void);
extern size_t	threadFreeStack (void);
extern void	threadFPUFault (void);

#endif /* __thread_h__ */
