int tsload_create_threadpool(const char* tp_name, unsigned num_threads, ts_time_t quantum, const char* disp_name) { thread_pool_t* tp = NULL; if(num_threads > TPMAXTHREADS || num_threads == 0) { tsload_error_msg(TSE_INVALID_DATA, "Too much or zero threads requested (%u, max: %u)", num_threads, TPMAXTHREADS); return TSLOAD_ERROR; } if(quantum < tp_min_quantum) { tsload_error_msg(TSE_INVALID_DATA, "Too small quantum requested (%lld, max: %lld)", quantum, tp_min_quantum); return TSLOAD_ERROR; } tp = tp_search(tp_name); if(tp != NULL) { tsload_error_msg(TSE_INVALID_DATA, "Thread pool '%s' already exists", tp_name); return TSLOAD_ERROR; } tp = tp_create(tp_name, num_threads, quantum, disp_name); if(tp == NULL) { tsload_error_msg(TSE_INTERNAL_ERROR, "Internal error occured while creating threadpool"); return TSLOAD_ERROR; } return TSLOAD_OK; }
int main(int argc, char **argv){ pTp= tp_create(10, THD_NUM); int i; exit_cnt = 0; pthread_mutex_init(&lock, NULL); tp_init(pTp); srand((int)time(0)); for(i=0; i < THD_NUM; i++){ tp_process_job(pTp, proc_fun, i); } tp_run(pTp); free(pTp); fprintf(stdout, "All jobs done!\r\n"); return 0; }
int main(int argc, char *argv[]) { SDL_Surface *screen; TPool *tpool; CIList *cil; CImage *ci; int i, ch; unsigned int rw, rh; // requested window size unsigned long int fcount, do_jpeg; double ticks_start, load_fade, aspect; /* Copyright notice */ printf("\n Continuous Imaging 'fly'\n Copyright (C) 2008-2012 David Lowy & Tom Rathborne\n\n"); /* Get options --jpeg / -j and --geometry / -g */ static struct option longopts[] = { { "jpeg", no_argument, NULL, 'j' }, { "geometry", required_argument, NULL, 'g' }, { NULL, 0, NULL, 0 } }; /* Defaults */ do_jpeg = 0; rw = 0; rh = 0; while ((ch = getopt_long(argc, argv, "jg:", longopts, NULL)) != -1) switch(ch) { case 'j': do_jpeg = 1; break; case 'g': if (sscanf(optarg, "%ux%u", &rw, &rh) != 2) { printf("Unhandled geometry '%s': format is WxH\n", optarg); rw = 0; rh = 0; } break; default: printf("Unrecognized option %c ignored\n", ch); } argc -= optind; argv += optind; /* Get SDL+GL screen */ screen = init_sdl_gl(CI_BPC, CI_BITS, rw, rh); if(!screen) { fprintf(stderr, "Failed to init SDL GL context.\n"); return (0); } #ifndef CI_LINUX SDL_ShowCursor(SDL_DISABLE); #endif SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); /* Set up JPEG if necessary */ if (do_jpeg) jpeg_alloc(screen->w, screen->h); aspect = CI_ASPECT / ((double)screen->w / (double)screen->h); /* time entire program */ ticks_start = SDL_GetTicks(); /* Init texture pool */ tpool = tp_create(65535, 800); // This was supposed to keep fewer textures in VRAM, but it just fills VRAM. /* create CI List */ cil = cil_create(tpool, "thumb/%s.jpg", "image/%s.jpg"); /* Load all dbs, make links */ cil_load_scidb(cil, "cidb.db"); /* Load image data and textures - and draw 'em! */ for(i = 0; i < cil->rcount; i++) { ci = cil->list[i]; assert(ci); assert(ci->subs); cil_ci_imgprep(cil, ci, 0); /* load images to N levels */ ci_load_tx(ci, 0); /* load textures to N level */ // Render load_fade = sqrt(1.0 - ((double) i / (double) cil->rcount)); glLoadIdentity(); glScalef(load_fade, load_fade / aspect, 1.0); // glRotatef(360.0 * ((double) i / (double) cil->rcount), 0.0, 0.0, 1.0); glTranslatef(-0.5, -0.5, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor4f(1.0, 1.0, 1.0, sqrt(load_fade)); glBindTexture(GL_TEXTURE_2D, ci->tid); glCallList(cil->gl_list); SDL_GL_SwapBuffers(); } for(i = 0; i < cil->rcount; i++) { ci = cil->list[i]; assert(ci); assert(ci->subs); ci_mklist(ci, cil->gl_list); } printf("Startup took %.2fs.\n", (SDL_GetTicks() - ticks_start) / 1000.0); /* Main loop */ ticks_start = SDL_GetTicks(); SDL_WarpMouse(screen->w/2, screen->h/2); SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE); fcount = fly(screen, cil, do_jpeg); printf("Average FPS: %.2f\n", fcount * 1000.0 / (SDL_GetTicks() - ticks_start)); printf("Cleaning up ...\n"); cil_cleanup(cil); /* cleanup */ cil_delete(cil); /* drop our data */ tp_delete(tpool); /* JPEG cleanup */ if (do_jpeg) jpeg_free(); SDL_Quit(); return (0); }
int main(void) { int stdin_size; char *stdin_mem = read_stdin(&stdin_size); int cpu_count = get_cpu_count(); char output_buffer[7][MAX_OUTPUT]; # define DECLARE_PARAM(o, n) {\ .start = stdin_mem, \ .length = stdin_size, \ .frame = n,\ .output = output_buffer[o],\ .output_size = MAX_OUTPUT } struct print_freqs_param freq_params[2] = { DECLARE_PARAM(0, 1), DECLARE_PARAM(1, 2) }; # undef DECLARE_PARAM # define DECLARE_PARAM(o, s) {\ .start = stdin_mem, \ .length = stdin_size, \ .nuc_seq = s,\ .output = output_buffer[o],\ .output_size = MAX_OUTPUT } struct print_occurences_param occurences_params[5] = { DECLARE_PARAM(2, "GGT"), DECLARE_PARAM(3, "GGTA"), DECLARE_PARAM(4, "GGTATT"), DECLARE_PARAM(5, "GGTATTTTAATT"), DECLARE_PARAM(6, "GGTATTTTAATTTATAGT") }; # undef DECLARE_PARAM struct tp *tp = tp_create(7); for (int i = 0 ; i < 2; i++) { tp_add_job(tp, &print_freqs, &freq_params[i]); } for (int i = 0 ;i < 5; i++) { tp_add_job(tp, &print_occurences, &occurences_params[i]); } tp_run(tp, cpu_count + 1); tp_destroy(tp); for (int i = 0; i < 2; i++) { printf("%s\n", output_buffer[i]); } for (int i = 2; i < 7; i++) { printf("%s", output_buffer[i]); } free(stdin_mem); return 0; }