[rtems commit] imfs: Use most efficient way to get the time

Sebastian Huber sebh at rtems.org
Fri Mar 16 07:21:55 UTC 2018


Module:    rtems
Branch:    master
Commit:    478dc8968fe54f8762e77ca17db98d6b290dd2b8
Changeset: http://git.rtems.org/rtems/commit/?id=478dc8968fe54f8762e77ca17db98d6b290dd2b8

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Mar 16 07:01:48 2018 +0100

imfs: Use most efficient way to get the time

As a side-effect, this fixes some warnings.

Close #3350.

---

 cpukit/include/rtems/imfs.h | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/cpukit/include/rtems/imfs.h b/cpukit/include/rtems/imfs.h
index fe3c5b1..3d2048a 100644
--- a/cpukit/include/rtems/imfs.h
+++ b/cpukit/include/rtems/imfs.h
@@ -16,6 +16,7 @@
 #ifndef _RTEMS_IMFS_H
 #define _RTEMS_IMFS_H
 
+#include <sys/time.h>
 #include <limits.h>
 
 #include <rtems/libio_.h>
@@ -337,41 +338,39 @@ static inline IMFS_memfile_t *IMFS_iop_to_memfile( const rtems_libio_t *iop )
   return (IMFS_memfile_t *) iop->pathinfo.node_access;
 }
 
-static inline void IMFS_update_atime( IMFS_jnode_t *jnode )
+static inline time_t _IMFS_get_time( void )
 {
-  struct timeval now;
+  struct bintime now;
 
-  gettimeofday( &now, 0 );
+  /* Use most efficient way to get the time in seconds (CLOCK_REALTIME) */
+  _Timecounter_Getbintime( &now );
 
-  jnode->stat_atime = now.tv_sec;
+  return now.sec;
 }
 
-static inline void IMFS_update_mtime( IMFS_jnode_t *jnode )
+static inline void IMFS_update_atime( IMFS_jnode_t *jnode )
 {
-  struct timeval now;
-
-  gettimeofday( &now, 0 );
+  jnode->stat_atime = _IMFS_get_time();
+}
 
-  jnode->stat_mtime = now.tv_sec;
+static inline void IMFS_update_mtime( IMFS_jnode_t *jnode )
+{
+  jnode->stat_mtime = _IMFS_get_time();
 }
 
 static inline void IMFS_update_ctime( IMFS_jnode_t *jnode )
 {
-  struct timeval now;
-
-  gettimeofday( &now, 0 );
-
-  jnode->stat_ctime = now.tv_sec;
+  jnode->stat_ctime = _IMFS_get_time();
 }
 
 static inline void IMFS_mtime_ctime_update( IMFS_jnode_t *jnode )
 {
-  struct timeval now;
+  time_t now;
 
-  gettimeofday( &now, 0 );
+  now = _IMFS_get_time();
 
-  jnode->stat_mtime = now.tv_sec;
-  jnode->stat_ctime = now.tv_sec;
+  jnode->stat_mtime = now;
+  jnode->stat_ctime = now;
 }
 
 typedef struct {




More information about the vc mailing list