Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69240 - in trunk: boost/chrono/detail/inlined/win boost/detail/win libs/chrono/example
From: DDeakins_at_[hidden]
Date: 2011-02-24 13:21:57


Author: davedeakins
Date: 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
New Revision: 69240
URL: http://svn.boost.org/trac/boost/changeset/69240

Log:
Changes to complete Boost.Chrono support for Windows CE. Closes ticket 5218.
Text files modified:
   trunk/boost/chrono/detail/inlined/win/chrono.hpp | 18 ++++++++++++++++--
   trunk/boost/chrono/detail/inlined/win/process_clock.hpp | 7 ++++++-
   trunk/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp | 26 +++++++++++++++++++++++++-
   trunk/boost/detail/win/GetCurrentThread.hpp | 8 ++++++++
   trunk/boost/detail/win/GetProcessTimes.hpp | 2 ++
   trunk/boost/detail/win/time.hpp | 4 ++++
   trunk/libs/chrono/example/chrono_unit_test.cpp | 8 ++++++++
   trunk/libs/chrono/example/runtime_resolution.cpp | 24 +++++++++++++++++-------
   trunk/libs/chrono/example/timeval_demo.cpp | 20 +++++++++++++++-----
   9 files changed, 101 insertions(+), 16 deletions(-)

Modified: trunk/boost/chrono/detail/inlined/win/chrono.hpp
==============================================================================
--- trunk/boost/chrono/detail/inlined/win/chrono.hpp (original)
+++ trunk/boost/chrono/detail/inlined/win/chrono.hpp 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
@@ -95,7 +95,14 @@
   system_clock::time_point system_clock::now()
   {
     boost::detail::win32::FILETIME_ ft;
- boost::detail::win32::GetSystemTimeAsFileTime( &ft ); // never fails
+ #if defined(UNDER_CE)
+ // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps.
+ boost::detail::win32::SYSTEMTIME_ st;
+ boost::detail::win32::GetSystemTime( &st );
+ boost::detail::win32::SystemTimeToFileTime( &st, &ft );
+ #else
+ boost::detail::win32::GetSystemTimeAsFileTime( &ft ); // never fails
+ #endif
     return system_clock::time_point(system_clock::duration(
       (static_cast<__int64>( ft.dwHighDateTime ) << 32) | ft.dwLowDateTime));
   }
@@ -104,7 +111,14 @@
   system_clock::time_point system_clock::now( system::error_code & ec )
   {
     boost::detail::win32::FILETIME_ ft;
- boost::detail::win32::GetSystemTimeAsFileTime( &ft ); // never fails
+ #if defined(UNDER_CE)
+ // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps.
+ boost::detail::win32::SYSTEMTIME_ st;
+ boost::detail::win32::GetSystemTime( &st );
+ boost::detail::win32::SystemTimeToFileTime( &st, &ft );
+ #else
+ boost::detail::win32::GetSystemTimeAsFileTime( &ft ); // never fails
+ #endif
     if (!BOOST_CHRONO_IS_THROWS(ec))
     {
         ec.clear();

Modified: trunk/boost/chrono/detail/inlined/win/process_clock.hpp
==============================================================================
--- trunk/boost/chrono/detail/inlined/win/process_clock.hpp (original)
+++ trunk/boost/chrono/detail/inlined/win/process_clock.hpp 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
@@ -34,6 +34,11 @@
 
     times_.real = duration( steady_clock::now().time_since_epoch().count() );
        
+ #ifdef UNDER_CE
+ // Windows CE does not support GetProcessTimes
+ assert( 0 && "GetProcessTimes not supported under Windows CE" );
+ times_.real = times_.system = times_.user = nanoseconds(-1);
+ #else
     if ( boost::detail::win32::GetProcessTimes(
             boost::detail::win32::GetCurrentProcess(), &creation, &exit,
             &system_time, &user_time ) )
@@ -67,7 +72,7 @@
             times_.real = times_.system = times_.user = nanoseconds(-1);
         }
     }
-
+ #endif
 }
 } // namespace chrono
 } // namespace boost

Modified: trunk/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp
==============================================================================
--- trunk/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp (original)
+++ trunk/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
@@ -33,6 +33,11 @@
     // note that Windows uses 100 nanosecond ticks for FILETIME
     boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
 
+ #ifdef UNDER_CE
+ // Windows CE does not support GetProcessTimes
+ assert( 0 && "GetProcessTimes not supported under Windows CE" );
+ return time_point();
+ #else
     if ( boost::detail::win32::GetProcessTimes(
             boost::detail::win32::GetCurrentProcess(), &creation, &exit,
             &system_time, &user_time ) )
