New Function srv_msgq_set_blocking_threshold in Open Server

A new API function, srv_msgq_set_blocking_threshold(), allows you to set a threshold for the number of messages that can be stored in the message queue without blocking the sending thread.

Syntax

CS_RETCODE srv_msgq_set_blocking_threshold(SRV_OBJID mqid, CS_INT threshold)

Parameters

  • mqid

    the identifier for the message queue on which to set the blocking threshold.

  • threshold

    the maximum number of messages that may be put in the message queue without blocking the sending thread; or CS_NO_LIMIT to specify no threshold.

Return Value

Returns

Indicates

CS_SUCCEED

The threshold is set correctly.

CS_FAIL

The threshold is not set correctly.

Usage Example

/* 
** We want the threads to block if there are already 10 messages 
** in the queue. 
*/ 
ret = srv_msgq_set_blocking_threshold(mqid, 10);

Notes

  • The default value (when srv_msgq_set_blocking_threshold() has not been called) is CS_NO_LIMIT.
  • Set the threshold to CS_NO_LIMIT for message queue behavior as in earlier versions of Open Server. srv_putmsgq() will not block but will fail when the server wide maximum number of messages have been stored. The server-wide maximum number of messages is specified with the SRV_S_MSGPOOL property.
  • Setting the threshold to 0 (zero) causes every call to srv_putmsgq() for this message queue to be blocked until the message is retrieved with srv_getmsgq().
  • The threshold cannot be set to a negative value other than CS_NO_LIMIT.
  • The threshold cannot be set to a value that is larger than the server-wide maximum number of messages that can be stored in a message queue. The server-wide maximum number of messages is specified with the SRV_S_MSGPOOL property.
  • If the threshold is set to a value that is fewer than the current number of messages in the queue, adding new messages blocks the calling thread until enough messages have been removed from the queue and the new limit has been reached.
  • If the threshold is set to a value that is higher than the current number of messages in the queue, the blocked threads are unblocked one by one when messages are removed from the queue.
  • Calls to srv_putmsgq() with the SRV_M_WAIT flag do not count for the threshold value. Usage of this flag already causes the caller to block since they wait until the message itself is retrieved again from the queue.