コード例 #1
0
ファイル: test_hash.c プロジェクト: dlbeer/libdlb
static void test_add_remove(int flags)
{
	add_half(0, flags);
	assert(hsh.count == N / 2);
	assert(hsh.size >= N / 2);
	check_present(0);
	check_not_present(1);

	hash_capacity_hint(&hsh, N);
	assert(hsh.size >= N);

	add_half(1, flags | HASH_INSERT_UNIQUE);
	assert(hsh.count == N);
	assert(hsh.size >= N);
	check_present(0);
	check_present(1);

	remove_half(0);
	assert(hsh.count == N / 2);
	assert(hsh.size >= N / 2);
	check_not_present(0);
	check_present(1);

	remove_half(1);
	check_not_present(0);
	check_not_present(1);
	assert(hsh.count == 0);
}
コード例 #2
0
ファイル: fifo-main.c プロジェクト: rosrez/drv2
static int __init fifo_init(void)
{
    int i, val, ret;

    ret = ififo_alloc(&fifo, size, GFP_KERNEL);
    if (ret)
        return ret;

    printk("%s: populating fifo\n", MODNAME);
    for (i = 0; ififo_put(fifo, i + 1); i++);

    printk("%s: initial fifo state\n", MODNAME);
    print_fifo(fifo);

    printk("%s: COPY -- initial fifo state\n", MODNAME);
    print_fifo(fifo);

    /* try to enqueue one more item */
    if (!ififo_put(fifo, size + 1)) 
        printk("unsuccessful attempt to insert to full fifo\n");

    add_one(fifo, size + 1);
    printk("%s: added 1 item\n", MODNAME);
    print_fifo(fifo);

    printk("%s: COPY -- after adding one\n", MODNAME);
    print_fifo_copy(fifo);   

    /* add another half items */
    add_half(fifo, size + 2);
    printk("%s: added half\n", MODNAME);
    print_fifo(fifo);   

    printk("%s: COPY -- after adding half\n", MODNAME);
    print_fifo_copy(fifo);   

    printk("printing -- draining the queue\n");
    i = 1;
    while (ififo_get(fifo, &val)) 
        printk("item[%d] = %d\n", i++, val);
    
    printk("queue size now is %d\n", ififo_len(fifo));
 
    printk("%s: init complete\n", MODNAME);
    return 0;
}