⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmtlib.man

📁 简单实现多任务的C语言库 可以实现各个任务间的简单的消息通讯
💻 MAN
字号:
NAME
	cmt_pause - give away timeslice

SYNOPSIS
	#include "cmtlib.h"

	void far cdecl cmt_pause(void)

DESCRIPTION
	this function switches to next task in the task list and
	returns after all other tasks have gotten their share of
	the CPU time. as our the multitasker is cooperative, this
	function should be called as often as possible to keep
	things alive. as for all cooperative multitaskers, task
	switch overhead is very small and will not waste a lot of
	cycles.

NOTES
	do not use any 'tight loops' in your code without invoking
	cmt_pause() from time to time unless you really mean it,
	because you program will not multitask in this case.
NAME
	cmt_fork - create a new task

SYNOPSIS
	#include "cmtlib.h"

	CMT_TASK far * cdecl cmt_fork(void far cdecl (*task)(void),
		unsigned int stacksize)

DESCRIPTION
	this function creates a new task. in our context, task
	is simply a normal C function which takes no parameters
	and does not return anything. the new task gets it's own
	stack of the specified size (in bytes). if stacksize is
	0, then the default CMT_DEFAULTSTACKSIZE is used. the
	created task is placed in the task list as the next task
	to be run - next cmt_pause() switches to last task created.

DIAGNOSTICS
	this function returns pointer to new task or NULL
	if the task can not be created.

NOTES
	due the way Borland's FP emulator is implemented, you cannot
	do any floating point operations in forked tasks if you don't
	have FP coprecessor (more precisely, FP emulator allocates
	it's workspace from the 'system' stack and assumes that
	SS never changes).
NAME
	cmt_send - send a message to another task

SYNOPSIS
	#include "cmtlib.h"

	int far cdecl cmt_send(void far *msg,CMT_TASK far *task)

DESCRIPTION
	this function send one message to given task. as each task
	has room only for one active message, this function fails
	if the task already has a pending message. use cmt_psend()
	to send multiple messages.

DIAGNOSTICS
	if the message was delivered successfully, this function
	returns 1, otherwise it returns 0.
NAME
	cmt_receive - receives a message

SYNOPSIS
	#include "cmtlib.h"

	void far * far cdecl cmt_receive(void)

DESCRIPTION
	this function receives a message send with cmt_send()
	to current task. if there is no penging message, the caller
	blocks until message arrives.

DIGANOSTICS
	returns a received message
NAME
	cmt_recvclr - return a message if there is any

SYNOPSIS
	#include "cmtlib.h"

	void far * far cmt_recvclr(void)

DESCRIPTION
	this function can be used for two different tasks -
	it returns a message if there is one waiting, but
	as a side effect, it also discards any waiting
	messages

DIAGNOSTICS
	returns a message or NULL
NAME
	cmt_recvtim - waits for a message

SYNOPSIS
	#include "cmtlib.h"

	void far * far cdecl cmt_recvtim(unsiged int clocks)

DESCRIPTION
	this message waits for a given number of 10-msec
	intervals for a message to arrive, blocking
	while doing so. note that the actual time delay is
	only precise to 55ms, which is timer tick period on
	PC. the code uses clocks*100/55 to get a number of
	timer ticks it should wait.

DIAGNOSTICS
	returns a message or NULL
NAME
	cmt_screate - create a semaphore

SYNOPSIS
	#include "cmtlib.h"

	CMT_SEM far * far cdecl cmt_screate(int initcount)

DESCRIPTION
	allocates space for semaphore and initializes it to the
	given value.

DIAGNOSTICS
	returns pointer to new semaphore or NULL.
NAME
	cmt_sdelete - discard a semaphore

SYNOPSIS
	#include "cmtlib.h"

	CMT_SEM far * far cdecl cmt_sdelete(CMT_SEM far *sem)

DESCRIPTION
	discards a semaphore

DIAGNOSTICS
	always returns NULL
NAME
	cmt_wait - wait on semaphore

SYNOPSIS
	#include "cmtlib.h"

	void far cdecl cmt_wait(CMT_SEM far *sem)

DESCRIPTION
	this function waits for a signal on semaphore. in our
	system this means decrementing semaphore value and
	then blocking until semaphore value goes back to 0.
NAME
	cmt_signal - set a semaphore

SYNOPSIS
	#include "cmtlib.h"

	void far cdecl cmt_signal(CMT_SEM far *sem)

DESCRIPTION
	this function sets a 'signal' flag on semaphore. in our
	system we just incement semaphore value.
NAME
	cmt_tsart - starts a timer

SYNOPSIS
	#include "cmtlib.h"

	void far cdecl cmt_tstart(CMT_TIMER far *t,unsigned long ticks)

DESCRIPTION
	this function starts a timer countdown on the given
	timer for given number of 55 ms clock ticks.
NAME
	cmt_texpired - check if the timer has expired

SYNOPSIS
	#include "cmtlib.h"

	int far cdecl cmt_texpired(CMT_TIMER far *t)

