const cmn_char_t* CTimeInfo::get_day_time(cmn_char_t *pszBuf) { #if __PLATFORM__ == __PLATFORM_LINUX__ #ifdef __MICRO_SECOND__ struct timeval tv; gettimeofday(&tv, NULL); #else time_t tt = get_time_in_seconds(); #endif struct tm t; #if defined __MICRO_SECOND__ localtime_r(&(tv.tv_sec), &t); snprintf(pszBuf, 36, "%i-%2.2i-%2.2i_%2.2i:%2.2i:%2.2i.%6.6ld", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, tv.tv_usec); #else localtime_r(&tt, &t); swprintf(pwszBuf, 36, L"%i-%2.2i-%2.2i %2.2i:%2.2i:%2.2i", t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); #endif #elif defined(__PLATEFORM_WINDOWS__) SYSTEMTIME st; ::GetLocalTime(&st); ::swprintf(pwszBuf, L"%4.4u-%2.2u-%2.2u(%2.2u:%2.2u:%2.2u.%3.3u)", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); #endif return pszBuf; }
int main(int argc, char* argv[]) { // Set up a SIGINT handler. signal(SIGINT, catch_sigint); // Create the InterfaceKit object. CPhidgetInterfaceKitHandle ifKit = 0; CPhidgetInterfaceKit_create(&ifKit); // Register device handlers. CPhidget_set_OnAttach_Handler((CPhidgetHandle)ifKit, attach_handler, NULL); CPhidget_set_OnDetach_Handler((CPhidgetHandle)ifKit, detach_handler, NULL); CPhidget_set_OnError_Handler((CPhidgetHandle)ifKit, error_handler, NULL); // Open the interfacekit for device connections. CPhidget_open((CPhidgetHandle)ifKit, -1); // Wait for a device attachment. fprintf(stderr, "waiting for interface kit to be attached....\n"); int result; const char *err; if ((result = CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 10000))) { CPhidget_getErrorDescription(result, &err); fprintf(stderr, "problem waiting for attachment: %s\n", err); return 0; } // Check some properties of the device. const char *device_type; int num_outputs; CPhidget_getDeviceType((CPhidgetHandle)ifKit, &device_type); CPhidgetInterfaceKit_getOutputCount(ifKit, &num_outputs); if ((strcmp(device_type, "PhidgetInterfaceKit") != 0)) { fprintf(stderr, "unexpected device type: %s\n", device_type); return 1; } if (num_outputs != 4) { fprintf(stderr, "unexpected number of device outputs: %d\n", num_outputs); return 1; } while (1) { double time = get_time_in_seconds(); double factor = 1; int l0_state = fmod(time * factor, 20) < 10; int l1_state = fmod(time * factor, 20) >= 10; CPhidgetInterfaceKit_setOutputState(ifKit, 0, l0_state); CPhidgetInterfaceKit_setOutputState(ifKit, 2, l1_state); usleep(100000); } fprintf(stderr, "shutting down...\n"); CPhidget_close((CPhidgetHandle)ifKit); CPhidget_delete((CPhidgetHandle)ifKit); return 0; }
int main(int argc, char **argv) { int consumer_count; int buffer_size; if (process_arguments(argc, argv, &buffer_size, &production_count, &producer_count, &consumer_count)) { printf("Invalid arguments\n"); return 1; } //initailze the buffer to null. //the buffer is dynamically built up //using the add and remove operations. //the size is enforced by a semaphore. buffer = NULL; //initalize semaphores sem_init(&buff_lock, 0, 1); sem_init(&count, 0, 0); sem_init(&buff_size, 0, buffer_size); sem_init(&con_num, 0, production_count); //array of id's used for joining pthread_t p_thread_id[producer_count]; pthread_t c_thread_id[consumer_count]; //creates structs to pass to threads struct thread_params p_id[producer_count]; struct thread_params c_id[consumer_count]; //get time before first fork double time_before_first_thread_created = get_time_in_seconds(); //creates producer threads int i; for (i = 0; i < producer_count; ++i) { p_id[i].id = i; pthread_create(&(p_thread_id[i]), NULL, &producer, &(p_id[i])); } //create consumer threads int c; for (c = 0; c < consumer_count; ++c) { c_id[c].id = c; pthread_create(&(c_thread_id[c]), NULL, &consumer, &(c_id[c])); } int j; for (j = 0; j < producer_count; ++j) { pthread_join(p_thread_id[j], NULL); } int k; for (k = 0; k < consumer_count; ++k) { pthread_join(c_thread_id[k], NULL); } double time_after_last_consumed = get_time_in_seconds(); double execution_time = time_after_last_consumed - time_before_first_thread_created; printf("System execution time: %f seconds\n", execution_time); //clean up semaphores sem_destroy(&buff_lock); sem_destroy(&count); sem_destroy(&buff_size); sem_destroy(&con_num); return 0; }
void SurfTrack::defrag_mesh( ) { // // First clear deleted vertices from the data stuctures // double start_time = get_time_in_seconds(); // do a quick pass through to see if any vertices have been deleted bool any_deleted = false; for ( size_t i = 0; i < get_num_vertices(); ++i ) { if ( m_mesh.vertex_is_deleted(i) ) { any_deleted = true; break; } } if ( !any_deleted ) { for ( size_t i = 0; i < get_num_vertices(); ++i ) { m_defragged_vertex_map.push_back( Vec2st(i,i) ); } double end_time = get_time_in_seconds(); g_stats.add_to_double( "total_clear_deleted_vertices_time", end_time - start_time ); } else { // Note: We could rebuild the mesh from scratch, rather than adding/removing // triangles, however this function is not a major computational bottleneck. size_t j = 0; std::vector<Vec3st> new_tris = m_mesh.get_triangles(); for ( size_t i = 0; i < get_num_vertices(); ++i ) { if ( !m_mesh.vertex_is_deleted(i) ) { pm_positions[j] = pm_positions[i]; pm_newpositions[j] = pm_newpositions[i]; m_masses[j] = m_masses[i]; m_defragged_vertex_map.push_back( Vec2st(i,j) ); // Now rewire the triangles containting vertex i // copy this, since we'll be changing the original as we go std::vector<size_t> inc_tris = m_mesh.m_vertex_to_triangle_map[i]; for ( size_t t = 0; t < inc_tris.size(); ++t ) { Vec3st triangle = m_mesh.get_triangle( inc_tris[t] ); assert( triangle[0] == i || triangle[1] == i || triangle[2] == i ); if ( triangle[0] == i ) { triangle[0] = j; } if ( triangle[1] == i ) { triangle[1] = j; } if ( triangle[2] == i ) { triangle[2] = j; } remove_triangle(inc_tris[t]); // mark the triangle deleted add_triangle(triangle); // add the updated triangle } ++j; } } pm_positions.resize(j); pm_newpositions.resize(j); m_masses.resize(j); } double end_time = get_time_in_seconds(); g_stats.add_to_double( "total_clear_deleted_vertices_time", end_time - start_time ); // // Now clear deleted triangles from the mesh // m_mesh.set_num_vertices( get_num_vertices() ); m_mesh.clear_deleted_triangles( &m_defragged_triangle_map ); if ( m_collision_safety ) { rebuild_continuous_broad_phase(); } }