TPOOL_RTN_E tpool_create(struct tpool_ctx ** obj, uint8_t num) { int i; struct tpool_ctx * tpool = NULL; if ((tpool = malloc(sizeof(struct tpool_ctx))) == NULL) return TPOOL_FAILED; memset(tpool, 0, sizeof(struct tpool_ctx)); tpool->workers_num_total = 0; tpool->workers_num_running = 0; tpool->workers_num_working = 0; tpool->keep_alive = 0; pthread_mutex_init(&tpool->workers_num_lock, NULL); pthread_cond_init(&tpool->workers_idle_cond, NULL); pthread_mutex_init(&tpool->tasks_uid_lock, NULL); // Initial tasks if (qlist_create(&tpool->tasks) != QLIST_SUCCESS) { tpool_destroy(tpool); return TPOOL_FAILED; } // Initial workers array tpool->workers = (struct tpool_worker **) malloc(sizeof(struct tpool_worker *) * num); if (tpool->workers == NULL) { tpool_destroy(tpool); return TPOOL_FAILED; } // Initial all workers for (i = 0; i < num; i++) { if (worker_create(&tpool->workers[i]) != TPOOL_SUCCESS) { tpool_destroy(tpool); return TPOOL_FAILED; } tpool->workers[i]->uid = 0; tpool->workers[i]->tpool = tpool; tpool->workers_num_total++; } *obj = tpool; return TPOOL_SUCCESS; }
void sparser (BB *btree, char fl, int N, char *idx_path) { Qlist *query = qlist_create(); int i=0; unsigned int ch; char *word = (char*)malloc(sizeof(char)*80); int state = INIT; int numb_query = 0; int count_word = 0; while ((ch = getchar())!=EOF) { if (i>80) { // printf ("I'm here\n"); char *tmp = (char *)realloc(word, 10000); word = tmp; } if (state == INIT) { if (ch == '\n') { word[i++] = '\0'; if (!(isspace(word[0]) || word[0]=='\0' || ispoint(word[0]))) { qlist_insert(query,word,i); memset(word,0,i); count_word++; numb_query++; } i=0; query_find(btree,query,count_word,fl,numb_query,N); // qlist_prn(query); qlist_clear(query); state = INIT; count_word=0; continue; } if (isalnum(ch)) { state = SB; word[i] = tolower(ch); i++; continue; } else { state = INIT; continue; } } if (state == LF) { word[i++] = '\0'; qlist_insert(query,word,i); memset(word,0,i); i=0; count_word++; numb_query++; query_find(btree,query,count_word,fl,numb_query,N); // qlist_prn(query); qlist_clear(query); state = INIT; count_word=0; } if (state == SB) { if (isalnum(ch) || ch =='\'' || ch == '-') { word[i++]=tolower(ch); continue; } if (ch == '\n') { word[i++] = '\0'; qlist_insert(query,word,i); memset(word,0,i); i=0; count_word++; numb_query++; query_find(btree,query,count_word,fl,numb_query,N); // qlist_prn(query); qlist_clear(query); state = INIT; count_word=0; continue; } else { word[i] = '\0'; i++; qlist_insert(query,word,i); memset(word,0,i); i=0; state = INIT; count_word++; } } } printf ("searching queries have finished\n"); }