void mmap_read(struct video_config * self, unsigned char *outbuffer, int write_ppm) { struct video_mbuf vidbuf; int numframe = 0; unsigned char *buffer; ioctl(self->device_fd, VIDIOCGMBUF, &(vidbuf)); buffer = mmap(NULL, vidbuf.size, PROT_READ, MAP_SHARED, (self->device_fd), 0); memset(outbuffer, 0, self->vm.width * self->vm.height * 3); memcpy(outbuffer, buffer, vidbuf.size); self->vm.format = VIDEO_PALETTE_RGB24; self->vm.frame = 0; set_res(self, self->vm.width, self->vm.height); if(ioctl(self->device_fd, VIDIOCMCAPTURE, &(self->vm)) < 0) { printf("Error in VIDIOCMCAPTURE\n"); } if(ioctl(self->device_fd, VIDIOCSYNC, &numframe) < 0) { printf("Error in VIDIOCSYNC\n"); } if(write_ppm) { save_ppm(self, buffer); } }
static inline value alloc_result(PGresult *res, np_callback *cb) { value v_res = caml_alloc_final(3, free_result, 1, 500); set_res(v_res, res); set_res_cb(v_res, cb); np_incr_refcount(cb); return v_res; }
static inline void free_result(value v_res) { PGresult *res; np_decr_refcount(get_res_cb(v_res)); set_res_cb(v_res, NULL); res = get_res(v_res); if (res) { set_res(v_res, NULL); PQclear(res); } }
int run(int iPoolID) { int *pInt = (int*)mgr.GetArg(iPoolID); if (pInt != NULL) { set_res(*pInt); } mgr.Resume(iPoolID); return 0; }
static int mt9v011_reset(struct v4l2_subdev *sd, u32 val) { int i; for (i = 0; i < ARRAY_SIZE(mt9v011_init_default); i++) mt9v011_write(sd, mt9v011_init_default[i].reg, mt9v011_init_default[i].value); set_balance(sd); set_res(sd); set_read_mode(sd); return 0; };
void testfunc() { for (int i = 0 ; i < MAX_CO_COUNT ; ++i) { int id = mgr.Alloc(process, &i , sizeof(int)); //printf("id: %d\n",id); ids.push_back(id); } for (int i = 0 ; i < MAX_CO_COUNT ; ++i) { mgr.Resume(ids[i]); } printf("------------------------------------------------------------\n"); unsigned int t = (unsigned int)time(NULL); (void)t; srand(0); while (1 ) { if (ids.size() == 0) { break; } int idx = rand() % ids.size(); //printf("id: %d/size :%d\n",idx, (int)ids.size()); int *pInt = (int*)mgr.GetArg(ids[idx]); if (pInt != NULL) { set_res(*pInt); } int iRet = mgr.Resume(ids[idx]); if (iRet == 0) { std::vector<int>::iterator ite = ids.begin(); std::advance(ite, idx); ids.erase(ite); } } ids.clear(); }
/* Buffer should be width * height * 3 */ void read_read(struct video_config * self, unsigned char *buffer, int write_ppm) { /* unsigned char *buffer; */ int len = 0; set_res(self,self->vm.width,self->vm.height); /* buffer = malloc(vm.width * vm.height * 3); */ len = read(self->device_fd, buffer, self->vm.width * self->vm.height * 3); if(write_ppm) { save_ppm(self, buffer); } /* free(buffer); */ }
static int mt9v011_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt) { struct mt9v011 *core = to_mt9v011(sd); int rc; rc = mt9v011_try_mbus_fmt(sd, fmt); if (rc < 0) return -EINVAL; core->width = fmt->width; core->height = fmt->height; set_res(sd); return 0; }
static int mt9v011_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt) { struct v4l2_pix_format *pix = &fmt->fmt.pix; struct mt9v011 *core = to_mt9v011(sd); int rc; rc = mt9v011_try_fmt(sd, fmt); if (rc < 0) return -EINVAL; core->width = pix->width; core->height = pix->height; set_res(sd); return 0; }
t_content *set_mod(t_op *operation, t_shunting *stack) { t_content *op1; t_content *op2; t_content *sym; char *res; op2 = pop_front_elem(stack->operator_stack); op1 = pop_front_elem(stack->operator_stack); sym = pop_front_elem(operation->postfix_notation); if ((res = modulo_operation(op1->content, op2->content, operation)) == NULL) return (NULL); if ((res = uniform_sym(op1->content, op2->content, res, operation->operators[3])) == NULL) return (NULL); free_node(op1); free_node(op2); free_node(sym); return (set_res(res, operation)); }
void testperformance() { printf("testperformance \n"); for (int i = 0 ; i < MAX_CO_COUNT ; ++i) { int id = mgr.Alloc(process1, &i , sizeof(int)); //printf("id: %d ",id); ids.push_back(id); } for (int i = 0 ; i < MAX_CO_COUNT ; ++i) { mgr.Resume(ids[i]); } time_t t = (unsigned int)time(NULL); srand(t); struct timeval starttime ; gettimeofday(&starttime, NULL); while (1 ) { if ((int)ids.size() != MAX_CO_COUNT) { printf("ids.size() != MAX_CO_COUNT"); assert((int)ids.size() == MAX_CO_COUNT); } int idx = rand() % ids.size(); //printf("id: %d/size :%d\n",idx, (int)ids.size()); int *pInt = (int*)mgr.GetArg(ids[idx]); if (pInt != NULL) { set_res(*pInt); } int iRet = mgr.Resume(ids[idx]); if (iRet == 0) { if (assertvalue != idx*loopcount) { printf("assertvalue != idx*loopcount"); assert(assertvalue == idx*loopcount); } ids[idx] = mgr.Alloc(process1, &idx , sizeof(int)); } static uint64_t ii =0; if (ii%100000 == 0) { struct timeval now ; gettimeofday(&now, NULL); float diff = (now.tv_sec-starttime.tv_sec) + ((now.tv_usec - starttime.tv_usec))/1000000.f; printf("count %lu, tps %f, time:%f\n",ii, (float)ii / diff, diff); starttime = now; printf("%lu\n", ii); ii = 0; } ++ii; } }