14 #include <utility/io/izstream.hh>
29 #include <utility/io/ozstream.hh>
31 #include <utility/basic_sys_util.hh>
32 #include <utility/file/file_sys_util.hh>
40 #include <basic/options/option.hh>
41 #include <basic/options/after_opts.hh>
43 #include <basic/options/keys/out.OptionKeys.gen.hh>
44 #include <basic/options/keys/boinc.OptionKeys.gen.hh>
83 int WATCHDOG_BLINK_TIME = 2;
84 int const PCT_COMPLETE_UPDATE_TIME = 5;
87 HANDLE watchdogThread;
93 UINT WINAPI main_watchdog_windows(
void* lpParam )
104 using namespace basic::options;
108 if ( option[ OptionKeys::boinc::watchdog ] ) {
109 std::cerr <<
"Starting watchdog..." << std::endl;
111 watchdogThread = (HANDLE)_beginthreadex(
114 main_watchdog_windows,
119 pthread_t p_watchdog;
120 pthread_create ( &p_watchdog, NULL,
131 using namespace basic::options;
134 if ( option[ OptionKeys::boinc::watchdog ] ) {
135 std::cerr << std::endl;
136 std::cerr <<
"BOINC :: Watchdog shutting down..." << std::endl;
142 WaitForSingleObject(watchdogThread, INFINITE);
143 CloseHandle(watchdogThread);
153 using basic::options::option;
154 using namespace basic::options::OptionKeys;
158 boinc_fraction_done(1);
159 boinc_begin_critical_section();
161 std::cerr << utility::timestamp() <<
" :: BOINC " << std::endl;
164 std::string const fullname = option[ out::file::silent ]();
182 std::cerr <<
"Output exists: " << fullname +
".gz" <<
" Size: " << utility::file::file_size( fullname +
".gz" ) << std::endl;
187 utility::io::izstream infile( wholename.c_str() );
189 std::cerr <<
"-----" << std::endl;
190 std::cerr << infile << std::endl;
191 std::cerr <<
"-----" << std::endl;
199 std::cerr <<
"Stream information inconsistent." << std::endl;
205 std::cerr <<
"Writing W_0000001" << std::endl;
215 utility::io::ozstream pdb_out_checkstream( fullname,
216 std::ios_base::in|std::ios_base::out );
217 utility::io::ozstream pdb_out_stream;
223 if (!pdb_out_checkstream ) {
224 pdb_out_checkstream.close();
225 pdb_out_checkstream.clear();
226 pdb_out_stream.open( fullname );
227 if ( !pdb_out_stream ) {
228 std::cout <<
"Open failed for file: " << fullname << std::endl;
229 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
235 pdb_out_checkstream.close();
236 pdb_out_checkstream.clear();
237 pdb_out_stream.open_append( fullname );
238 if ( !pdb_out_stream ) {
239 std::cout <<
" Append failed for file: " << fullname << std::endl;
240 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
253 pdb_out_stream.close();
254 pdb_out_stream.clear();
259 boinc_end_critical_section();
273 update_pct_complete()
275 static int pct_complete_blink_counter( 1 );
276 if ( pct_complete_blink_counter++ % PCT_COMPLETE_UPDATE_TIME == 0)
282 watchdog_sleep(
int const watchdog_time){
284 Sleep( 1000 * watchdog_time );
286 sleep(watchdog_time);
294 using namespace basic::options;
295 using namespace protocols::boinc;
297 double current_cpu_time = 0.0;
298 std::stringstream moreinfo;
300 int watchdog_time = option[ OptionKeys::boinc::watchdog_time ];
301 int cpu_run_timeout = option[ OptionKeys::boinc::cpu_run_timeout ];
303 int startup_time = 30;
305 int count_blinks = 0;
307 std::cerr <<
"Watchdog active." << std::endl;
319 watchdog_sleep(WATCHDOG_BLINK_TIME);
324 update_pct_complete();
327 if (count_blinks < watchdog_time)
continue;
329 if (!
init && count_blinks < startup_time)
continue;
335 BOINC_STATUS *rosetta_status =
new BOINC_STATUS;
336 boinc_get_status( rosetta_status );
337 if (!rosetta_status->suspended) {
343 boinc_wu_cpu_time(current_cpu_time);
348 int cpu_run_time = boinc_wu.get_project_pref_max_cpu_run_time();
351 if (current_cpu_time > (cpu_run_timeout + cpu_run_time) && cpu_run_time > 0) {
352 moreinfo <<
"CPU time: " << current_cpu_time <<
" seconds. Exceeded timeout" << cpu_run_timeout <<
" + " << cpu_run_time <<
" seconds";
353 std::cerr <<
"BOINC:: CPU time: " << current_cpu_time <<
"s, " << cpu_run_timeout <<
"s + " << cpu_run_time <<
"s";
354 get_the_hell_out(moreinfo.str());
360 std::cout <<
"Watchdog finished." << std::endl;