task.h 3.38 KB
/*
 * Copyright (C) 1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * Copyright (C) 1998 Digital Equipment Corporation
 *
 * This file is part of the SimOS distribution.
 * See LICENSE file for terms of the license.
 *
 */

#ifndef _TASK_H_
#define _TASK_H_

/*
 * Definition of the event structure and bit field mnemonics
 */

#include <values.h>
#include "event.h"
#include "export.h"

/* The order of the first few fields is important.
 * The time wheel defines a struct that contains only next, prev, time
 * and priority.
 */
typedef struct task {
    struct task *next;
    struct task *prev;
    aint_time_t time;
    int priority;		/* larger number == higher priority */
    int pid;
    int (*ufunc) (struct task *);	/* user-defined function to call */
    struct task *tstack;	/* stack of tasks to execute next */
    struct event *pevent;	/* pointer to an event structure */
    long ival1;			/* user-defined integer value */
    long ival2;			/* user-defined integer value */
    long ival3;			/* user-defined integer value */
    long ival4;			/* user-defined integer value */
    long ival5;			/* user-defined integer value */
    long ival6;			/* user-defined integer value */
    double dval1;		/* user-defined double value */
    double dval2;		/* user-defined double value */
    aint_time_t tval1;		/* user-defined time value */
    aint_time_t tval2;		/* user-defined time value */
    aint_time_t tval3;		/* user-defined time value */
    void *uptr;			/* user-defined pointer */
    void *uptr2;		/* user-defined pointer */
    void *uptr3;		/* user-defined pointer */
    void *uptr4;		/* user-defined pointer */
    long virtual_address;	/* user-defined to contain value of
				   ptask->pevent->vaddr */ 
    long event_type;		/* user-defined to contain value of
				   ptask->pevent->type */ 
    int (*ufunc2) (struct task *);	/* user-defined function pointer */
    struct task *unext;		/* user-defined forward link */
    struct task *uprev;		/* user-defined backward link */

    /*
     * There are supposed to be more things in here, that the user may define.
     * Will deal with them later
     */
} task_t, *task_ptr;

typedef int (*PFTASK) (struct task * ptask);

/* the default priority */
#define DEF_PRIORITY 0

#define PRIORITY_HIGH (~(1 << 31))
#define PRIORITY_LOW  (1 << 31)

#define T_ADVANCE 0
#define T_FREE    1
#define T_NO_ADVANCE T_FREE	/* For backwards compatibility? */
#define T_YIELD   2
#define T_CONTINUE 3
#define T_MAX     5		/* Must be last */


#ifdef __cplusplus
extern "C" {
#endif

/* Function prototypes */

int wait_for_children (thread_ptr pthread);
int wait_for_child (thread_ptr pthread);
int task_yield (task_ptr ptask);
int task_exit (task_ptr ptask);
int task_done (task_ptr ptask);
int task_fork (task_ptr ptask);
int task_m_fork (task_ptr ptask);
int task_block (task_ptr ptask);
int task_timed_block (task_ptr ptask);
int task_unblock (task_ptr ptask);
int task_unblock_list (task_ptr ptask);
int task_terminate (task_ptr ptask);
task_ptr pri_sched_task (task_ptr ptask, PFTASK ufunc, aint_time_t tval,
    		     int priority);
task_ptr stack_task (task_ptr ptask, PFTASK ufunc);
task_ptr sched_task (task_ptr ptask, PFTASK ufunc, aint_time_t tval);
task_ptr schedule_task (task_ptr pnew);
task_ptr new_task (task_ptr ptask);
task_ptr newtask ();
void free_task (task_ptr ptask);



#ifdef  __cplusplus
}
#endif				/* __cplusplus */

#endif /* _TASK_H_ */