/*
 * Copyright (c) 2012 by Matthias Noack, Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

#include "libxtreemfs/interrupt.h"

#include <boost/date_time/posix_time/posix_time_types.hpp>

namespace xtreemfs
{

  Interruptibilizer::query_function Interruptibilizer::f_ = NULL;

  void
  Interruptibilizer::Initialize(query_function f)
  {
    f_ = f;
  }

  bool
  Interruptibilizer::WasInterrupted()
  {
    return (f_ == NULL) ? false : static_cast<bool>(f_()); // TODO: NULL check still needed and usefull?
  }

  void
  Interruptibilizer::SleepInterruptible(int rel_time_in_ms)
  {
    assert(rel_time_in_ms >= 0);
    const int intervall_in_ms = 100;
    int runs = rel_time_in_ms / intervall_in_ms
        + ((rel_time_in_ms % intervall_in_ms) > 0 ? 1 : 0);

    for (int i = 0; i < runs && !Interruptibilizer::WasInterrupted(); ++i)
      {
        boost::this_thread::sleep(boost::posix_time::millisec(intervall_in_ms));
      }
  }

} // namespace xtreemfs

/*
 * Copyright (c) 2012 by Matthias Noack, Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

#include "libxtreemfs/interrupt.h"

#include <boost/date_time.hpp>

namespace xtreemfs
{

  Interruptibilizer::query_function Interruptibilizer::f_ = NULL;

  void
  Interruptibilizer::Initialize(query_function f)
  {
    f_ = f;
  }

  bool
  Interruptibilizer::WasInterrupted()
  {
    return (f_ == NULL) ? false : static_cast<bool>(f_()); // TODO: NULL check still needed and usefull?
  }

  void
  Interruptibilizer::SleepInterruptible(int rel_time_in_ms)
  {
    assert(rel_time_in_ms >= 0);
    const int intervall_in_ms = 100;
    int runs = rel_time_in_ms / intervall_in_ms
        + ((rel_time_in_ms % intervall_in_ms) > 0 ? 1 : 0);

    for (int i = 0; i < runs && !Interruptibilizer::WasInterrupted(); ++i)
      {
        boost::this_thread::sleep(boost::posix_time::millisec(intervall_in_ms));
      }
  }

} // namespace xtreemfs

--- 
+++ 
@@ -7,7 +7,7 @@
 
 #include "libxtreemfs/interrupt.h"
 
-#include <boost/date_time.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
 
 namespace xtreemfs
 {
client: Fix compilation error by including a more specific header file.

The compilation error was:
[  5%] Building CXX object CMakeFiles/xtreemfs.dir/src/libxtreemfs/interrupt.cpp.o
In file included from /usr/include/boost/date_time/local_time/tz_database.hpp:14,
                 from /usr/include/boost/date_time/local_time/local_time.hpp:19,
                 from /usr/include/boost/date_time.hpp:15,
                 from /scratch/autotests/checkouts/xtreemfs_checkout-20120616T000001/cpp/src/libxtreemfs/interrupt.cpp:10:
/usr/include/boost/date_time/tz_db_base.hpp:161: error: declaration of ‘typedef class boost::date_time::dst_adjustment_offsets<typename time_zone_type::time_duration_type> boost::date_time::tz_db_base<time_zone_type, rule_type>::dst_adjustment_offsets’
/usr/include/boost/date_time/time_zone_base.hpp:76: error: changes meaning of ‘dst_adjustment_offsets’ from ‘class boost::date_time::dst_adjustment_offsets<typename time_zone_type::time_duration_type>’

http://lists.boost.org/boost-users/2009/01/43983.php contains the required fix for the boost library. However, we could work around the error by including a more specific header. This way, we don't have to require newer boost versions which contain the original fix.

git-svn-id: 4a24f560d5bb049edaa12cbc2145b2f5ee41c6a2@3166 f8528748-c2c0-11dd-ba5c-d3b7c2b3b534
