Пример #1
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * implementation
 */
tb_bool_t tb_memory_init_env(tb_allocator_ref_t allocator)
{
    // done
    tb_bool_t ok = tb_false;
    do
    {   
        // init page
        if (!tb_page_init()) break;

        // init the native memory
        if (!tb_native_memory_init()) break;

        // init the allocator
#if defined(TB_CONFIG_MICRO_ENABLE) || \
        (defined(__tb_small__) && !defined(__tb_debug__))
        g_allocator = allocator? allocator : tb_native_allocator();
#else
        g_allocator = allocator? allocator : tb_default_allocator(tb_null, 0);
#endif
        tb_assert_and_check_break(g_allocator);

        // ok
        ok = tb_true;

    } while (0);

    // failed? exit it
    if (!ok) tb_memory_exit_env();
    
    // ok?
    return ok;
}
Пример #2
0
Файл: tbox.c Проект: waruqi/tbox
tb_void_t tb_exit()
{
    // have been exited?
    if (TB_STATE_OK != tb_atomic_fetch_and_pset(&g_state, TB_STATE_OK, TB_STATE_EXITING)) return ;

    // kill singleton
    tb_singleton_kill();

    // exit object
#ifdef TB_CONFIG_MODULE_HAVE_OBJECT
    tb_object_exit_env();
#endif
    
    // exit network envirnoment
    tb_network_exit_env();
     
    // exit libm envirnoment
    tb_libm_exit_env();
     
    // exit math envirnoment
    tb_math_exit_env();
    
    // exit libc envirnoment
    tb_libc_exit_env();
    
    // exit platform envirnoment
    tb_platform_exit_env();
    
    // exit singleton
    tb_singleton_exit();

    // exit memory envirnoment
    tb_memory_exit_env();

    // trace
    tb_trace_d("exit: ok");

    // exit trace
    tb_trace_exit();

    // end
    tb_atomic_set(&g_state, TB_STATE_END);
}