void loop_run(loop_t *a){ const bool print_this_time = CHECK_BIT(settings, LOOP_PRINT_THIS_TIME); if(print_this_time){ FLIP_BIT(settings, LOOP_PRINT_THIS_TIME); printf_("settings: " + std::to_string(settings) + "\n", PRINTF_VITAL); } std::string summary = a->name + "\n"; const uint_ code_size = a->code.size(); const long double start_time = get_time(); if(CHECK_BIT(settings, LOOP_CODE_PARTIAL_MT) == 1){ std::vector<std::thread*> thread; for(uint_ i = 0;i < code_size;i++){ if(loop_entry_will_run(a, &a->code[i])){ thread.push_back(new std::thread(a->code[i].code)); } } for(uint_ i = 0;i < code_size;i++){ thread[i]->join(); delete thread[i]; thread[i] = nullptr; } }else if(CHECK_BIT(settings, LOOP_CODE_NEVEREND_MT) == 0){ for(uint_ i = 0;i < code_size;i++){ if(loop_entry_will_run(a, &a->code[i])){ const long double start_time = get_time(); a->code[i].code(); if(likely(print_this_time)){ summary += "\t" + a->code[i].name + "\t\t" + std::to_string(get_time()-start_time) + "\n"; } } // perhaps print a little notice if it isn't running? } if(unlikely(a->neverend_threads.size() != 0)){ for(uint_ i = 0;i < a->code.size();i++){ a->code[i].term = true; } for(uint_ i = 0;i < a->neverend_threads.size();i++){ a->neverend_threads[i]->join(); delete a->neverend_threads[i]; } a->neverend_threads.clear(); } }else if(CHECK_BIT(settings, LOOP_CODE_NEVEREND_MT) == 1){ loop_update_neverend_thread(a); } const long double end_time = get_time(); const long double current_rate = 1/(end_time-start_time); if(unlikely(a->average_rate == 0)){ a->average_rate = current_rate; } a->average_rate += current_rate; a->average_rate *= .5; if(print_this_time){ summary += "current frame rate: " + std::to_string(current_rate) + "\naverage framerate: " + std::to_string(a->average_rate) + "\nloop_settings: " + std::to_string(settings) + "\n"; if(a->neverend_threads.size() != 0){ summary += "neverend_thread is in use with " + std::to_string(a->neverend_threads.size()) + " threads.\n"; }else{ summary += "neverend_thread is not in use\n"; }// unify all of this into some sort of standard summary += "\tTitle\tIteration Skip\n"; for(uint_ i = 0;i < a->code.size();i++){ summary += "\t" + a->code[i].name + "\t" + std::to_string(a->code[i].iteration_skip) + "\n"; } printf("%s", summary.c_str()); } ++a->tick; if(check_for_parameter("--debug", argc_, argv_)) ms_sleep(1000); }
void toggle_pin (volatile uint8_t * port, uint8_t pin) { FLIP_BIT(*port, pin); __asm__ ("NOP"); FLIP_BIT(*port, pin); __asm__ ("NOP"); }
unsigned int flip_bit_uint(unsigned int pos, unsigned int val) { return FLIP_BIT(pos, val); }