1 / 16

Message Buffer

Message Buffer. Nguyễn Hoàng Tâm 50702111 Nguyễn Văn Trọng 50702651. Using message buffer. Synchronization and communication : Passing variable-size messages Holding messages for sending and receiving

aminia
Download Presentation

Message Buffer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Message Buffer Nguyễn Hoàng Tâm 50702111 Nguyễn Văn Trọng 50702651

  2. Using message buffer • 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).

  3. Message sender and receipt • 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

  4. 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

  5. Synchronous Communication by Message Buffer

  6. Functions 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 )

  7. 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

  8. 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 )

  9. 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)

  10. 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

  11. 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

  12. 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)

  13. 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

  14. 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

  15. 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)

  16. 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

More Related