@@ -60,6 +65,7 @@
             return time_point();
         }
     }
+ #endif
 
 }
 process_user_cpu_clock::time_point process_user_cpu_clock::now(
@@ -69,6 +75,11 @@
     // note that Windows uses 100 nanosecond ticks for FILETIME
     boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
 
+ #ifdef UNDER_CE
+ // Windows CE does not support GetProcessTimes
+ assert( 0 && "GetProcessTimes not supported under Windows CE" );
+ return time_point();
+ #else
     if ( boost::detail::win32::GetProcessTimes(
             boost::detail::win32::GetCurrentProcess(), &creation, &exit,
             &system_time, &user_time ) )
@@ -99,6 +110,7 @@
             return time_point();
         }
     }
+ #endif
 
 }
 process_system_cpu_clock::time_point process_system_cpu_clock::now(
@@ -108,6 +120,11 @@
     // note that Windows uses 100 nanosecond ticks for FILETIME
     boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
 
+ #ifdef UNDER_CE
+ // Windows CE does not support GetProcessTimes
+ assert( 0 && "GetProcessTimes not supported under Windows CE" );
+ return time_point();
+ #else
     if ( boost::detail::win32::GetProcessTimes(
             boost::detail::win32::GetCurrentProcess(), &creation, &exit,
             &system_time, &user_time ) )
@@ -138,7 +155,8 @@
             return time_point();
         }
     }
-
+ #endif
+
 }
 process_cpu_clock::time_point process_cpu_clock::now(
         system::error_code & ec )
@@ -147,6 +165,11 @@
     // note that Windows uses 100 nanosecond ticks for FILETIME
     boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
 
+ #ifdef UNDER_CE
+ // Windows CE does not support GetProcessTimes
+ assert( 0 && "GetProcessTimes not supported under Windows CE" );
+ return time_point();
+ #else
     if ( boost::detail::win32::GetProcessTimes(
             boost::detail::win32::GetCurrentProcess(), &creation, &exit,
             &system_time, &user_time ) )
@@ -183,6 +206,7 @@
             return time_point();
         }
     }
+ #endif
 
 }
 } // namespace chrono

Modified: trunk/boost/detail/win/GetCurrentThread.hpp
==============================================================================
--- trunk/boost/detail/win/GetCurrentThread.hpp (original)
+++ trunk/boost/detail/win/GetCurrentThread.hpp 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
@@ -14,11 +14,19 @@
 namespace boost {
 namespace detail {
 namespace win32 {
+#if defined( UNDER_CE )
+// Windows CE define GetCurrentThread as an inline function in kfuncs.h
+inline HANDLE_ GetCurrentThread()
+{
+ return ::GetCurrentThread();
+}
+#else
 #if defined( BOOST_USE_WINDOWS_H )
     using ::GetCurrentThread;
 #else
     extern "C" __declspec(dllimport) HANDLE_ WINAPI GetCurrentThread();
 #endif
+#endif
 }
 }
 }

Modified: trunk/boost/detail/win/GetProcessTimes.hpp
==============================================================================
--- trunk/boost/detail/win/GetProcessTimes.hpp (original)
+++ trunk/boost/detail/win/GetProcessTimes.hpp 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
@@ -14,6 +14,7 @@
 namespace boost {
 namespace detail {
 namespace win32 {
+#if !defined(UNDER_CE) // Windows CE does not define GetProcessTimes
 #if defined( BOOST_USE_WINDOWS_H )
     using ::GetProcessTimes;
 #else
@@ -26,6 +27,7 @@
             LPFILETIME_ lpUserTime
         );
 #endif
+#endif
 }
 }
 }

Modified: trunk/boost/detail/win/time.hpp
==============================================================================
--- trunk/boost/detail/win/time.hpp (original)
+++ trunk/boost/detail/win/time.hpp 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
@@ -23,7 +23,9 @@
     typedef SYSTEMTIME SYSTEMTIME_;
     typedef SYSTEMTIME* PSYSTEMTIME_;
 
+ #ifndef UNDER_CE // Windows CE does not define GetSystemTimeAsFileTime
     using ::GetSystemTimeAsFileTime;
+ #endif
     using ::FileTimeToLocalFileTime;
     using ::GetSystemTime;
     using ::SystemTimeToFileTime;
@@ -47,8 +49,10 @@
       WORD_ wMilliseconds;
     } SYSTEMTIME_, *PSYSTEMTIME_;
 
+ #ifndef UNDER_CE // Windows CE does not define GetSystemTimeAsFileTime
     __declspec(dllimport) void WINAPI
         GetSystemTimeAsFileTime(FILETIME_* lpFileTime);
