/* Audio_Thread::clear: free thread */ void Audio_Thread::clear() { stop(); m_kill = true; /* wait */ if(m_cond != NULL) glfwSignalCond(m_cond); if(m_mutex != NULL || m_cond != NULL || m_thread >= 0) { if(m_thread >= 0) { glfwWaitThread(m_thread, GLFW_WAIT); glfwDestroyThread(m_thread); } if(m_cond != NULL) glfwDestroyCond(m_cond); if(m_mutex != NULL) glfwDestroyMutex(m_mutex); glfwTerminate(); } if(m_alias) free(m_alias); if(m_file) free(m_file); initialize(); }
/* Sphinx_Thread::clear: free thread */ void Sphinx_Thread::clear() { if(m_thread >= 0) { if(m_recog) delete m_recog; glfwWaitThread(m_thread, GLFW_WAIT); glfwDestroyThread(m_thread); glfwTerminate(); } if (m_recog) { //ps_free(m_recog); /* m_config is also released in ps_free */ } if(m_languageModel != NULL) free(m_languageModel); if(m_dictionary != NULL) free(m_dictionary); if(m_acousticModel != NULL) free(m_acousticModel); if(m_configFile != NULL) free(m_configFile); if(m_logFolder != NULL) free(m_logFolder); initialize(); }
/* Audio_Manager::clear: clear */ void Audio_Manager::clear() { Audio_Link *tmp1, *tmp2; m_kill = true; /* stop and release all thread */ for(tmp1 = m_list; tmp1; tmp1 = tmp2) { tmp2 = tmp1->next; tmp1->audio_thread.stopAndRelease(); delete tmp1; } /* wait */ if(m_cond != NULL) glfwSignalCond(m_cond); if(m_mutex != NULL || m_cond != NULL || m_thread >= 0) { if(m_thread >= 0) { glfwWaitThread(m_thread, GLFW_WAIT); glfwDestroyThread(m_thread); } if(m_cond != NULL) glfwDestroyCond(m_cond); if(m_mutex != NULL) glfwDestroyMutex(m_mutex); glfwTerminate(); } Audio_EventQueue_clear(&m_bufferQueue); initialize(); }
/* Julius_Thread::clear: free thread */ void Julius_Thread::clear() { if(m_thread >= 0) { if(m_recog) j_close_stream(m_recog); glfwWaitThread(m_thread, GLFW_WAIT); glfwDestroyThread(m_thread); glfwTerminate(); } if (m_recog) { j_recog_free(m_recog); /* jconf is also released in j_recog_free */ } else if (m_jconf) { j_jconf_free(m_jconf); } if(m_languageModel != NULL) free(m_languageModel); if(m_dictionary != NULL) free(m_dictionary); if(m_acousticModel != NULL) free(m_acousticModel); if(m_triphoneList != NULL) free(m_triphoneList); if(m_configFile != NULL) free(m_configFile); if(m_userDictionary != NULL) free(m_userDictionary); initialize(); }
Thread::~Thread() { if (IsAlive()) { RequestStop(); glfwWaitThread(m_oThread, GLFW_WAIT); m_oThread = -1; std::cout << m_sName << " thread has been shut down.\n"; } ///FpsCounter::RemoveCounter(m_pFpsCounter); }
void Thread_Manager::WaitForThread(ThreadID threadID) { glfwWaitThread(threadID,GLFW_WAIT); }
int main( int argc, char **argv ) { int i, frames, benchmark; double t0, t; GLFWthread physics_thread = 0; // Use multithreading by default, but don't benchmark multithreading = 1; benchmark = 0; // Check command line arguments for( i = 1; i < argc; i ++ ) { // Use benchmarking? if( strcmp( argv[i], "-b" ) == 0 ) { benchmark = 1; } // Force multithreading off? else if( strcmp( argv[i], "-s" ) == 0 ) { multithreading = 0; } // With a Finder launch on Mac OS X we get a bogus -psn_0_46268417 // kind of argument (actual numbers vary). Ignore it. else if( strncmp( argv[i], "-psn_", 5) == 0 ); // Usage else { if( strcmp( argv[i], "-?" ) != 0 ) { printf( "Unknonwn option %s\n\n", argv[ i ] ); } printf( "Usage: %s [options]\n", argv[ 0 ] ); printf( "\n"); printf( "Options:\n" ); printf( " -b Benchmark (run program for 60 s)\n" ); printf( " -s Run program as single thread (default is to use two threads)\n" ); printf( " -? Display this text\n" ); printf( "\n"); printf( "Program runtime controls:\n" ); printf( " w Toggle wireframe mode\n" ); printf( " ESC Exit program\n" ); exit( 0 ); } } // Initialize GLFW if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit( EXIT_FAILURE ); } // Open OpenGL fullscreen window if( !glfwOpenWindow( WIDTH, HEIGHT, 5,6,5,0, 16,0, GLFW_FULLSCREEN ) ) { fprintf( stderr, "Failed to open GLFW window\n" ); glfwTerminate(); exit( EXIT_FAILURE ); } // Set window title glfwSetWindowTitle( "Particle engine" ); // Disable VSync (we want to get as high FPS as possible!) glfwSwapInterval( 0 ); // Window resize callback function glfwSetWindowSizeCallback( Resize ); // Set keyboard input callback function glfwSetKeyCallback( KeyFun ); // Upload particle texture glGenTextures( 1, &particle_tex_id ); glBindTexture( GL_TEXTURE_2D, particle_tex_id ); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, P_TEX_WIDTH, P_TEX_HEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, particle_texture ); // Upload floor texture glGenTextures( 1, &floor_tex_id ); glBindTexture( GL_TEXTURE_2D, floor_tex_id ); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, F_TEX_WIDTH, F_TEX_HEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, floor_texture ); // Check if we have GL_EXT_separate_specular_color, and if so use it if( glfwExtensionSupported( "GL_EXT_separate_specular_color" ) ) { glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SEPARATE_SPECULAR_COLOR_EXT ); } // Set filled polygon mode as default (not wireframe) glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); wireframe = 0; // Clear particle system for( i = 0; i < MAX_PARTICLES; i ++ ) { particles[ i ].active = 0; } min_age = 0.0f; // Set "running" flag running = 1; // Set initial times thread_sync.t = 0.0; thread_sync.dt = 0.001f; // Init threading if( multithreading ) { thread_sync.p_frame = 0; thread_sync.d_frame = 0; thread_sync.particles_lock = glfwCreateMutex(); thread_sync.p_done = glfwCreateCond(); thread_sync.d_done = glfwCreateCond(); physics_thread = glfwCreateThread( PhysicsThreadFun, NULL ); } // Main loop t0 = glfwGetTime(); frames = 0; while( running ) { // Get frame time t = glfwGetTime() - t0; // Draw... Draw( t ); // Swap buffers glfwSwapBuffers(); // Check if window was closed running = running && glfwGetWindowParam( GLFW_OPENED ); // Increase frame count frames ++; // End of benchmark? if( benchmark && t >= 60.0 ) { running = 0; } } t = glfwGetTime() - t0; // Wait for particle physics thread to die if( multithreading ) { glfwWaitThread( physics_thread, GLFW_WAIT ); } // Display profiling information printf( "%d frames in %.2f seconds = %.1f FPS", frames, t, (double)frames / t ); printf( " (multithreading %s)\n", multithreading ? "on" : "off" ); // Terminate OpenGL glfwTerminate(); exit( EXIT_SUCCESS ); }