Example #1
0
int add_gff_record(gff_record_t* record, gff_file_t *gff_file)
{
    void *result = cp_list_append(gff_file->records, record);
    if (result != NULL) {
        LOG_DEBUG_F("record %zu\n", cp_list_item_count(gff_file->records));
    } else {
        LOG_DEBUG_F("record %zu not inserted\n", cp_list_item_count(gff_file->records));
    }
    return result != NULL;
}
Example #2
0
int add_gff_header_entry(gff_header_entry_t *header_entry, gff_file_t *gff_file)
{
    void *result = cp_list_append(gff_file->header_entries, header_entry);
    if (result != NULL) {
        LOG_DEBUG_F("header entry %zu\n", cp_list_item_count(gff_file->header_entries));
    } else {
        LOG_DEBUG_F("header entry %zu not inserted\n", cp_list_item_count(gff_file->header_entries));
    }
    return result != NULL;
}
Example #3
0
int cp_thread_pool_count_available(cp_thread_pool *pool)
{
	return (pool->max_size - pool->size) + 
			cp_list_item_count(pool->free_pool);
}
Example #4
0
int cp_db_register_dbms(char *name, void (*shutdown_call)())
{
	cp_list_append(shutdown_hook, shutdown_call);

	return cp_list_item_count(shutdown_hook);
}
Example #5
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;
}