Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Checkpoint.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file
11 /// @brief
12 /// @author
13 
14 // must be here to avoid VC++ ambiguous symbol w/ ObjexxFCL::byte
15 // for boinc builds - dek
16 #ifdef BOINC
17 #include <protocols/boinc/boinc.hh>
18 #endif // BOINC
19 
20 // Unit headers
22 
23 
24 
25 namespace protocols {
26 namespace checkpoint {
27 
28  void checkpoint_with_interval( const int interval_in ) {
29  Timer timer = Timer::instance();
30  timer.set_interval( interval_in );
31  }
32 
34  {
35  static Timer theTimer;
36  return theTimer;
37  }
38 
39  void Timer::set_interval( const int interval_in ) {
40  if (interval_in < 1) return;
41  interval_ = interval_in;
42  }
43 
44  bool Timer::is_on() { return is_on_; }
45 
47 #ifdef BOINC
48  // honor user's disk write interval preference
49  // note: boinc_time_to_checkpoint sets critical section to true if
50  // it's time to checkpoint to prevent the client from stopping the app
51  // when checkpointing. uses boinc api calls
52 
53  if (!boinc_time_to_checkpoint() && !boinc_is_standalone()) return false;
54  boinc_end_critical_section(); // boinc_time_to_checkpoint sets is, and we dont need it yet.
55 #endif
56  double time_diff(0.0);
57  time_t curr_time;
58  time(&curr_time);
59  time_diff = difftime( curr_time, time_ );
60  if ( time_diff > interval_ ) return true;
61 
62  return false;
63  }
64 
65  void Timer::reset() {
66  time(&time_);
67 #ifdef BOINC
70 #endif
71  }
72 
73  bool Timer::is_on_ = false;
74  int Timer::interval_ = 600;
75  time_t Timer::time_ = time(0);
76 
77 
78 } // checkpoint
79 
80 } // protocols
81 
82