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 a side to another side.

Function: int qsmm_side_send (qsmm_side_t side_from, qsmm_side_t side_to, size_t sz, const void *msgp)

This function sends a data packet occupying sz bytes and addressed by msgp from a side side_from to a side side_to. The function appends the data packet to the end of the queue of received data packets of side_to. If another thread called the function qsmm_side_recv for side_to and is waiting for a data packet to receive, the thread resumes execution, and that function returns the data packet just received.

On success, the function returns a non-negative value. If there was not enough memory to perform the operation, the function returns negative error code QSMM_ERR_NOMEM.

The following function receives a data packet.

Function: int qsmm_side_recv (qsmm_side_t side, size_t sz, void *msgp)

This function retrieves a data packet from the queue of received data packets of side and stores the data packet in a buffer msgp with size sz bytes. If sz is greater than the size of this data packet, the function leaves the remaining content of msgp unchanged. If there is no data packet to retrieve, the function blocks until another thread sends a data packet to side.

On success, the function returns a non-negative number of bytes occupied by a retrieved data packet or INT_MAX if this number is greater than INT_MAX. If sz is less than the size of the data packet in the queue, or if sz is positive, and msgp is NULL, the function returns negative error code QSMM_ERR_INVAL.

Use the following macro to send a data packet from a side to another side.

Macro: QSMM_SIDE_SEND (from, to, msg)

This macro sends a data packet stored in a variable msg from a side from to a side to. The macro expands to:

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

The macro argument msg must be a variable and not a constant, as the macro takes the address of that argument using ‘&’. For example, to send signal 1 from a side side_from to a side side_to, use lines of code like these:

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

Use the following macro to receive a data packet.

Macro: QSMM_SIDE_RECV (side, msgp)

This macro retrieves a data packet from the queue of received data packets of side and stores the data packet in a variable *msgp. The macro expands to:

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

For example, to receive a signal sent to a side, use lines of code like these:

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]