int free_ws_output(int num_threads) { // Free file descriptors, summary counters and gene list cp_hashtable_destroy(output_files); cp_hashtable_destroy(summary_count); cp_hashtable_destroy(gene_list); // Free line buffers for (int i = 0; i < num_threads; i++) { free(line[i]); free(output_line[i]); free(snp_line[i]); free(snp_output_line[i]); free(mutation_line[i]); free(mutation_output_line[i]); } free(max_line_size); free(line); free(output_line); free(snp_max_line_size); free(snp_line); free(snp_output_line); free(mutation_max_line_size); free(mutation_line); free(mutation_output_line); return 0; }
int cp_log_close() { int rc; if (log_closing) return 0; log_closing = 1; if (logfile == NULL) return 0; rc = fclose(logfile); logfile = NULL; if (log_filename) { free(log_filename); log_filename = NULL; } cp_hashtable_destroy(error_message_lookup); if (thread_id) { cp_hashtable_destroy(thread_id); thread_id = NULL; } return rc; }
int cp_db_shutdown() { if (!initialized) return 1; initialized = 0; cp_list_destroy_custom(shutdown_hook, invoke_shutdown_call); if (drivers) cp_hashtable_destroy(drivers); return 0; }
int load_mime_types(char *filename) { FILE *fp; char mimebuf[LINELEN]; int rc = 0; char *name; char *ext; char *curr; mimemap = cp_hashtable_create_by_option(COLLECTION_MODE_NOSYNC | COLLECTION_MODE_COPY | COLLECTION_MODE_DEEP, 500, cp_hash_string, cp_hash_compare_string, (cp_copy_fn) strdup, (cp_destructor_fn) free, (cp_copy_fn) strdup, (cp_destructor_fn) free); fp = fopen(filename, "r"); if (fp == NULL) { cp_error(CP_INVALID_VALUE, "can\'t open %s", filename); cp_hashtable_destroy(mimemap); return -1; } while (fgets(mimebuf, LINELEN, fp)) { if (mimebuf[0] == '#') continue; name = curr = mimebuf; while (*curr && !isspace(*curr)) curr++; if (*curr == '\0') continue; /* no extension for this type */ *curr++ = '\0'; while (1) { while (*curr && isspace(*curr)) curr++; ext = curr; while (*curr && !isspace(*curr)) curr++; if (strlen(ext)) { *curr++ = '\0'; cp_hashtable_put(mimemap, ext, name); } else break; } } fclose(fp); return rc; }
void free_output_data_structures(cp_hashtable *output_files, cp_hashtable *summary_count, cp_hashtable *gene_list) { // Free file descriptors, summary counters and gene list cp_hashtable_destroy(output_files); cp_hashtable_destroy(summary_count); cp_hashtable_destroy(gene_list); }
static int stop_file_service() { cp_hashtable_destroy(mimemap); return 0; }
int main(int argc, char *argv[]) { int i; cp_thread w[COUNT]; cp_thread r[COUNT]; long total; int rc; if (argc > 1) silent = atoi(argv[1]); for (i = 0; i < COUNT; i++) { rc = cp_mutex_init(&lock[i], NULL); cp_cond_init(&cond[i], NULL); t[i] = cp_hashtable_create(10, cp_hash_string, cp_hash_compare_string); tl[i] = cp_list_create(); } rc = cp_mutex_init(&start_mutex, NULL); cp_cond_init(&start_cond, NULL); for (i = 0; i < COUNT; i++) cp_thread_create(r[i], NULL, reader, (void *) i); for (i = 0; i < COUNT; i++) cp_thread_create(w[i], NULL, writer, (void *) INSERTS); printf("press enter\n"); getchar(); cp_mutex_lock(&start_mutex); running = 1; total = time(NULL); cp_cond_broadcast(&start_cond); rc = cp_mutex_unlock(&start_mutex); if (rc == 0) write_err("MAIN"); for (i = 0; i < COUNT; i++) cp_thread_join(w[i], NULL); running = 0; for (i = 0; i < COUNT; i++) { cp_mutex_lock(&lock[i]); cp_cond_broadcast(&cond[i]); cp_mutex_unlock(&lock[i]); cp_thread_join(r[i], NULL); } total = time(NULL) - total; printf("\ndone in %ld seconds. tables should be empty now. press enter.\n", total); getchar(); for (i = 0; i < COUNT; i++) { printf("table %d: %ld items\n", i, cp_hashtable_count(t[i])); cp_hashtable_destroy(t[i]); printf("list %d: %ld items\n", i, cp_list_item_count(tl[i])); while (cp_list_item_count(tl[i])) { char *leftover = cp_list_remove_head(tl[i]); printf(" * %s\n", leftover); } cp_list_destroy(tl[i]); } printf("deleted them tables. press enter.\n"); getchar(); printf("bye.\n"); return 0; }