Ticket #5218: boost-chrono-windowsce.patch

File boost-chrono-windowsce.patch, 11.2 KB (added by David Deakins, 12 years ago)

Patches to enable Windows CE support

  • boost/chrono/detail/inlined/win/chrono.hpp

     
    9595  system_clock::time_point system_clock::now()
    9696  {
    9797    boost::detail::win32::FILETIME_ ft;
    98     boost::detail::win32::GetSystemTimeAsFileTime( &ft );  // never fails
     98        #if defined(UNDER_CE)
     99                // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps.
     100                boost::detail::win32::SYSTEMTIME_ st;
     101                boost::detail::win32::GetSystemTime( &st );
     102                boost::detail::win32::SystemTimeToFileTime( &st, &ft );
     103        #else
     104                boost::detail::win32::GetSystemTimeAsFileTime( &ft );  // never fails
     105        #endif
    99106    return system_clock::time_point(system_clock::duration(
    100107      (static_cast<__int64>( ft.dwHighDateTime ) << 32) | ft.dwLowDateTime));
    101108  }
     
    104111  system_clock::time_point system_clock::now( system::error_code & ec )
    105112  {
    106113    boost::detail::win32::FILETIME_ ft;
    107     boost::detail::win32::GetSystemTimeAsFileTime( &ft );  // never fails
     114        #if defined(UNDER_CE)
     115                // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps.
     116                boost::detail::win32::SYSTEMTIME_ st;
     117                boost::detail::win32::GetSystemTime( &st );
     118                boost::detail::win32::SystemTimeToFileTime( &st, &ft );
     119        #else
     120                boost::detail::win32::GetSystemTimeAsFileTime( &ft );  // never fails
     121        #endif
    108122    if (!BOOST_CHRONO_IS_THROWS(ec))
    109123    {
    110124        ec.clear();
  • boost/chrono/detail/inlined/win/process_clock.hpp

     
    3434
    3535    times_.real = duration( steady_clock::now().time_since_epoch().count() );
    3636       
     37        #ifdef UNDER_CE
     38        // Windows CE does not support GetProcessTimes
     39    assert( 0 && "GetProcessTimes not supported under Windows CE" );
     40        times_.real = times_.system = times_.user = nanoseconds(-1);
     41        #else
    3742    if ( boost::detail::win32::GetProcessTimes(
    3843            boost::detail::win32::GetCurrentProcess(), &creation, &exit,
    3944            &system_time, &user_time ) )
     
    6772            times_.real = times_.system = times_.user = nanoseconds(-1);
    6873        }
    6974    }
    70 
     75        #endif
    7176}
    7277} // namespace chrono
    7378} // namespace boost
  • boost/chrono/detail/inlined/win/process_cpu_clocks.hpp

     
    3333    //  note that Windows uses 100 nanosecond ticks for FILETIME
    3434    boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
    3535
     36        #ifdef UNDER_CE
     37        // Windows CE does not support GetProcessTimes
     38    assert( 0 && "GetProcessTimes not supported under Windows CE" );
     39        return time_point();
     40        #else
    3641    if ( boost::detail::win32::GetProcessTimes(
    3742            boost::detail::win32::GetCurrentProcess(), &creation, &exit,
    3843            &system_time, &user_time ) )
     
    6065            return time_point();
    6166        }
    6267    }
     68        #endif
    6369
    6470}
    6571process_user_cpu_clock::time_point process_user_cpu_clock::now(
     
    6975    //  note that Windows uses 100 nanosecond ticks for FILETIME
    7076    boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
    7177
     78        #ifdef UNDER_CE
     79        // Windows CE does not support GetProcessTimes
     80    assert( 0 && "GetProcessTimes not supported under Windows CE" );
     81        return time_point();
     82        #else
    7283    if ( boost::detail::win32::GetProcessTimes(
    7384            boost::detail::win32::GetCurrentProcess(), &creation, &exit,
    7485            &system_time, &user_time ) )
     
    99110            return time_point();
    100111        }
    101112    }
     113        #endif
    102114
    103115}
    104116process_system_cpu_clock::time_point process_system_cpu_clock::now(
     
    108120    //  note that Windows uses 100 nanosecond ticks for FILETIME
    109121    boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
    110122
     123        #ifdef UNDER_CE
     124        // Windows CE does not support GetProcessTimes
     125    assert( 0 && "GetProcessTimes not supported under Windows CE" );
     126        return time_point();
     127        #else
    111128    if ( boost::detail::win32::GetProcessTimes(
    112129            boost::detail::win32::GetCurrentProcess(), &creation, &exit,
    113130            &system_time, &user_time ) )
     
    138155            return time_point();
    139156        }
    140157    }
    141 
     158        #endif
     159       
    142160}
    143161process_cpu_clock::time_point process_cpu_clock::now(
    144162        system::error_code & ec )
     
    147165    //  note that Windows uses 100 nanosecond ticks for FILETIME
    148166    boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
    149167
     168        #ifdef UNDER_CE
     169        // Windows CE does not support GetProcessTimes
     170    assert( 0 && "GetProcessTimes not supported under Windows CE" );
     171        return time_point();
     172        #else
    150173    if ( boost::detail::win32::GetProcessTimes(
    151174            boost::detail::win32::GetCurrentProcess(), &creation, &exit,
    152175            &system_time, &user_time ) )
     
    183206            return time_point();
    184207        }
    185208    }
     209        #endif
    186210
    187211}
    188212} // namespace chrono
  • boost/detail/win/GetCurrentThread.hpp

     
    1414namespace boost {
    1515namespace detail {
    1616namespace win32 {
     17#if defined( UNDER_CE )
     18// Windows CE define GetCurrentThread as an inline function in kfuncs.h
     19inline HANDLE_ GetCurrentThread()
     20{
     21        return ::GetCurrentThread();
     22}
     23#else
    1724#if defined( BOOST_USE_WINDOWS_H )
    1825    using ::GetCurrentThread;
    1926#else
    2027    extern "C" __declspec(dllimport) HANDLE_ WINAPI GetCurrentThread();
    2128#endif
     29#endif
    2230}
    2331}
    2432}
  • boost/detail/win/GetProcessTimes.hpp

     
    1414namespace boost {
    1515namespace detail {
    1616namespace win32 {
     17#if !defined(UNDER_CE)  // Windows CE does not define GetProcessTimes
    1718#if defined( BOOST_USE_WINDOWS_H )
    1819    using ::GetProcessTimes;
    1920#else
     
    2627            LPFILETIME_ lpUserTime
    2728        );
    2829#endif
     30#endif
    2931}
    3032}
    3133}
  • boost/detail/win/time.hpp

     
    2323    typedef SYSTEMTIME SYSTEMTIME_;
    2424    typedef SYSTEMTIME* PSYSTEMTIME_;
    2525
     26        #ifndef UNDER_CE        // Windows CE does not define GetSystemTimeAsFileTime
    2627    using ::GetSystemTimeAsFileTime;
     28        #endif
    2729    using ::FileTimeToLocalFileTime;
    2830    using ::GetSystemTime;
    2931    using ::SystemTimeToFileTime;
     
    4749      WORD_ wMilliseconds;
    4850    } SYSTEMTIME_, *PSYSTEMTIME_;
    4951
     52        #ifndef UNDER_CE        // Windows CE does not define GetSystemTimeAsFileTime
    5053    __declspec(dllimport) void WINAPI
    5154        GetSystemTimeAsFileTime(FILETIME_* lpFileTime);
     55        #endif
    5256    __declspec(dllimport) int WINAPI
    5357        FileTimeToLocalFileTime(const FILETIME_* lpFileTime,
    5458                FILETIME_* lpLocalFileTime);
  • libs/chrono/example/chrono_unit_test.cpp

     
    2323  std::time_t sys_time
    2424    = boost::chrono::system_clock::to_time_t(boost::chrono::system_clock::now());
    2525
     26  #ifdef UNDER_CE
     27  // Windows CE does not define asctime()
     28  struct tm * t = std::gmtime(&sys_time);
    2629  std::cout
    2730    << "system_clock::to_time_t(system_clock::now()) is "
     31    << t->tm_mon << "/" << t->tm_mday << "/" << (1900 + t->tm_year) << " " << t->tm_hour << ":" << t->tm_min << ":" << t->tm_sec << std::endl;
     32  #else
     33  std::cout
     34    << "system_clock::to_time_t(system_clock::now()) is "
    2835    << std::asctime(std::gmtime(&sys_time)) << std::endl;
     36  #endif
    2937
    3038  return 0;
    3139}
  • libs/chrono/example/runtime_resolution.cpp

     
    4242
    4343namespace
    4444{
    45   //struct timeval {
    46   //        long    tv_sec;         /* seconds */
    47   //        long    tv_usec;        /* and microseconds */
    48   //};
     45  #ifdef UNDER_CE
     46  // Windows CE does not define timeval
     47  struct timeval {
     48          long    tv_sec;         /* seconds */
     49          long    tv_usec;        /* and microseconds */
     50  };
     51  #endif
    4952
    5053  int gettimeofday(struct timeval * tp, void *)
    5154  {
    5255    FILETIME ft;
    53     ::GetSystemTimeAsFileTime( &ft );  // never fails
     56        #if defined(UNDER_CE)
     57                // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps.
     58                SYSTEMTIME st;
     59                ::GetSystemTime( &st );
     60                ::SystemTimeToFileTime( &st, &ft );
     61        #else
     62                ::GetSystemTimeAsFileTime( &ft );  // never fails
     63        #endif
    5464    long long t = (static_cast<long long>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
    5565  # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300 // > VC++ 7.0
    5666    t -= 116444736000000000LL;
     
    92102            : rep_(static_cast<rep>(d.count() * ticks_per_nanosecond)) {}
    93103
    94104    // explicit
    95        operator tonanosec() const {return tonanosec(rep_/ticks_per_nanosecond);}
     105    tonanosec convert_to_nanosec() const {return tonanosec(rep_/ticks_per_nanosecond);}
    96106
    97107    // observer
    98108
     
    218228    clock::duration elapsed = stop - start;
    219229    std::cout << "paused " <<
    220230    boost::chrono::nanoseconds(
    221         boost::chrono::duration_cast<boost::chrono::nanoseconds>(duration::tonanosec(elapsed))).count()
     231        boost::chrono::duration_cast<boost::chrono::nanoseconds>( elapsed.convert_to_nanosec() )).count()
    222232                           << " nanoseconds\n";
    223233}
    224234
  • libs/chrono/example/timeval_demo.cpp

     
    4444
    4545namespace
    4646{
    47   //struct timeval {
    48   //        long    tv_sec;         /* seconds */
    49   //        long    tv_usec;        /* and microseconds */
    50   //};
     47  #ifdef UNDER_CE
     48  // Windows CE does not define timeval
     49  struct timeval {
     50          long    tv_sec;         /* seconds */
     51          long    tv_usec;        /* and microseconds */
     52  };
     53  #endif
    5154
    5255  int gettimeofday(struct timeval * tp, void *)
    5356  {
    5457    FILETIME ft;
    55     ::GetSystemTimeAsFileTime( &ft );  // never fails
     58        #if defined(UNDER_CE)
     59                // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps.
     60                SYSTEMTIME st;
     61                ::GetSystemTime( &st );
     62                ::SystemTimeToFileTime( &st, &ft );
     63        #else
     64                ::GetSystemTimeAsFileTime( &ft );  // never fails
     65        #endif
    5666    long long t = (static_cast<long long>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
    5767  # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300 // > VC++ 7.0
    5868    t -= 116444736000000000LL;