nguy ễ n hoàng tâm50702111 nguy ễ n văn tr ọ ng50702651
TRANSCRIPT
Message Buffer
Nguyễn Hoàng Tâm 50702111Nguyễn Văn Trọng 50702651
Synchronization and communication :◦ Passing variable-size messages◦ Holding messages for sending and receiving◦ 2 queues : messages waiting to be sent ( send
queue),tasks waiting for messages receipt ( receive queue).
Using message buffer
Sender : ◦ Copy message to buffer◦ If not enough space :
message is queued for sending until enough space is available.
task waiting to send is put in send queue
Message sender and receipt
Receipt :◦ Message is fetched from buffer◦ If buffer has no messages : task enter Wait state
and put in receive queue What if buffer size is 0 :
◦ Message communication function is synchronous◦ Task wait for system call to be invoked◦ Message is passed when both side issue system
call
Message sender and receipt
Synchronous Communication by Message Buffer
tk_cre_mbf : create message buffer ID mbfid = tk_cre_mbf(T_CMBF *pk_cmbf) pk_cmbf details :
◦ VP exinf Extended informations◦ ATR mbfatr Message buffer attributes◦ INT bufsz Message buffer size ( in bytes )◦ INT maxmsz Maximun massage size (in
bytes )
Functions
Error code :- E_OK Normal completion- E_NOMEM Insufficient memory (memory for control block or ring buffer area cannot be allocated)- E_LIMIT Number of message buffers exceeds the system limit- E_RSATR Reserved attribute (mbfatr is invalid or cannot be used)- E_PAR Parameter error (pk cmbf is invalid, or bufsz or maxmsz is negative or invalid) mbfatr :- TA_TFIFO Tasks waiting to send are queued in FIFO order- TA_TPRI Tasks waiting to send are queued in priority order- TA_NODISWAI Wait disabling by tk dis wai is prohibited
Functions
Notes :◦ Tasks waiting for a message to be sent can be
designated in TA_FIFO or TA_PRI◦ Messages are queued in FIFO order only◦ Tasks waiting for message receipt are queued in
FIFO order only◦ When there’re multiple tasks waiting to send , the
order will always be obeyed in spite of buffer space ( enough or not )
Functions
tk_del_mbf : delete message buffer ER recd = tk_del_mbf(ID mbfid)
Error code :- E_OK : Normal completion- E_ID : Invalid ID number (mbfid is invalid or cannot be used)- E_NOEXS : Object does not exist (the message buffer designated in mbfid does not exist)
Functions
When this functions is called : Release : message buffer space and control
block If there’re tasks queued in message buffer,
error code E_DLT returned to the tasks in Wait state
If there’re message in buffer, it is deleted and no error code is returned
Functions
tk_snd_mbf : send message to message buffer ER ercd = tk_snd_mbf ( ID mbfid, VP msg,
INT msgsz, TMO tmout ) Parameter :
- ID mbfid Message buffer ID- INT msgsz Send message size (in bytes)- VP msg Start address of send message packet- TMO tmout Timeout designation
Functions
Error code :- E_OK :Normal completion- E_ID :Invalid ID number (mbfid is invalid or cannot be used)- E_NOEXS : Object does not exist (the message buffer designated in mbfid does not exist)- E_PAR : Parameter error (msgsz · 0, msgsz > maxmsz,value that cannot be used in msg, or tmout · (¡2))- E_DLT : The object being waited for was deleted (message buffer was deleted while waiting)- E_RLWAI : Wait state released (tk rel wai received in wait state)- E_DISWAI : Wait released by wait disabled state- E_TMOUT : Polling failed or timeout- E_CTX : Context error (issued from task-independent portion or in dispatch disabled state)
Functions
Descriptions :◦ Copy msgsz bytes starting at mgz to message queue
of message buffer◦ If msgsz is larger than maxmsz , error code is
returned◦ If not enough space, task issued this system call goes
to wait state◦ If tmout elapses before wait state releases , system
call terminates and return error code ◦ When tmout = T_POL , if there’s enough space, error
code return without entering wait state◦ When tmout = T_FEVR , task continues to wait for
buffer space become available
Functions
tk_recv_mbf : receive message buffer INT msgsz = tk_rcv_mbf ( ID mbfid, VP msg,
TMO tmout ) Return message size or error code- Parameter, error code : similar to tk_snd_mbf
Functions
tk_ref_mbf : get message buffer status ER ercd = tk_ref_mbf ( ID mbfid, T_RMBF
*pk_rmbf ) Pk_rmbf details :
◦ VP exinf :Extended information◦ ID wtsk :Waiting task information◦ ID stsk :Send task information◦ INT msgsz :Size of the next message to be
received (in bytes)◦ INT frbufsz :Free buffer size (in bytes)◦ INT maxmsz :Maximum message size (in bytes)
Functions
Descriptions :◦ Reference the status of message buffer◦ If multiple tasks are waiting , return the ID of task
at the head of queue◦ If no task waiting , 0 is returned◦ If there’s no message at the queue, msgsz = 0 is
returned
Functions