DESCRIPTION
	this function check if the given timer has expired.

DIAGNOSTICS
	returns 1 if the timer has expired, 0 if it is not.
NAME
	cmt_expire - force timer to expire

SYNOPSIS
	#include "cmtlib.h"

	void far cdecl cmt_expire(CMT_TIMER far *t)

DESCRIPTION
	this function immidiately expires the given timer.
NAME
	cmt_sleep - blocks a task for given number of seconds

SYNOPSIS
	#include "cmtlib.h"

	void far cdecl cmt_sleep(unsigned int seconds)

DESCRIPTION
	this is a sleep function it goes into loop giving away
	the calling task's timeslice and waiting for a given
	number of seconds to pass by.

	if number of seconds is 0, cmt_sleep equals to cmt_pause
NAME
	cmt_pcreate - create a message port

SYNOPSIS
	#include "cmtlib.h"

	CMT_PORT far * far cdecl cmt_pcreate(int size)

DESCRIPTION
	this function creates a message port for a given number
	of messages. in our multitasker, messages are always
	void far pointers, the given size indicates how many pointers
	this port can hold.

DIAGNOSTICS
	returns pointer to newly created port or NULL
NAME
	cmt_pdelete - discards a message port

SYNOPSIS
	#include "cmtlib.h"

	CMT_PORT far * far cdecl cmt_pdelete(CMT_PORT far *port)

DESCRIPTION
	this function discards a message port.

DIAGNOSTICS
	always returns NULL

NOTES
	this function does not check if the port has any
	pending messages (which would be lost after the port
	is discarded).
NAME
	cmt_psend - sends a message to port

SYNOPSIS
	#include "cmtlib.h"

	void far cdecl cmt_psend(CMT_PORT far *port,void far *message)

DESCRIPTION
	send a message to message port. if the port is full, this
	function blocks until there is room for another message.
NAME
	cmt_psendnobl - sends a message to port, not blocking

SYNOPSIS
	#include "cmtlib.h"

	int far cdecl cmt_psendnobl(CMT_PORT far *port,void far *message)

DESCRIPTION
	tries to send a message to message port

DIAGNOSTICS
	returns 1 if the message is successfully delivered or 0 if the
	port is full
NAME
	cmt_preceive - receive a message from port

SYNOPSIS
	#include "cmtlib.h"

	void far * far cdecl cmt_preceive(CMT_PORT far *port)

DESCRIPTION
	receives a message from a port. blocks until a message
	becomes avaiable

DIAGNOSTICS
	returns a message
NAME
	cmt_pcount - returns number of messages in the port

SYNOPSIS
	#include "cmtlib.h"

	int far cdecl cmt_pcount(CMT_PORT far *port)

DESCRIPTION
	this function simply returns a number of messages
	that are waiting delivery in the port.

DIAGNOSTICS
	returns number of pending messages
NAME
	cmt_malloc - allocate memory for cmt engine

SYNOPSIS
	#include "cmtlib.h"

	void far * far cdecl cmt_malloc(unsigned size);

DESCRIPTION
	cmt_malloc is a memory allocator wrapper function that
	allocates memory for cmt use. this includes task stacks.
	the library version of this function maps directly to 
	farmalloc()

DIAGNOSTICS
	returns far pointer to newly allocated memory block, or
	NULL
NAME
	cmt_free - discards memory block allocated by cmt_malloc

SYNOPSIS
	#include "cmtlib.h"

	void far cdecl cmt_free(void far *block);

DESCRIPTION
	memory deallocator. library version maps directly to
	farfree().
NAME
	CMT_TASK - task structure

DESCRIPTION
	CMT_TASK is a basic task structure, each forked task gets
	one created for it. the structure has following elements:

	  CMT_TASK far *next,far *prev;
		pointers for creating double-linked task list.
		next points to task that will run next when the
		cmt_pause() is called. If cmt_fork() is ever
		used, then there will always be one task which
		will never terminate, if all forked tasks terminte
		then system task's link pointers will point to
		itself.
	
	  unsigned short far *stack;
		pointer to stack storage. cmt_fork allocates
		stack space for new tasks using cmt_malloc()

	  unsigned short id;
		task ID

	  unsigned short ss,sp;
		current stack pointer and segment for this task

	  void far *message;
		storage for message

	  void far (*entertask)(void);
	  void far (*leavetask)(void);
	  void far (*killtask)(void);

		these 3 are user-defined handers which are called
		with following conditions being true:

		entertask: _cmtactivetask points to task about to
		be run, stack is switched to this task's stack.

		leavetask: _cmtactivetask still points to task
		which cmt_pause()-d and stack is not switched yet.

		killtask: _cmtactivetask points to task which is
		about to die, stack still points to this task's stack.
		
		you can set these handlers after the cmt_fork() as
		cmt_fork only creates the task. There is one exception -
		on the first cmt_fork(), the system task is automatically
		created and _cmtsystemtask is set to point at it.


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -