コード例 #1
0
ファイル: fixed_pool.c プロジェクト: 1060460048/tbox
static tb_fixed_pool_slot_t* tb_fixed_pool_slot_find(tb_fixed_pool_impl_t* impl, tb_pointer_t data)
{
    // check
    tb_assert_and_check_return_val(impl && data, tb_null);

    // done
    tb_fixed_pool_slot_t* slot = tb_null;
    do
    {
        // belong to the current slot?
        if (impl->current_slot && tb_fixed_pool_slot_exists(impl->current_slot, data))
        {
            slot = impl->current_slot;
            break;
        }
            
        // find the slot from the partial slots
        tb_for_all_if(tb_fixed_pool_slot_t*, partial_slot, tb_list_entry_itor(&impl->partial_slots), partial_slot)
        {
            // is this?
            if (tb_fixed_pool_slot_exists(partial_slot, data))
            {
                slot = partial_slot;
                break;
            }
        }
        
        // no found?
        tb_check_break(!slot);

        // find the slot from the full slots
        tb_for_all_if(tb_fixed_pool_slot_t*, full_slot, tb_list_entry_itor(&impl->full_slots), full_slot)
        {
            // is this?
            if (tb_fixed_pool_slot_exists(full_slot, data))
            {
                slot = full_slot;
                break;
            }
        }

    } while (0);

    // ok?
    return slot;
}
コード例 #2
0
ファイル: fixed_pool.c プロジェクト: 1060460048/tbox
static tb_fixed_pool_slot_t* tb_fixed_pool_slot_find(tb_fixed_pool_impl_t* impl, tb_pointer_t data)
{
    // check
    tb_assert_and_check_return_val(impl && data, tb_null);

    // init the iterator
    tb_iterator_t iterator = tb_iterator_init_ptr((tb_pointer_t*)impl->slot_list, impl->slot_count);

    // find it
    tb_size_t itor = tb_binary_find_all_if(&iterator, tb_fixed_pool_slot_comp, data);
    tb_check_return_val(itor != tb_iterator_tail(&iterator), tb_null);

    // the slot
    tb_fixed_pool_slot_t* slot = impl->slot_list[itor];
    tb_assert_and_check_return_val(slot, tb_null);

    // check
    tb_assert_abort(tb_fixed_pool_slot_exists(slot, data));

    // ok?
    return slot;
}
コード例 #3
0
ファイル: fixed_pool.c プロジェクト: siwuxian/xmake
static tb_fixed_pool_slot_t* tb_fixed_pool_slot_find(tb_fixed_pool_t* pool, tb_pointer_t data)
{
    // check
    tb_assert_and_check_return_val(pool && data, tb_null);

    // make the iterator
    tb_array_iterator_t array_iterator;
    tb_iterator_ref_t   iterator = tb_iterator_make_for_ptr(&array_iterator, (tb_pointer_t*)pool->slot_list, pool->slot_count);
    tb_assert(iterator);

    // find it
    tb_size_t itor = tb_binary_find_all_if(iterator, tb_fixed_pool_slot_comp, data);
    tb_check_return_val(itor != tb_iterator_tail(iterator), tb_null);

    // the slot
    tb_fixed_pool_slot_t* slot = pool->slot_list[itor];
    tb_assert_and_check_return_val(slot, tb_null);

    // check
    tb_assert(tb_fixed_pool_slot_exists(slot, data));

    // ok?
    return slot;
}