Hi!
I have just run a multi-threaded device resource manager but perhaps there is a mysterious
I want to know what thread_pool_start actually does.
I'm sorry! I increased font size to be easy to view.
Code:
thread_pool_attr_t pool_attr;
.......................................
pool_attr.handle = dpp;
pool_attr.context_alloc = (void*)dispatch_context_alloc;
pool_attr.block_func =(void*)dispatch_block;
pool_attr.unblock_func =(void*)dispatch_unblock;
pool_attr.handler_func = (void*)dispatch_handler;
pool_attr.context_free = (void*) dispatch_context_free;
I guess:
-At the first, dispatch_context_alloc is called and it need a dispatch_t argument . This argument is pool_attr.handle
- and then, thread_pool_start calls dispatch_block but this function needs a dispatch_context_t argument. But I don't know what will be used as a argument for this funciton.
- and the same question for dispatch_unblock, dispatch_handler
I viewed fields of thread_pool_attr_. This structure has not any dispatch_context_t field
Code:
#ifndef THREAD_POOL_PARAM_T
#define THREAD_POOL_PARAM_T void
#endif
#ifndef THREAD_POOL_HANDLE_T
#define THREAD_POOL_HANDLE_T dispatch_t
#endif
typedef struct _thread_pool_attr {
THREAD_POOL_HANDLE_T *handle;
THREAD_POOL_PARAM_T *(*block_func)(THREAD_POOL_PARAM_T *ctp);
void (*unblock_func)(THREAD_POOL_PARAM_T *ctp);
int (*handler_func)(THREAD_POOL_PARAM_T *ctp);
THREAD_POOL_PARAM_T *(*context_alloc)(THREAD_POOL_HANDLE_T *handle);
void (*context_free)(THREAD_POOL_PARAM_T *ctp);
pthread_attr_t *attr;
unsigned short lo_water;
unsigned short increment;
unsigned short hi_water;
unsigned short maximum;
unsigned reserved[8];
} thread_pool_attr_t;
The only field which can be used is pthread_attr_t *attr;
And this is fields of the structure:
Code:
#if defined(__PTHREAD_ATTR_T)
typedef __PTHREAD_ATTR_T pthread_attr_t;
#undef __PTHREAD_ATTR_T
#endif
Code:
#define __PTHREAD_ATTR_T \
struct _thread_attr { \
int flags; \
_Sizet stacksize; \
void *stackaddr; \
void (*exitfunc)(void *status); \
int policy; \
struct sched_param param; \
unsigned guardsize; \
unsigned prealloc; \
int spare[2]; \
}
Code:
dispatch_context_t *dispatch_context_alloc(dispatch_t *dpp);
dispatch_context_t *dispatch_block(dispatch_context_t *ctp);
void dispatch_unblock(dispatch_context_t *ctp);
int dispatch_handler(dispatch_context_t *ctp);
void dispatch_context_free(dispatch_context_t *ctp);
|