那位有资源管理器的例子源程序
这个是最基本的。
#include <stdio.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <sys/neutrino.h>
#include <sys/resmgr.h>
dispatch_t *dpp;
int res_id;
int main()
{
thread_pool_attr_t pool_attr;
thread_pool_t *tpp;
resmgr_attr_t res_attr;
resmgr_io_funcs_t io_funcs;
resmgr_connect_funcs_t cf;
iofunc_attr_t attr;
memset(&pool_attr, 0, sizeof pool_attr);
if ((pool_attr.handle = dpp = dispatch_create()) == NULL) {
perror("dispatch_create");
return -1;
}
pool_attr.context_alloc = (void *)dispatch_context_alloc;
pool_attr.block_func = (void *)dispatch_block;
pool_attr.handler_func = (void *)dispatch_handler;
pool_attr.context_free = (void *)dispatch_context_free;
pool_attr.lo_water = 2;
pool_attr.hi_water = 3;
pool_attr.increment = 1;
pool_attr.maximum = 5;
if(!(tpp = thread_pool_create(&pool_attr, POOL_FLAG_EXIT_SELF))) {
perror("thread_pool_create");
return -1;
}
memset(&res_attr, 0x00, sizeof res_attr);
res_attr.nparts_max = 10;
iofunc_attr_init(&attr, S_IFNAM | 0666, 0, 0);
iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &cf,
_RESMGR_IO_NFUNCS, &io_funcs);
if((res_id = resmgr_attach(dpp, &res_attr, "/dev/mymgr",
_FTYPE_ANY, 0, &cf, &io_funcs, &attr)) == -1) {
perror("resmgr_attach(/dev/mymgr)");
return -1;
}
return thread_pool_start(tpp);
}