int main( int argc, char *argv[] ) { DirectResult ret; /* Initialize DirectFB. */ ret = DirectFBInit( &argc, &argv ); if (ret) return DirectFBError( "DirectFBInit()", ret ); dfb_system_lookup(); ret = fusion_enter( -1, 0, FER_MASTER, &world ); if (ret) return DirectFBError( "fusion_enter()", ret ); printf( "\n" ); #if FUSION_BUILD_MULTI printf( "Fusion Benchmark (Multi Application Core)\n" ); #else printf( "Fusion Benchmark (Single Application Core)\n" ); #endif printf( "\n" ); bench_flock(); bench_mutex(); bench_mutex_threaded(); bench_skirmish(); bench_skirmish_threaded(); //bench_spinlock_threaded(); bench_property(); bench_ref(); bench_reactor(); bench_shmpool( false ); bench_shmpool( true ); printf( "\n" ); fusion_exit( world, false ); return 0; }
int main( int argc, char *argv[] ) { DirectResult ret; FusionWorld *world; StretRegion *root; StretRegion *child[16]; int child_num = 0; StretIteration iteration; DFBRegion clip; FusionSHMPoolShared *pool; ret = fusion_enter( -1, 0, FER_ANY, &world ); if (ret) return -1; ret = fusion_shm_pool_create( world, "StReT Test Pool", 0x10000, direct_config->debug, &pool ); if (ret) { fusion_exit( world, false ); return -1; } D_INFO( "StReT/Test: Starting...\n" ); ret = stret_region_create( 0, NULL, 0, SRF_ACTIVE, 2, 0, 0, 1000, 1000, NULL, 0, pool, &root ); if (ret) { D_DERROR( ret, "StReT/Test: Could not create root region!\n" ); goto error_root; } else { ret = stret_region_create( 0, NULL, 0, SRF_ACTIVE, 1, 10, 10, 100, 100, root, 1, pool, &child[child_num++] ); if (ret) { D_DERROR( ret, "StReT/Test: Could not create child region!\n" ); goto error_child; } else { ret = stret_region_create( 0, NULL, 0, SRF_ACTIVE, 1, 50, 50, 30, 30, child[0], 0, pool, &child[child_num++] ); if (ret) { D_DERROR( ret, "StReT/Test: Could not create child region!\n" ); goto error_child; } ret = stret_region_create( 0, NULL, 0, SRF_ACTIVE, 1, 20, 20, 30, 30, child[0], 0, pool, &child[child_num++] ); if (ret) { D_DERROR( ret, "StReT/Test: Could not create child region!\n" ); goto error_child; } else { ret = stret_region_create( 0, NULL, 0, SRF_ACTIVE, 1, 10, 10, 10, 10, child[2], 0, pool, &child[child_num++] ); if (ret) { D_DERROR( ret, "StReT/Test: Could not create child region!\n" ); goto error_child; } ret = stret_region_create( 0, NULL, 0, SRF_ACTIVE, 1, 20, 20, 10, 10, child[2], 0, pool, &child[child_num++] ); if (ret) { D_DERROR( ret, "StReT/Test: Could not create child region!\n" ); goto error_child; } } } ret = stret_region_create( 0, NULL, 0, SRF_ACTIVE, 1, 200, 10, 200, 200, root, 0, pool, &child[child_num++] ); if (ret) { D_DERROR( ret, "StReT/Test: Could not create child region!\n" ); goto error_child; } } stret_iteration_init( &iteration, root, NULL ); clip = (DFBRegion) { 50, 50, 200, 59 }; D_ASSERT( stret_iteration_next( &iteration, &clip ) == child[4] ); //D_ASSERT( stret_iteration_next( &iteration, &clip ) == child[3] ); D_ASSERT( stret_iteration_next( &iteration, &clip ) == child[2] ); //D_ASSERT( stret_iteration_next( &iteration, &clip ) == child[1] ); D_ASSERT( stret_iteration_next( &iteration, &clip ) == child[0] ); D_ASSERT( stret_iteration_next( &iteration, &clip ) == child[5] ); D_ASSERT( stret_iteration_next( &iteration, &clip ) == root ); D_ASSERT( stret_iteration_next( &iteration, &clip ) == NULL ); stret_region_destroy( child[child_num-1] ); error_child: while (--child_num) stret_region_destroy( child[child_num-1] ); stret_region_destroy( root ); error_root: fusion_shm_pool_destroy( world, pool ); fusion_exit( world, false ); return 0; }
DFBResult dfb_core_destroy( CoreDFB *core, bool emergency ) { D_MAGIC_ASSERT( core, CoreDFB ); D_ASSERT( core->refs > 0 ); D_ASSERT( core == core_dfb ); D_DEBUG_AT( DirectFB_Core, "%s...\n", __FUNCTION__ ); if (!emergency) { pthread_mutex_lock( &core_dfb_lock ); if (--core->refs) { pthread_mutex_unlock( &core_dfb_lock ); return DFB_OK; } } dfb_font_manager_destroy( core->font_manager ); if (core->signal_handler) direct_signal_handler_remove( core->signal_handler ); if (core->cleanup_handler) direct_cleanup_handler_remove( core->cleanup_handler ); if (core->master) { if (emergency) { fusion_kill( core->world, 0, SIGKILL, 1000 ); } else { fusion_kill( core->world, 0, SIGTERM, 5000 ); fusion_kill( core->world, 0, SIGKILL, 2000 ); } } dfb_core_process_cleanups( core, emergency ); while (fusion_arena_exit( core->arena, dfb_core_arena_shutdown, core->master ? NULL : dfb_core_arena_leave, core, emergency, NULL ) == DR_BUSY) { D_ONCE( "waiting for DirectFB slaves to terminate" ); direct_thread_sleep( 100000 ); } fusion_exit( core->world, emergency ); if (!emergency) direct_thread_remove_init_handler( core->init_handler ); D_MAGIC_CLEAR( core ); D_FREE( core ); core_dfb = NULL; if (!emergency) { pthread_mutex_unlock( &core_dfb_lock ); direct_shutdown(); } return DFB_OK; }
DFBResult dfb_core_create( CoreDFB **ret_core ) { int ret; #if FUSION_BUILD_MULTI char buf[16]; #endif CoreDFB *core = NULL; CoreDFBShared *shared = NULL; D_ASSERT( ret_core != NULL ); D_ASSERT( dfb_config != NULL ); D_DEBUG_AT( DirectFB_Core, "%s...\n", __FUNCTION__ ); pthread_mutex_lock( &core_dfb_lock ); D_ASSERT( core_dfb == NULL || core_dfb->refs > 0 ); if (core_dfb) { D_MAGIC_ASSERT( core_dfb, CoreDFB ); core_dfb->refs++; *ret_core = core_dfb; pthread_mutex_unlock( &core_dfb_lock ); return DFB_OK; } direct_initialize(); D_INFO( "DirectFB/Core: %s Application Core. ("BUILDTIME") %s%s\n", FUSION_BUILD_MULTI ? "Multi" : "Single", DIRECT_BUILD_DEBUG ? "[ DEBUG ]" : "", DIRECT_BUILD_TRACE ? "[ TRACE ]" : "" ); #if defined(DFB_DYNAMIC_LINKING) && defined(SOPATH) if (!dfb_lib_handle) #ifdef RTLD_GLOBAL dfb_lib_handle = dlopen(SOPATH, RTLD_GLOBAL|RTLD_LAZY); #else /* RTLD_GLOBAL is not defined on OpenBSD */ dfb_lib_handle = dlopen(SOPATH, RTLD_LAZY); #endif #endif ret = dfb_system_lookup(); if (ret) goto error; /* Allocate local core structure. */ core = D_CALLOC( 1, sizeof(CoreDFB) ); if (!core) { ret = D_OOM(); goto error; } core->refs = 1; core->init_handler = direct_thread_add_init_handler( dfb_core_thread_init_handler, core ); #if FUSION_BUILD_MULTI dfb_system_thread_init(); #endif direct_find_best_memcpy(); D_MAGIC_SET( core, CoreDFB ); core_dfb = core; ret = fusion_enter( dfb_config->session, DIRECTFB_CORE_ABI, FER_ANY, &core->world ); if (ret) goto error; core->fusion_id = fusion_id( core->world ); #if FUSION_BUILD_MULTI D_DEBUG_AT( DirectFB_Core, "world %d, fusion id %d\n", fusion_world_index(core->world), core->fusion_id ); snprintf( buf, sizeof(buf), "%d", fusion_world_index(core->world) ); setenv( "DIRECTFB_SESSION", buf, true ); #endif if (dfb_config->sync) { D_INFO( "DirectFB/Core: calling sync()...\n" ); direct_sync(); } if (dfb_config->core_sighandler) direct_signal_handler_add( DIRECT_SIGNAL_ANY, dfb_core_signal_handler, core, &core->signal_handler ); if (fusion_arena_enter( core->world, "DirectFB/Core", dfb_core_arena_initialize, dfb_core_arena_join, core, &core->arena, &ret ) || ret) { ret = ret ? ret : DFB_FUSION; goto error; } shared = core->shared; D_MAGIC_ASSERT( shared, CoreDFBShared ); if (dfb_config->block_all_signals) direct_signals_block_all(); if (dfb_config->deinit_check) direct_cleanup_handler_add( dfb_core_deinit_check, NULL, &core->cleanup_handler ); fusion_skirmish_prevail( &shared->lock ); if (!core->master) { while (!shared->active) fusion_skirmish_wait( &shared->lock, 0 ); } fusion_skirmish_dismiss( &shared->lock ); dfb_font_manager_create( core, &core->font_manager ); *ret_core = core; pthread_mutex_unlock( &core_dfb_lock ); D_DEBUG_AT( DirectFB_Core, "Core successfully created.\n" ); return DFB_OK; error: if (core) { if (core->world) fusion_exit( core->world, false ); if (core->init_handler) direct_thread_remove_init_handler( core->init_handler ); if (core->signal_handler) direct_signal_handler_remove( core->signal_handler ); D_MAGIC_CLEAR( core ); D_FREE( core ); core_dfb = NULL; } pthread_mutex_unlock( &core_dfb_lock ); direct_shutdown(); return ret; }
int main( int argc, char *argv[] ) { DirectResult ret; pid_t child_pid; TestMessage message = {0}; FusionReactor *reactor; Reaction reaction; FusionCall call; DirectFBInit( &argc, &argv ); ret = fusion_enter( -1, 0, FER_MASTER, &m_world ); if (ret) { D_DERROR( ret, "fusion_enter() failed" ); return ret; } MSG( "Entered world %d as master (FusionID %lu, pid %d)\n", fusion_world_index( m_world ), fusion_id( m_world ), getpid() ); reactor = fusion_reactor_new( sizeof(TestMessage), "Test", m_world ); if (!reactor) { D_ERROR( "fusion_reactor_new() failed\n" ); return -1; } MSG( "Attaching to reactor...\n" ); ret = fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); if (ret) { D_DERROR( ret, "fusion_reactor_attach() failed" ); return ret; } MSG( ".........FORKING NOW.........\n" ); fusion_world_set_fork_action( m_world, FFA_FORK ); child_pid = fork(); fusion_world_set_fork_action( m_world, FFA_CLOSE ); switch (child_pid) { case -1: D_PERROR( "fork() failed" ); break; case 0: setsid(); MSG( "...arrived after fork() in child (pid %d)..\n", getpid() ); MSG( "..child (FusionID %lu).\n", fusion_id( m_world ) ); usleep( 400000 ); break; default: usleep( 100000 ); MSG( "...returned from fork() in parent, child pid %d.\n", child_pid ); MSG( "Initializing dispatch callback...\n" ); ret = fusion_call_init( &call, dispatch_callback, NULL, m_world ); if (ret) { D_DERROR( ret, "fusion_call_init() failed" ); return ret; } MSG( "Setting dispatch callback...\n" ); ret = fusion_reactor_set_dispatch_callback( reactor, &call, NULL ); if (ret) { D_DERROR( ret, "fusion_reactor_set_dispatch_callback() failed" ); return ret; } MSG( "Sending message via reactor...\n" ); fusion_reactor_dispatch( reactor, &message, true, NULL ); usleep( 100000 ); MSG( "Destroying reactor...\n" ); fusion_reactor_destroy( reactor ); MSG( "...destroyed reactor!\n" ); usleep( 400000 ); MSG( "Freeing reactor...\n" ); fusion_reactor_free( reactor ); MSG( "...freed reactor!\n" ); break; } MSG( "Exiting from world %d (FusionID %lu, pid %d)...\n", fusion_world_index( m_world ), fusion_id( m_world ), getpid() ); fusion_exit( m_world, false ); return 0; }
int main( int argc, char *argv[] ) { DirectResult ret; pid_t child_pid; TestMessage message = {0}; DirectFBInit( &argc, &argv ); ret = fusion_enter( -1, 0, FER_MASTER, &m_world ); if (ret) { D_DERROR( ret, "fusion_enter() failed" ); return ret; } MSG( "Entered world %d as master (FusionID %lu, pid %d)\n", fusion_world_index( m_world ), fusion_id( m_world ), getpid() ); ret = fusion_ref_init( &m_ref, "Test", m_world ); if (ret) { D_DERROR( ret, "fusion_ref_init() failed" ); return -1; } MSG( "Adding local reference...\n" ); fusion_ref_up( &m_ref, false ); m_reactor = fusion_reactor_new( sizeof(TestMessage), "Test", m_world ); if (!m_reactor) { D_ERROR( "fusion_reactor_new() failed\n" ); return -1; } MSG( "Attaching to reactor...\n" ); ret = fusion_reactor_attach( m_reactor, reaction_callback, NULL, &m_reaction ); if (ret) { D_DERROR( ret, "fusion_reactor_attach() failed" ); return ret; } MSG( ".........FORKING NOW.........\n" ); fusion_world_set_fork_action( m_world, FFA_FORK ); child_pid = fork(); fusion_world_set_fork_action( m_world, FFA_CLOSE ); switch (child_pid) { case -1: D_PERROR( "fork() failed" ); break; case 0: setsid(); MSG( "...arrived after fork() in child (pid %d)..\n", getpid() ); MSG( "..child (FusionID %lu).\n", fusion_id( m_world ) ); break; default: usleep( 200000 ); MSG( "...returned from fork() in parent, child pid %d.\n", child_pid ); break; } MSG( "Sending message via reactor...\n" ); fusion_reactor_dispatch( m_reactor, &message, true, NULL ); usleep( 200000 ); MSG( "Removing local reference...\n" ); fusion_ref_down( &m_ref, false ); usleep( 200000 ); MSG( "Exiting from world %d (FusionID %lu, pid %d)...\n", fusion_world_index( m_world ), fusion_id( m_world ), getpid() ); fusion_exit( m_world, false ); return 0; }