|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r79497 - trunk/tools/build/v2/engine
From: jurko.gospodnetic_at_[hidden]
Date: 2012-07-14 09:23:46
Author: jurko
Date: 2012-07-14 09:23:45 EDT (Sat, 14 Jul 2012)
New Revision: 79497
URL: http://svn.boost.org/trac/boost/changeset/79497
Log:
Boost Jam code cleanup - extracted Windows specific FILETIME structure conversion functions from execnt.c to a lowel level filent.c Windows specific module so they may be reused in both. Renamed the functions to make their purpose clearer.
Added:
trunk/tools/build/v2/engine/filent.h (contents, props changed)
Text files modified:
trunk/tools/build/v2/engine/execnt.c | 59 ++++-----------------------------------
trunk/tools/build/v2/engine/filent.c | 49 ++++++++++++++++++++++++++++++--
2 files changed, 52 insertions(+), 56 deletions(-)
Modified: trunk/tools/build/v2/engine/execnt.c
==============================================================================
--- trunk/tools/build/v2/engine/execnt.c (original)
+++ trunk/tools/build/v2/engine/execnt.c 2012-07-14 09:23:45 EDT (Sat, 14 Jul 2012)
@@ -31,16 +31,13 @@
* exec_cmd() - launch an async command execution
* exec_wait() - wait for any of the async command processes to
* terminate
- *
- * Internal routines:
- * filetime_dt() - Windows FILETIME --> POSIX time_t conversion
- * filetime_seconds() - Windows FILETIME --> number of seconds conversion
*/
#include "jam.h"
#ifdef USE_EXECNT
#include "execcmd.h"
+#include "filent.h"
#include "lists.h"
#include "output.h"
#include "pathsys.h"
@@ -51,8 +48,6 @@
#include <errno.h>
#include <time.h>
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
#include <process.h>
#include <tlhelp32.h>
@@ -669,46 +664,6 @@
}
-/*
- * filetime_seconds() - Windows FILETIME --> number of seconds conversion
- */
-
-static double filetime_seconds( FILETIME const t )
-{
- return t.dwHighDateTime * ( (double)( 1UL << 31 ) * 2.0 * 1.0e-7 ) +
- t.dwLowDateTime * 1.0e-7;
-}
-
-
-/*
- * filetime_dt() - Windows FILETIME --> POSIX time_t conversion
- *
- * Lifted shamelessly from the CPython implementation.
- */
-
-static time_t filetime_dt( FILETIME const ft )
-{
- /* Seconds between 1.1.1601 and 1.1.1970 */
- static __int64 const secs_between_epochs = 11644473600;
-
- /* We can not simply cast and dereference a FILETIME, since it might not be
- * aligned properly. __int64 type variables are expected to be aligned to an
- * 8 byte boundary while FILETIME structures may be aligned to any 4 byte
- * boundary. Using an incorrectly aligned __int64 variable may cause a
- * performance penalty on some platforms or even exceptions on others
- * (documented on MSDN).
- */
- __int64 in;
- memcpy( &in, &ft, sizeof( in ) );
-
- /* FILETIME resolution: 100ns. */
- /* For resolutions finer than 1 second use the following:
- * nsec = (int)( in % 10000000 ) * 100;
- */
- return (time_t)( ( in / 10000000 ) - secs_between_epochs );
-}
-
-
static void record_times( HANDLE const process, timing_info * const time )
{
FILETIME creation;
@@ -717,10 +672,10 @@
FILETIME user;
if ( GetProcessTimes( process, &creation, &exit, &kernel, &user ) )
{
- time->system = filetime_seconds( kernel );
- time->user = filetime_seconds( user );
- time->start = filetime_dt( creation );
- time->end = filetime_dt( exit );
+ time->system = filetime_to_seconds( kernel );
+ time->user = filetime_to_seconds( user );
+ time->start = filetime_to_timestamp( creation );
+ time->end = filetime_to_timestamp( exit );
}
}
@@ -901,7 +856,7 @@
{
/* Compute the elapsed time. */
GetSystemTimeAsFileTime( ¤t );
- return filetime_seconds( add_FILETIME( current,
+ return filetime_to_seconds( add_FILETIME( current,
negate_FILETIME( creation ) ) );
}
return 0.0;
@@ -955,7 +910,7 @@
FILETIME user;
FILETIME current;
return GetProcessTimes( process, &creation, &exit, &kernel, &user )
- ? filetime_seconds( creation )
+ ? filetime_to_seconds( creation )
: 0.0;
}
Modified: trunk/tools/build/v2/engine/filent.c
==============================================================================
--- trunk/tools/build/v2/engine/filent.c (original)
+++ trunk/tools/build/v2/engine/filent.c 2012-07-14 09:23:45 EDT (Sat, 14 Jul 2012)
@@ -15,8 +15,10 @@
* filent.c - scan directories and archives on NT
*
* External routines:
- * file_archscan() - scan an archive for files
- * file_mkdir() - create a directory
+ * file_archscan() - scan an archive for files
+ * file_mkdir() - create a directory
+ * filetime_to_seconds() - Windows FILETIME --> number of seconds conversion
+ * filetime_to_timestamp() - Windows FILETIME --> timestamp conversion
*
* External routines called only via routines in filesys.c:
* file_collect_dir_content_() - collects directory content information
@@ -26,6 +28,7 @@
#include "jam.h"
#ifdef OS_NT
+#include "filent.h"
#include "filesys.h"
#include "object.h"
@@ -46,8 +49,6 @@
#include <direct.h>
#include <io.h>
-#include <windows.h>
-
/*
* file_collect_dir_content_() - collects directory content information
@@ -347,4 +348,44 @@
close( fd );
}
+
+/*
+ * filetime_to_seconds() - Windows FILETIME --> number of seconds conversion
+ */
+
+double filetime_to_seconds( FILETIME const t )
+{
+ return t.dwHighDateTime * ( (double)( 1UL << 31 ) * 2.0 * 1.0e-7 ) +
+ t.dwLowDateTime * 1.0e-7;
+}
+
+
+/*
+ * filetime_to_timestamp() - Windows FILETIME --> timestamp conversion
+ *
+ * Lifted shamelessly from the CPython implementation.
+ */
+
+time_t filetime_to_timestamp( FILETIME const ft )
+{
+ /* Seconds between 1.1.1601 and 1.1.1970 */
+ static __int64 const secs_between_epochs = 11644473600;
+
+ /* We can not simply cast and dereference a FILETIME, since it might not be
+ * aligned properly. __int64 type variables are expected to be aligned to an
+ * 8 byte boundary while FILETIME structures may be aligned to any 4 byte
+ * boundary. Using an incorrectly aligned __int64 variable may cause a
+ * performance penalty on some platforms or even exceptions on others
+ * (documented on MSDN).
+ */
+ __int64 in;
+ memcpy( &in, &ft, sizeof( in ) );
+
+ /* FILETIME resolution: 100ns. */
+ /* For resolutions finer than 1 second use the following:
+ * nsec = (int)( in % 10000000 ) * 100;
+ */
+ return (time_t)( ( in / 10000000 ) - secs_between_epochs );
+}
+
#endif /* OS_NT */
Added: trunk/tools/build/v2/engine/filent.h
==============================================================================
--- (empty file)
+++ trunk/tools/build/v2/engine/filent.h 2012-07-14 09:23:45 EDT (Sat, 14 Jul 2012)
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2012 Jurko Gospodnetic
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+/*
+ * filent.h - Windows specific file routines
+ */
+
+#ifndef FILENT_JG20120714_H
+#define FILENT_JG20120714_H
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include <time.h>
+
+double filetime_to_seconds( FILETIME const ft );
+time_t filetime_to_timestamp( FILETIME const ft );
+
+#endif
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