Return a dispatch context
#include <sys/dispatch.h>
dispatch_context_t * dispatch_context_alloc
( dispatch_t * dpp );
libc
The dispatch_context_alloc() function returns a dispatch context pointer. The function is passed in the handle dpp from dispatch_create(). The dispatch context is used by dispatch to do its work. It's passed as an argument to dispatch_block() and dispatch_handler().
![]() |
The dispatch_context_alloc() function fails if you haven't attached any events to dispatch yet (e.g. you didn't call message_attach(), resmgr_attach(), or select_attach()). The dispatch library can't allocate a proper context until it knows what kind of events you want to block. |
A pointer to a dispatch context, or NULL if an error occurs (errno is set).
#include <sys/dispatch.h>
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char **argv ) {
dispatch_t *dpp;
dispatch_context_t *ctp;
if( ( dpp = dispatch_create() ) == NULL ) {
fprintf( stderr, "%s: Unable to allocate \
dispatch handle.\n",argv[0] );
return EXIT_FAILURE;
}
⋮
ctp = dispatch_context_alloc( dpp );
⋮
return EXIT_SUCCESS;
}
For examples using the dispatch interface, see dispatch_create(), message_attach(), resmgr_attach(), and thread_pool_create().
| Safety: | |
|---|---|
| Cancellation point | Yes |
| Interrupt handler | No |
| Signal handler | No |
| Thread | Yes |
dispatch_block(), dispatch_context_free(), dispatch_create(), dispatch_handler()
"Components of a Resource Manager" section of the Writing a Resource Manager chapter in the Programmer's Guide.