コード例 #1
0
ファイル: gff_file.c プロジェクト: CharoL/bioinfo-libs
void gff_close(gff_file_t *gff_file, int free_records) 
{
    // Free string members
    free(gff_file->filename);
   
    // Free header entries
    if (!cp_list_is_empty(gff_file->header_entries)) {
        cp_list_destroy(gff_file->header_entries);
    }
    
    // Free records list if asked to
    if (free_records) {
        cp_list_destroy(gff_file->records);
    }
    
    munmap((void*) gff_file->data, gff_file->data_len);
    free(gff_file);
}
コード例 #2
0
void cp_thread_pool_destroy(cp_thread_pool *pool)
{
#ifdef __TRACE__
	DEBUGMSG("stopping cp_thread_pool %lX", pool);
#endif

	if (pool->running) cp_thread_pool_stop(pool);

	cp_list_destroy(pool->free_pool);
//	cp_list_destroy_custom(pool->free_pool, 
//				(cp_destructor_fn) cp_pooled_thread_destroy);
	cp_hashlist_destroy(pool->in_use);
//	cp_hashlist_destroy_custom(pool->in_use, NULL, 
//				(cp_destructor_fn) cp_pooled_thread_destroy);
	cp_mutex_destroy(pool->pool_lock);
	free(pool->pool_lock);
	cp_cond_destroy(pool->pool_cond);
	free(pool->pool_cond);

	free(pool);
}
コード例 #3
0
ファイル: test_hashtable2.c プロジェクト: dulton/tinybus
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;
}