コード例 #1
0
ファイル: fixed_pool.c プロジェクト: 1060460048/tbox
static tb_void_t tb_fixed_pool_slot_exit(tb_fixed_pool_impl_t* impl, tb_fixed_pool_slot_t* slot)
{
    // check
    tb_assert_and_check_return(impl && impl->large_pool && slot);
    tb_assert_and_check_return(impl->slot_list && impl->slot_count);

    // trace
    tb_trace_d("slot[%lu]: exit: size: %lu", impl->item_size, slot->size);

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

    // find the slot from the slot list
    tb_size_t itor = tb_binary_find_all(&iterator, (tb_cpointer_t)slot);
    tb_assert_abort(itor != tb_iterator_tail(&iterator) && itor < impl->slot_count && impl->slot_list[itor]);
    tb_check_return(itor != tb_iterator_tail(&iterator) && itor < impl->slot_count && impl->slot_list[itor]);
    
    // remove the slot
    if (itor + 1 < impl->slot_count) tb_memmov_(impl->slot_list + itor, impl->slot_list + itor + 1, (impl->slot_count - itor - 1) * sizeof(tb_fixed_pool_slot_t*));

    // update the slot count
    impl->slot_count--;

    // exit slot
    tb_large_pool_free(impl->large_pool, slot);
}
コード例 #2
0
ファイル: pool.c プロジェクト: KeplerGods/tbox
tb_void_t tb_pool_exit(tb_pool_ref_t pool)
{
    // check
    tb_pool_impl_t* impl = (tb_pool_impl_t*)pool;
    tb_assert_and_check_return(impl);

    // uses allocator?
    if (impl->allocator)
    {
        // exit it
        tb_allocator_free(impl->allocator, impl);
        return ;
    }

    // enter
    tb_spinlock_enter(&impl->lock);

    // exit small pool
    if (impl->small_pool) tb_small_pool_exit(impl->small_pool);
    impl->small_pool = tb_null;

    // leave
    tb_spinlock_leave(&impl->lock);

    // exit lock
    tb_spinlock_exit(&impl->lock);

    // exit pool
    if (impl->large_pool) tb_large_pool_free(impl->large_pool, impl);
}
コード例 #3
0
ファイル: fixed_pool.c プロジェクト: 1060460048/tbox
tb_void_t tb_fixed_pool_exit(tb_fixed_pool_ref_t pool)
{
    // check
    tb_fixed_pool_impl_t* impl = (tb_fixed_pool_impl_t*)pool;
    tb_assert_and_check_return(impl);

    // clear it
    tb_fixed_pool_clear(pool);

    // exit the slot list
    if (impl->slot_list) tb_large_pool_free(tb_large_pool(), impl->slot_list);
    impl->slot_list = tb_null;
    impl->slot_count = 0;
    impl->slot_space = 0;

    // exit it
    tb_large_pool_free(tb_large_pool(), impl);
}
コード例 #4
0
ファイル: small_pool.c プロジェクト: 1060460048/tbox
tb_bool_t tb_small_pool_free_(tb_small_pool_ref_t pool, tb_pointer_t data __tb_debug_decl__)
{
    // check
    tb_small_pool_impl_t* impl = (tb_small_pool_impl_t*)pool;
    tb_assert_and_check_return_val(impl && impl->large_pool && data, tb_false);

    // disable small pool for debug
#ifdef TB_SMALL_POOL_DISABLE
    return tb_large_pool_free(impl->large_pool, data);
#endif

    // done
    tb_bool_t ok = tb_false;
    do
    {
        // the data head
        tb_pool_data_head_t* data_head = &(((tb_pool_data_head_t*)data)[-1]);
        tb_assertf_break(data_head->debug.magic == TB_POOL_DATA_MAGIC, "free invalid data: %p", data);

        // the fixed pool
        tb_fixed_pool_ref_t fixed_pool = tb_small_pool_find_fixed(impl, data_head->size);
        tb_assert_and_check_break(fixed_pool);

        // the data space
        tb_size_t space = tb_fixed_pool_item_size(fixed_pool);
        tb_assert_and_check_break(space >= data_head->size);

        // check underflow
        tb_assertf_break(space == data_head->size || ((tb_byte_t*)data)[data_head->size] == TB_POOL_DATA_PATCH, "data underflow");

        // done
        ok = tb_fixed_pool_free_(fixed_pool, data __tb_debug_args__);

    } while (0);

    // failed? dump it
#ifdef __tb_debug__
    if (!ok) 
    {
        // trace
        tb_trace_e("free(%p) failed! at %s(): %lu, %s", data, func_, line_, file_);

        // dump data
        tb_pool_data_dump((tb_byte_t const*)data, tb_true, "[small_pool]: [error]: ");

        // abort
        tb_abort();
    }
#endif

    // ok?
    return ok;
}
コード例 #5
0
ファイル: small_pool.c プロジェクト: 1060460048/tbox
tb_void_t tb_small_pool_exit(tb_small_pool_ref_t pool)
{
    // check
    tb_small_pool_impl_t* impl = (tb_small_pool_impl_t*)pool;
    tb_assert_and_check_return(impl && impl->large_pool);

    // exit fixed pool
    tb_size_t i = 0;
    tb_size_t n = tb_arrayn(impl->fixed_pool);
    for (i = 0; i < n; i++)
    {
        // exit it
        if (impl->fixed_pool[i]) tb_fixed_pool_exit(impl->fixed_pool[i]);
        impl->fixed_pool[i] = tb_null;
    }

    // exit pool
    tb_large_pool_free(impl->large_pool, impl);
}