+ #endif
     __declspec(dllimport) int WINAPI
         FileTimeToLocalFileTime(const FILETIME_* lpFileTime,
                 FILETIME_* lpLocalFileTime);

Modified: trunk/libs/chrono/example/chrono_unit_test.cpp
==============================================================================
--- trunk/libs/chrono/example/chrono_unit_test.cpp (original)
+++ trunk/libs/chrono/example/chrono_unit_test.cpp 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
@@ -23,9 +23,17 @@
   std::time_t sys_time
     = boost::chrono::system_clock::to_time_t(boost::chrono::system_clock::now());
 
+ #ifdef UNDER_CE
+ // Windows CE does not define asctime()
+ struct tm * t = std::gmtime(&sys_time);
+ std::cout
+ << "system_clock::to_time_t(system_clock::now()) is "
+ << t->tm_mon << "/" << t->tm_mday << "/" << (1900 + t->tm_year) << " " << t->tm_hour << ":" << t->tm_min << ":" << t->tm_sec << std::endl;
+ #else
   std::cout
     << "system_clock::to_time_t(system_clock::now()) is "
     << std::asctime(std::gmtime(&sys_time)) << std::endl;
+ #endif
 
   return 0;
 }

Modified: trunk/libs/chrono/example/runtime_resolution.cpp
==============================================================================
--- trunk/libs/chrono/example/runtime_resolution.cpp (original)
+++ trunk/libs/chrono/example/runtime_resolution.cpp 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
@@ -42,15 +42,25 @@
 
 namespace
 {
- //struct timeval {
- // long tv_sec; /* seconds */
- // long tv_usec; /* and microseconds */
- //};
+ #ifdef UNDER_CE
+ // Windows CE does not define timeval
+ struct timeval {
+ long tv_sec; /* seconds */
+ long tv_usec; /* and microseconds */
+ };
+ #endif
 
   int gettimeofday(struct timeval * tp, void *)
   {
     FILETIME ft;
- ::GetSystemTimeAsFileTime( &ft ); // never fails
+ #if defined(UNDER_CE)
+ // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps.
+ SYSTEMTIME st;
+ ::GetSystemTime( &st );
+ ::SystemTimeToFileTime( &st, &ft );
+ #else
+ ::GetSystemTimeAsFileTime( &ft ); // never fails
+ #endif
     long long t = (static_cast<long long>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
   # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300 // > VC++ 7.0
     t -= 116444736000000000LL;
@@ -92,7 +102,7 @@
             : rep_(static_cast<rep>(d.count() * ticks_per_nanosecond)) {}
 
     // explicit
- operator tonanosec() const {return tonanosec(rep_/ticks_per_nanosecond);}
+ tonanosec convert_to_nanosec() const {return tonanosec(rep_/ticks_per_nanosecond);}
 
     // observer
 
@@ -218,7 +228,7 @@
     clock::duration elapsed = stop - start;
     std::cout << "paused " <<
     boost::chrono::nanoseconds(
- boost::chrono::duration_cast<boost::chrono::nanoseconds>(duration::tonanosec(elapsed))).count()
+ boost::chrono::duration_cast<boost::chrono::nanoseconds>( elapsed.convert_to_nanosec() )).count()
                            << " nanoseconds\n";
 }
 

Modified: trunk/libs/chrono/example/timeval_demo.cpp
==============================================================================
--- trunk/libs/chrono/example/timeval_demo.cpp (original)
+++ trunk/libs/chrono/example/timeval_demo.cpp 2011-02-24 13:21:52 EST (Thu, 24 Feb 2011)
@@ -44,15 +44,25 @@
 
 namespace
 {
- //struct timeval {
- // long tv_sec; /* seconds */
- // long tv_usec; /* and microseconds */
- //};
+ #ifdef UNDER_CE
+ // Windows CE does not define timeval
+ struct timeval {
+ long tv_sec; /* seconds */
+ long tv_usec; /* and microseconds */
+ };
+ #endif
 
   int gettimeofday(struct timeval * tp, void *)
   {
     FILETIME ft;
- ::GetSystemTimeAsFileTime( &ft ); // never fails
+ #if defined(UNDER_CE)
+ // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps.
+ SYSTEMTIME st;
+ ::GetSystemTime( &st );
+ ::SystemTimeToFileTime( &st, &ft );
+ #else
+ ::GetSystemTimeAsFileTime( &ft ); // never fails
+ #endif
     long long t = (static_cast<long long>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
   # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300 // > VC++ 7.0
     t -= 116444736000000000LL;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk