📄 cmtmsg.c
字号:
#include "cmtlib.h"
/* ----------------------------------------------------------------
** Messages.
** ----------------------------------------------------------------
*/
/*man**************************************************************
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.
******************************************************************/
int far cdecl cmt_send(void far *msg,CMT_TASK far *task)
{
if (!task->message) {
task->message=msg;
return 1;
}
return 0;
}
/*man**************************************************************
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
******************************************************************/
void far * far cdecl cmt_receive(void)
{
void far *m;
while (!_cmtactivetask->message)
cmt_pause();
m=_cmtactivetask->message;
_cmtactivetask->message=NULL;
return m;
}
/*man**************************************************************
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
******************************************************************/
void far * far cdecl cmt_recvclr(void)
{
void far *m;
m=_cmtactivetask->message;
_cmtactivetask->message=NULL;
return m;
}
/*man**************************************************************
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
******************************************************************/
void far * far cdecl cmt_recvtim(unsigned int clocks)
{
CMT_TIMER t;
void far *m;
cmt_tstart(&t,((unsigned long)clocks*100L/55L));
while (!_cmtactivetask->message && !cmt_texpired(&t))
cmt_pause();
m=_cmtactivetask->message;
_cmtactivetask->message=NULL;
return m;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -