From: Curt M. <we...@us...> - 2004-08-27 20:09:31
|
Update of /cvsroot/xastir/xastir/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20081 Modified Files: main.c Log Message: Fix for high CPU-usage when time skips backwards. This fix causes Xastir to sleep a bit in the UpdateTime() loop until time catches up again, thereby avoiding the problem. It also dumps a message out to STDERR as it goes into/out of this mode. Index: main.c =================================================================== RCS file: /cvsroot/xastir/xastir/src/main.c,v retrieving revision 1.513 retrieving revision 1.514 diff -C2 -d -r1.513 -r1.514 *** main.c 25 Aug 2004 19:39:39 -0000 1.513 --- main.c 27 Aug 2004 20:09:20 -0000 1.514 *************** *** 237,240 **** --- 237,243 ---- time_t sec_last_dtr = (time_t)0; + time_t last_updatetime = (time_t)0; + int time_went_backwards = 0; + /* language in use */ char lang_to_use[30]; *************** *** 10121,10124 **** --- 10124,10156 ---- nexttime = 2; + + if (last_updatetime > sec_now()) { + // Time just went in the wrong direction. Sleep for a bit + // so that we don't use massive CPU until the time catches + // up again. + // + if (time_went_backwards == 0) { + // This is our first time through UpdateTime() since the + // time went in the wrong direction. Dump out a + // message to the user. + time_went_backwards++; + fprintf(stderr,"\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); + fprintf(stderr, "!! System time jumped backwards! !!\n"); + fprintf(stderr, "!! Xastir sleeping, else will use excessive CPU !!\n"); + fprintf(stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"); + } + usleep(1); // Sleep for 1uS. + } + else { + // Time is behaving normally. + last_updatetime = sec_now(); + if (time_went_backwards) { + fprintf(stderr, + "Xastir is done sleeping due to time reversal.\n\n"); + } + time_went_backwards = 0; + } + + (void)sound_done(); *************** *** 10146,10152 **** --- 10178,10186 ---- check_message_remove(); // remove old messages + //if ( (new_message_data > 0) && ( (delay_time % 2) == 0) ) //update_messages(0); // Check Messages, no forced update + // Check whether it's time to expire some weather // alerts. This function will set redraw_on_new_data *************** *** 10155,10158 **** --- 10189,10193 ---- (void)alert_expire(); + #ifdef HAVE_GPSMAN // Check whether we've just completed a GPS transfer and *************** *** 10161,10164 **** --- 10196,10200 ---- check_for_new_gps_map(); + // Check whether it is time to snag RINO waypoints // again, creating APRS Objects out of them. "0" for *************** *** 10174,10181 **** --- 10210,10219 ---- #endif // HAVE_GPSMAN + if (xfontsel_query) { Query_xfontsel_pipe(); } + // Check on resize requests if (request_resize) { *************** *** 10185,10188 **** --- 10223,10227 ---- } + if (request_new_image) { // if (last_input_event < sec_now()) { *************** *** 10191,10195 **** } ! /* check on Redraw requests */ if ( ( (redraw_on_new_data > 1) || (redraw_on_new_data && (sec_now() > last_redraw + REDRAW_WAIT)) --- 10230,10235 ---- } ! ! // check on Redraw requests if ( ( (redraw_on_new_data > 1) || (redraw_on_new_data && (sec_now() > last_redraw + REDRAW_WAIT)) *************** *** 10249,10253 **** SayText(station_id); } ! #endif /* HAVE_FESTIVAL */ } last_alert_on_screen = temp_alert_count; --- 10289,10293 ---- SayText(station_id); } ! #endif // HAVE_FESTIVAL } last_alert_on_screen = temp_alert_count; *************** *** 10269,10272 **** --- 10309,10313 ---- } + if (Display_.dr_data && ((sec_now() - sec_last_dr_update) > update_DR_rate) ) { *************** *** 10281,10290 **** ! /* Look for packet data and check port status */ if (delay_time > 15) { display_packet_data(); interface_status(w); delay_time = 0; ! /* check station lists */ update_station_scroll_list(); // maybe update lists } --- 10322,10331 ---- ! // Look for packet data and check port status if (delay_time > 15) { display_packet_data(); interface_status(w); delay_time = 0; ! // check station lists update_station_scroll_list(); // maybe update lists } *************** *** 10323,10327 **** // Start the GPS listening process again ! /* check gps start up, GPS on GPSPORT */ if(sec_now() > sec_next_gps) { --- 10364,10368 ---- // Start the GPS listening process again ! // check gps start up, GPS on GPSPORT if(sec_now() > sec_next_gps) { *************** *** 10477,10481 **** } ! /* Check to reestablish a connection */ if(sec_now() > net_next_time) { net_last_time = sec_now(); --- 10518,10522 ---- } ! // Check to reestablish a connection if(sec_now() > net_next_time) { net_last_time = sec_now(); *************** *** 10483,10487 **** //net_next_time = net_last_time + 30; // This statement is for debug ! /*fprintf(stderr,"Checking for reconnects\n");*/ check_ports(); --- 10524,10528 ---- //net_next_time = net_last_time + 30; // This statement is for debug ! //fprintf(stderr,"Checking for reconnects\n"); check_ports(); *************** *** 10494,10507 **** } ! /* Check to see if it is time to spit out data */ if(!wait_to_redraw) { if (last_time == 0) { ! /* first update */ next_time = 120; last_time = sec_now(); do_time = 1; } else { ! /* check for update */ ! /*fprintf(stderr,"Checking --- time %ld time to update %ld\n",sec_now(),last_time+next_time);*/ if(sec_now() >= (last_time + next_time)) { next_time += next_time; --- 10535,10548 ---- } ! // Check to see if it is time to spit out data if(!wait_to_redraw) { if (last_time == 0) { ! // first update next_time = 120; last_time = sec_now(); do_time = 1; } else { ! // check for update ! //fprintf(stderr,"Checking --- time %ld time to update %ld\n",sec_now(),last_time+next_time); if(sec_now() >= (last_time + next_time)) { next_time += next_time; *************** *** 10575,10580 **** // if (do_time || transmit_now) { // transmit_now = 0; ! // /* output to ALL net/tnc ports */ ! // /*fprintf(stderr,"Output data\n");*/ // output_my_aprs_data(); // } --- 10616,10621 ---- // if (do_time || transmit_now) { // transmit_now = 0; ! // // output to ALL net/tnc ports ! // //fprintf(stderr,"Output data\n"); // output_my_aprs_data(); // } *************** *** 10595,10599 **** update_station_info(w); // Go refresh the Station Info display ! /* Time to put out raw WX data ? */ if (sec_now() > sec_next_raw_wx) { sec_next_raw_wx = sec_now()+600; --- 10636,10640 ---- update_station_info(w); // Go refresh the Station Info display ! // Time to put out raw WX data ? if (sec_now() > sec_next_raw_wx) { sec_next_raw_wx = sec_now()+600; *************** *** 10604,10613 **** #endif // TRANSMIT_RAW_WX ! /* check wx data last received */ wx_last_data_check(); } } ! /* is it time to spit out messages? */ check_and_transmit_messages(sec_now()); --- 10645,10654 ---- #endif // TRANSMIT_RAW_WX ! // check wx data last received wx_last_data_check(); } } ! // is it time to spit out messages? check_and_transmit_messages(sec_now()); *************** *** 10641,10645 **** } ! /* get data from interfaces */ max=0; // Allow up to 1000 packets to be processed inside this --- 10682,10686 ---- } ! // get data from interfaces max=0; // Allow up to 1000 packets to be processed inside this *************** *** 10696,10705 **** if (data_avail) { ! int data_type; /* 0=AX25, 1=GPS */ //fprintf(stderr,"device_type: %d\n",port_data[data_port].device_type); switch (port_data[data_port].device_type) { ! /* NET Data stream */ case DEVICE_NET_STREAM: --- 10737,10746 ---- if (data_avail) { ! int data_type; // 0=AX25, 1=GPS //fprintf(stderr,"device_type: %d\n",port_data[data_port].device_type); switch (port_data[data_port].device_type) { ! // NET Data stream case DEVICE_NET_STREAM: *************** *** 10735,10739 **** break; ! /* TNC Devices */ case DEVICE_SERIAL_KISS_TNC: case DEVICE_SERIAL_MKISS_TNC: --- 10776,10780 ---- break; ! // TNC Devices case DEVICE_SERIAL_KISS_TNC: case DEVICE_SERIAL_MKISS_TNC: *************** *** 10808,10812 **** } else { ! /* get TNC data */ if (log_tnc_data) log_data(LOGFILE_TNC, --- 10849,10853 ---- } else { ! // get TNC data if (log_tnc_data) log_data(LOGFILE_TNC, *************** *** 10892,10900 **** break; ! /* GPS Devices */ case DEVICE_SERIAL_GPS: case DEVICE_NET_GPSD: ! /*fprintf(stderr,"GPS Data <%s>\n",incoming_data);*/ (void)gps_data_find((char *)incoming_data, data_port); --- 10933,10941 ---- break; ! // GPS Devices case DEVICE_SERIAL_GPS: case DEVICE_NET_GPSD: ! //fprintf(stderr,"GPS Data <%s>\n",incoming_data); (void)gps_data_find((char *)incoming_data, data_port); *************** *** 10912,10916 **** break; ! /* WX Devices */ case DEVICE_SERIAL_WX: --- 10953,10957 ---- break; ! // WX Devices case DEVICE_SERIAL_WX: *************** *** 10946,10951 **** } ! /* END- get data from interface */ ! /* READ FILE IF OPENED */ if (read_file) { if (sec_now() >= next_file_read) { --- 10987,10993 ---- } ! ! // END- get data from interface ! // READ FILE IF OPENED if (read_file) { if (sec_now() >= next_file_read) { *************** *** 10954,10958 **** } } ! /* END- READ FILE IF OPENED */ } --- 10996,11000 ---- } } ! // END- READ FILE IF OPENED } *************** *** 10971,10976 **** check_pointer_position(); - } sched_yield(); // Yield the processor to another thread --- 11013,11018 ---- check_pointer_position(); } + sched_yield(); // Yield the processor to another thread |