Next: , Previous: , Up: Exchanging Data Packets in a Multithreaded Program   [Contents][Index]


6.4.2 Exchanging Data Packets Between Sides

The following function sends a data packet from one side to the other side.

Function: int qsmm_side_send (qsmm_side_t side_from, qsmm_side_t side_to, size_t data_sz, const void *data_p)

This function sends a data packet of size data_sz (in bytes) addressed by data_p from one side to the other side. A side that sends the data packet is specified by handle side_from. A side that should receive the data packet is specified by handle side_to. The data packet is appended to the end of the queue of received data packets of side side_to. If a thread where side side_to is executed has called the function qsmm_side_recv and is waiting for a new data packet to receive, then the thread will resume execution, and that function will return the data packet just received.

On success, the function returns a non-negative value. If there is not enough memory to perform the operation, then negative error code QSMM_SIDE_ERR_NOMEM will be returned.

The following function receives a data packet.

Function: int qsmm_side_recv (qsmm_side_t side, size_t bufsz, void *bufp)

This function retrieves a data packet from the queue of received data packets of side. The data packet is stored in buffer bufp of size bufsz (in bytes). If bufsz is greater than the size of the data packet retrieved, then the remaining content of buffer bufp will be left intact. If there is no data packet to retrieve, then the function will block until another thread sends a data packet to side.

On success, the function returns a non-negative number equal to the size (in bytes) of a data packet retrieved or INT_MAX, whichever is lesser. If bufsz is less than the size of a data packet to be retrieved, or if bufsz is non-zero and bufp is NULL, then the function will return negative error code QSMM_SIDE_ERR_INVAL.

To send a data packet from one side to the other side, it is recommended to use the following macro.

Macro: QSMM_SIDE_SEND (from, to, msg)

This macro sends data packet msg from one side to the other side. A side that sends the data packet is specified by side handle from. A side that should receive the data packet is specified by side handle to. The macro is expanded to:

qsmm_side_send((from), (to), sizeof(msg), &(msg))

Macro argument msg must be a variable, not a constant. For example, to send signal 1 from one side to the other side, the following lines of code could be used:

qsmm_sig_t sig_out=1;
QSMM_SIDE_SEND(side_from,side_to,sig_out);

To receive a data packet, it is recommended to use the following macro.

Macro: QSMM_SIDE_RECV (side, msgp)

This macro retrieves a data packet from the queue of received data packets of side. The data packet is stored in variable *msgp. The macro is expanded to:

qsmm_side_recv((side), sizeof(*(msgp)), (msgp))

For example, to receive a signal sent to a side, the following lines of code could be used:

qsmm_sig_t sig_in=QSMM_SIG_INVALID;
QSMM_SIDE_RECV(side,&sig_in);

Next: , Previous: , Up: Exchanging Data Packets in a Multithreaded Program   [Contents][Index]