/* stack.h:
 * This program package constitutes the lowest of the five modules of the Pads
 * hierarchy.  Pads provides Parallel And Distributed Support for application
 * programs, as externally specified in the document "PADS, an infrastructure
 * for parallel and distributed programs: Users' Manual", which should be read
 * first.  This module provides for multiple stacks within a process, as
 * needed by the tasking module (the next up the hierarchy).  The tasking
 * thereby supported does not offer true parallelism: control passes from
 * stack to stack sequentially.  What it does offer is concurrency, namely
 * freedom from the first in, last out discipline of a single stack.
 */
#if !defined(stack_h)

#if defined(ultrix) && !defined(mips)
/* Longjmp in non-mips ultrix does not, as assumed by the implementation,
 * directly jump but instead "unrolls" the stack.  Therefore an alternative
 * implementation of setjmp/longjmp is provided that does directly jump.
 */
typedef int jmp_buf[144];
#else /* defined(ultrix) && !defined(mips) */
#include <setjmp.h>
#endif /* defined(ultrix)  && !defined(mips) */

#if !defined(Null)
typedef unsigned char Byte;		/* byte type */
typedef Byte *Ptr;			/* generic pointer type */
#define Null ((Ptr) 0)			/* null value */
#else /* !defined(Null) */
#endif /* !defined(Null) */

/* Stack identifier, a pointer to a structure holding its state.
 */
typedef struct stk_ {
#if defined(CRAY)
    int ctrl[3];			/* multitasking control */
    jmp_buf jb;				/* jmp buffer */
    int event;				/* event to regulate running of stack */
    struct stk_ *fp;			/* forward circular list ptr */
    struct stk_ *bp;			/* backward circular list ptr */
#	define _exit exit_		/*  use alternative exit */
    void (*proc)();			/* main stack procedure ptr */
#else /* defined(CRAY) */
#if defined(sparc)
    jmp_buf jb;				/* jmp buffer */
    int pad;				/* Prevents damage */
    void (*proc)();			/* main stack procedure  ptr*/
#else /* defined(sparc) */
    jmp_buf jb;				/* jmp buffer */
    void (*proc)();			/* main stack procedure ptr */
#endif /* defined(sparc) */
#endif /* defined(CRAY) */
} *Stack;
 
/* Create a new stack. */
    extern Stack			/* returns new stack id or null */
Crestk ();				/*
    void (*proc)()			   main stack procedure
    unsigned long size			   stack size */

/* Switch control to another stack. */
    extern Stack			/* returns current stack id */
Swistk ();				/*
    Stack stack				   next stack id */

/* Destroy a stack. */
    extern Stack			/* returns null */
Dststk ();				/*
    Stack stack				   next stack id */

#define stack_h
#endif

/*
     *    * * *  *      * * *  * * *    *    *   *  * * *  * *          *     *
   * *    *      *      *        *    *   *  *   *  *      *   *      *     *
 * * * *  * *    *      * *      *    *      * * *  * *    * *    * * * * *
   * *    *      *      *        *    *   *  *   *  *      *   *      *     *
     *    *      * * *  * * *    *      *    *   *  * * *  *   *        *     *

 * Programmed by John G. Fletcher, who makes it available without any warranty
 * and maintains it on the basis of best effort, time as available.  No
 * organization or other person has any responsibility for it.

 * (C) Copyright 1992, the Regents of the University of California.  All Rights
 * Reserved.  This work was produced under the sponsorship of the U.S.
 * Department of Energy.  The Government retains certain rights therein.
 */
