Exemple #1
0
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);
}
Exemple #2
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * implementation
 */
tb_small_pool_ref_t tb_small_pool_init(tb_large_pool_ref_t large_pool)
{
    // done
    tb_bool_t               ok = tb_false;
    tb_small_pool_impl_t*   impl = tb_null;
    do
    {
        // using the default large pool 
        if (!large_pool) large_pool = tb_large_pool();
        tb_assert_and_check_break(large_pool);

        // make pool
        impl = (tb_small_pool_impl_t*)tb_large_pool_malloc0(large_pool, sizeof(tb_small_pool_impl_t), tb_null);
        tb_assert_and_check_break(impl);

        // init pool
        impl->large_pool = large_pool;

        // ok
        ok = tb_true;

    } while (0);

    // failed?
    if (!ok)
    {
        if (impl) tb_small_pool_exit((tb_small_pool_ref_t)impl);
        impl = tb_null;
    }

    // ok?
    return (tb_small_pool_ref_t)impl;
}