resmgr_block()

Updated: April 19, 2023

Block while waiting for a message

Synopsis:

#include <sys/iofunc.h>
#include <sys/dispatch.h>

resmgr_context_t* resmgr_block( resmgr_context_t * ctp );

Arguments:

ctp
A pointer to a resmgr_context_t structure that the resource-manager library uses to pass context information between functions.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The resmgr_block() function waits for a message (created by a call to resmgr_context_alloc()) for context ctp.

Note: This function is a special case of dispatch_block() that you should use only with a simple resource manager. If you need to attach pulses or other messages, then you should use dispatch_block().

Returns:

The same pointer as ctp, or NULL if an error occurs (errno is set).

Errors:

EFAULT
A fault occurred when the kernel tried to access the buffers provided. Because the OS accesses the sender's buffers only when MsgReceive() is called, a fault could occur in the sender if the sender's buffers are invalid. If a fault occurs when accessing the sender buffers (only) they'll receive an EFAULT and the MsgReceive() won't unblock.
EINTR
The call was interrupted by a signal.
ETIMEDOUT
A kernel timeout (that was set with dispatch_timeout()) unblocked the call.

Examples:

#include <sys/dispatch.h>
#include <stdio.h>
#include <stdlib.h>

int main( int argc, char **argv ) {
   dispatch_t          *dpp;
   resmgr_context_t    *ctp;

   if ((dpp = dispatch_create()) == NULL) {
      fprintf( stderr, "%s: Unable to allocate \
               dispatch handle.\n",argv[0] );
      return EXIT_FAILURE;
   }

   …

   ctp = resmgr_context_alloc( dpp );

   while (1) {
     if ( ( ctp = resmgr_block( ctp )) == NULL ) {
        fprintf( stderr, "block error\n" );
        return EXIT_FAILURE;
     }
     resmgr_handler( ctp );
   }
}

For examples using the dispatch interface, see dispatch_create(), message_attach(), resmgr_attach(), and thread_pool_create().

Classification:

QNX Neutrino

Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

Caveats:

Use resmgr_block() only in a simple resource manager and when you don't use message_attach(), pulse_attach(), or select_attach().