diff --git a/h/ocm_chan.h b/h/ocm_chan.h new file mode 100644 index 000000000..ff66f8594 --- /dev/null +++ b/h/ocm_chan.h @@ -0,0 +1,47 @@ +/* ocm_chan.h - channel definitions */ +#include <stdio.h> +#include "ocm_parco.h" + +typedef union channel { + struct { /* Interprocess channel */ + char _type; /* Channel type, see note */ + char synch; /* State in channel synchronization */ + long val; /* Transmitted value */ + } c; + struct { /* File channel */ + char _type; /* Dummy field, see note */ + char index; /* Index in the file array */ + char flgs; /* Status flags: in use & readahead */ + char preread; /* Possible preread character */ + } f; +} chan; +#define type c._type /* Channel type */ +/* Note: The channel type should not be part of each structure in chan. But + * the C alignment rules would make chan about 50% bigger if we had done it + * the right way. Note that the order of fields in a struct cannot be a problem + * as long as struct c is the largest within the union. + */ + +#define C_T_CHAN 0 /* Type of a interprocess channel */ +#define C_T_FILE 1 /* Type of a file channel */ + +#define C_S_FREE 0 /* IP channel is free */ +#define C_S_ANY 1 /* IP channel contains data */ +#define C_S_ACK 2 /* IP channel data is removed */ + +#define C_F_EOF (-1L) /* File channel returns EOF */ +#define C_F_TEXT (-2L) /* File channel becomes line oriented */ +#define C_F_RAW (-3L) /* File channel becomes character oriented */ + +#define C_F_INUSE 0x01 /* File channel is connected to a UNIX file */ +#define C_F_READAHEAD 0x02 /* File channel has a preread character */ + +extern chan file[20]; /* Array of file channels */ +extern FILE *unix_file[20]; /* Pointers to buffered UNIX files */ + +void c_init(); + +void chan_in(), cbyte_in(), c_wa_in(), c_ba_in(); +void chan_out(), c_wa_out(), c_ba_out(); + +int chan_any(); diff --git a/h/ocm_parco.h b/h/ocm_parco.h new file mode 100644 index 000000000..1588d43c3 --- /dev/null +++ b/h/ocm_parco.h @@ -0,0 +1,18 @@ +/* parco.h - Define names for simulation routines + * + * This file is to be included by users of the higher-level routines + * + */ + +void pc_begin(), resumenext(), parend(), resume(), coend(); +int pc_fork(); + +#define nullid ((int *) 0 - (int *) 0) + /* I.e. a 0 of type "pointer difference" */ + +#define parbegin(sbrk) pc_begin(sbrk, nullid) +#define parfork() pc_fork(nullid) +#define cobegin(sbrk, id) pc_begin(sbrk, id) +#define cofork(id) pc_fork(id) + +extern int deadlock; diff --git a/h/ocm_proc.h b/h/ocm_proc.h new file mode 100644 index 000000000..3f716e812 --- /dev/null +++ b/h/ocm_proc.h @@ -0,0 +1,56 @@ +/* process.h - Define administration types and functions + * + * This file is to be included by implementors of the higher + * level routines + * + */ +#include "ocm_parco.h" + +#ifndef ptrdiff /* This type must be able to hold a pointer difference */ +#if EM_WSIZE <EM_PSIZE +#define ptrdiff long +#else +#define ptrdiff int /* Define as long int if necessary */ +#endif +#endif + +#define nil 0 +void *alloc(), free(); + +typedef ptrdiff wordsize, identification; + +wordsize top_size(); +int top_save(); +void top_load(); /* Primitives */ + +struct procgroup; + +struct process { + struct process *next; /* Next process in the same group */ + struct procgroup *down; /* Process group running under this process */ + void *stack; /* Pointer to the saved stack top */ + identification id; /* Coroutine identification */ +}; + +#define init_between __i_b__ /* These names are hidden */ +#define save_between __s_b__ +#define load_betweens __l_b__ +#define delete_between __d_b__ + +void init_between(), save_between(), load_betweens(), delete_between(); + +struct procgroup { + struct process **active;/* Active process within this group */ + struct procgroup *up; /* The group that this group belongs to */ + struct process *first; /* List of processes belonging to this group */ + void *s_brk; /* Point where the stack is split */ + void *between; /* Stack space between s_brk and up->s_brk */ +}; + +#define group __grp__ /* Ignore this please */ +#define highest_group __hgrp__ + +extern struct procgroup *group; /* Current running group */ +extern struct procgroup *highest_group; /* highest group that has been seen + * while searching for a process + */