home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
ctask.zip
/
TSK.H
< prev
next >
Wrap
C/C++ Source or Header
|
1988-03-01
|
8KB
|
246 lines
/*
TSK.H - CTask - Type definitions and global routine prototypes.
Public Domain Software written by
Thomas Wagner
Patschkauer Weg 31
D-1000 Berlin 33
West Germany
*/
#include <stdio.h>
#if defined(OPEN_MAX) /* Only defined in Turbo C stdio.h */
#define _Near
#else
#define _Near near
#endif
#define local static /* Comment out the "static" for debugging */
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;
typedef void (cdecl far *funcptr)();
typedef void far *farptr;
typedef byte far *byteptr;
typedef word far *wordptr;
#define TTIMEOUT ((farptr) -1L)
#define TWAKE ((farptr) -2L)
/* Task states */
#define ST_KILLED 0
#define ST_STOPPED 1
#define ST_DELAYED 2
#define ST_WAITING 3
#define ST_ELIGIBLE 4
#define ST_RUNNING 5
/* Task flags */
#define F_TIMER 0x80 /* Task is enqueued in timer queue */
#define F_CRIT 0x01 /* Task is critical, may not be preempted */
#define FL_SYSM 0xf0 /* Mask for system flags */
#define FL_USRM 0x0f /* Mask for user flags */
typedef struct tcb_rec far *tcbptr;
typedef tcbptr far *tqueptr;
typedef struct dlink_rec far *dlinkptr;
struct dlink_rec {
dlinkptr follow;
dlinkptr prev;
dword timeout; /* Timeout counter */
tcbptr tcbp;
};
typedef struct dlink_rec dlink;
struct tcb_rec {
tcbptr next; /* Next in queue */
tqueptr queue; /* Queue head pointer */
byteptr stack; /* Task stack */
byteptr stkbot; /* Task stack bottom */
word prior; /* Task priority */
word initprior; /* Initial Task priority */
byte state; /* Task state */
byte flags; /* Task flags */
dlink timerq; /* Timer queue link */
farptr retptr; /* Event return pointer */
int retsize; /* Return buffer size for pipes */
};
typedef struct tcb_rec tcb;
typedef struct {
tcbptr wait_set;
tcbptr wait_clear;
int state;
} flag;
typedef flag far *flagptr;
typedef struct {
tcbptr wait_set;
tcbptr wait_clear;
dword state;
} counter;
typedef counter far *counterptr;
typedef struct {
tcbptr waiting;
tcbptr owner;
int state;
} resource;
typedef resource far *resourceptr;
struct msg_header {
struct msg_header far *next;
};
typedef struct msg_header far *msgptr;
typedef struct {
tcbptr waiting;
msgptr mail_first;
msgptr mail_last;
} mailbox;
typedef mailbox far *mailboxptr;
typedef struct {
tcbptr wait_read;
tcbptr wait_write;
tcbptr wait_clear;
word bufsize;
word filled;
word inptr;
word outptr;
byteptr contents;
} pipe;
typedef pipe far *pipeptr;
typedef struct {
tcbptr wait_read;
tcbptr wait_write;
tcbptr wait_clear;
word bufsize;
word filled;
word inptr;
word outptr;
wordptr wcontents;
} wpipe;
typedef wpipe far *wpipeptr;
typedef struct {
resource buf_write;
resource buf_read;
wpipe pip;
word msgcnt;
} buffer;
typedef buffer far *bufferptr;
extern void far install_tasker (byte varpri, int speedup);
extern void far remove_tasker (void);
extern void far preempt_on (void);
extern void far preempt_off (void);
extern void far schedule (void);
extern void far create_task (tcbptr task, funcptr func, byteptr stack,
word stksz, word prior, farptr arg);
extern void far kill_task (tcbptr task);
extern int far start_task (tcbptr task);
extern int far wake_task (tcbptr task);
extern void far set_priority (tcbptr task, word prior);
extern int far t_delay (dword ticks);
extern void far create_resource (resourceptr rsc);
extern void far delete_resource (resourceptr rsc);
extern void far release_resource (resourceptr rsc);
extern int far request_resource (resourceptr rsc, dword timeout);
extern int far c_request_resource (resourceptr rsc);
extern int far check_resource (resourceptr rsc);
extern void far create_flag (flagptr flg);
extern void far delete_flag (flagptr flg);
extern void far set_flag (flagptr flg);
extern void far clear_flag (flagptr flg);
extern int far wait_flag_set (flagptr flg, dword timeout);
extern int far wait_flag_clear (flagptr flg, dword timeout);
extern int far check_flag (flagptr flg);
extern void far create_counter (counterptr cnt);
extern void far delete_counter (counterptr cnt);
extern void far clear_counter (counterptr cnt);
extern int far wait_counter_set (counterptr cnt, dword timeout);
extern int far wait_counter_clear (counterptr cnt, dword timeout);
extern void far inc_counter (counterptr cnt);
extern dword far check_counter (counterptr cnt);
extern void far create_mailbox (mailboxptr box);
extern void far delete_mailbox (mailboxptr box);
extern void far send_mail (mailboxptr box, farptr msg);
extern farptr far wait_mail (mailboxptr box, dword timeout);
extern farptr far c_wait_mail (mailboxptr box);
extern int far check_mailbox (mailboxptr box);
extern void far create_pipe (pipeptr pip, farptr buf, word bufsize);
extern void far delete_pipe (pipeptr pip);
extern int far read_pipe (pipeptr pip, dword timeout);
extern int far c_read_pipe (pipeptr pip);
extern int far write_pipe (pipeptr pip, byte ch, dword timeout);
extern int far c_write_pipe (pipeptr pip, byte ch);
extern int far wait_pipe_empty (pipeptr pip, dword timeout);
extern int far check_pipe (pipeptr pip);
extern word far pipe_free (pipeptr pip);
extern void far create_wpipe (wpipeptr pip, farptr buf, word bufsize);
extern void far delete_wpipe (wpipeptr pip);
extern word far read_wpipe (wpipeptr pip, dword timeout);
extern word far c_read_wpipe (wpipeptr pip);
extern int far write_wpipe (wpipeptr pip, word ch, dword timeout);
extern int far c_write_wpipe (wpipeptr pip, word ch);
extern int far wait_wpipe_empty (wpipeptr pip, dword timeout);
extern word far check_wpipe (wpipeptr pip);
extern word far wpipe_free (wpipeptr pip);
extern void far create_buffer (bufferptr buf, farptr pbuf, word bufsize);
extern void far delete_buffer (bufferptr buf);
extern int far read_buffer (bufferptr buf, farptr msg, int size, dword timeout);
extern int far c_read_buffer (bufferptr buf, farptr msg, int size);
extern int far write_buffer (bufferptr buf, farptr msg, int size, dword timeout);
extern int far c_write_buffer (bufferptr buf, farptr msg, int size);
extern word far check_buffer (bufferptr buf);
extern word far t_read_key (void);
extern word far t_wait_key (dword timeout);
extern word far t_keyhit (void);
extern int far tsk_dis_int (void);
extern void far tsk_ena_int (int);
extern void far tsk_cli (void);
extern void far tsk_sti (void);
extern void far tsk_nop (void);
extern void far tsk_outp (int port, byte b);
extern byte far tsk_inp (int port);
#define CRITICAL int crit_intsav
#define C_ENTER crit_intsav = tsk_dis_int()
#define C_LEAVE tsk_ena_int (crit_intsav)