int main(int argc, char** argv) { struct function_queue fq; struct qtpool_startup_info tqsi; struct qtpool tq; size_t threads = 4; int i = 0; int tqse[4]; puts("fq_init"); fq_init(&fq, FQTYPE_IA, 25); tqsi.fq = &fq; tqsi.max_threads = threads; puts("qtinit"); qtinit(&tq, &tqsi); puts("start"); qtstart(&tq, tqse); puts("pushing"); for(i = 0; i < 100; ++i) { fq_push(&fq, i %3 ? my_puts2 : my_puts, (void*) i, 1); printf("pushed %p with %p\n", i %3 ? my_puts2 : my_puts, (void*) i); } sleep(2); qtstop(&tq, 1); puts("stopped"); qtdestroy(&tq); fq_destroy(&fq); return 0; }
/** * Initialize context pointers */ void context_init(struct csv_context *ctx) { // Init our passthrough buffer ctx->csv_buf = cbuf_init(BUFFER_SIZE); // Initialize our blocking queue fq_init(&ctx->io_queue, BG_QUEUE_MAX); // Initialize our CSV parser if(csv_init(&ctx->parser, 0) != 0) { fprintf(stderr, "Couldn't initialize CSV parser!\n"); exit(EXIT_FAILURE); } // Set our csv block realloc size csv_set_blk_size(&ctx->parser, CSV_BLK_SIZE); // Initialize our thread count ctx->thread_count = IO_THREADS_DEFAULT; // Default to no group column ctx->gcol = -1; // Default to not gzipping our output files ctx->gzip = 0; // Header injection flags ctx->use_header = 0; ctx->count_header = 0; ctx->header_len = 0; }
fq_t *sff2fq (sff_t *sff) { fq_t *fq = NULL; if (NULL == (fq = fq_init())) { return fq; } int clip_left_index = 0; int clip_right_index = 0; clip_left_index = max (1, max (sff_clip_qual_left (sff), sff_clip_adapter_left (sff))); clip_right_index = min ((sff_clip_qual_right (sff) == 0 ? sff_n_bases(sff):sff_clip_qual_right(sff)), (sff_clip_adapter_right(sff) == 0 ? sff_n_bases(sff):sff_clip_adapter_right(sff))); // NB: clip_right_index and clip_left_offset now form a 0-based, half-open range const int clip_left_offset = clip_left_index - 1; assert(clip_left_offset >= 0); // If right clip precedes left, clip is invalid and truncated to 0-length read const int clip_seqlen = (clip_right_index >= clip_left_offset) ? clip_right_index - clip_left_offset : 0; assert(clip_seqlen >= 0); assert(clip_seqlen <= strlen(sff_bases(sff))); //copy name fq->name = strdup (sff_name(sff)); //copy sequence fq->seq = (char *) malloc (strlen (sff_bases(sff))+1); strncpy (fq->seq, sff_bases(sff)+clip_left_offset, clip_seqlen); fq->seq[clip_seqlen] = '\0'; //copy quality char *qual = qual_to_fastq (sff_quality(sff)); fq->qual = (char *) malloc (strlen (sff_quality(sff))+1); strncpy (fq->qual, qual+clip_left_offset, clip_seqlen); fq->qual[clip_seqlen] = '\0'; free (qual); //set length fq->l = strlen (fq->seq); return fq; }