Changeset 10a97ad for src/libcfa


Ignore:
Timestamp:
Apr 12, 2018, 8:53:12 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
07b8001
Parents:
2ae8507
Message:

reduce size of "time"

Location:
src/libcfa
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/Makefile.am

    r2ae8507 r10a97ad  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Tue Apr 10 15:20:28 2018
    14 ## Update Count     : 230
     13## Last Modified On : Thu Apr 12 14:38:34 2018
     14## Update Count     : 231
    1515###############################################################################
    1616
     
    101101        gmp                             \
    102102        time_t.h                        \
     103        clock                   \
    103104        bits/align.h            \
    104105        bits/containers.h               \
  • src/libcfa/Makefile.in

    r2ae8507 r10a97ad  
    265265        concurrency/thread concurrency/kernel concurrency/monitor \
    266266        ${shell find stdhdr -type f -printf "%p "} math gmp time_t.h \
    267         bits/align.h bits/containers.h bits/defs.h bits/debug.h \
     267        clock bits/align.h bits/containers.h bits/defs.h bits/debug.h \
    268268        bits/locks.h concurrency/invoke.h
    269269HEADERS = $(nobase_cfa_include_HEADERS)
     
    438438        gmp                             \
    439439        time_t.h                        \
     440        clock                   \
    440441        bits/align.h            \
    441442        bits/containers.h               \
  • src/libcfa/iostream

    r2ae8507 r10a97ad  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan 25 13:08:39 2018
    13 // Update Count     : 149
     12// Last Modified On : Thu Apr 12 14:34:37 2018
     13// Update Count     : 150
    1414//
    1515
     
    159159forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Istream_cstrC );
    160160
     161
     162#include <time_t.h>                                                                             // Duration (constructors) / Time (constructors)
     163
     164forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur );
     165forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
     166
     167
    161168// Local Variables: //
    162169// mode: c //
  • src/libcfa/time

    r2ae8507 r10a97ad  
    1010// Created On       : Wed Mar 14 23:18:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 10 17:25:34 2018
    13 // Update Count     : 622
     12// Last Modified On : Thu Apr 12 16:53:35 2018
     13// Update Count     : 629
    1414//
    1515
     
    2323#include <sys/time.h>                                                                   // timeval
    2424}
    25 #include <iostream>                                                                             // istype/ostype
     25#include <time_t.h>                                                                             // Duration/Time types
    2626
    2727enum { TIMEGRAN = 1_000_000_000LL };                                    // nanosecond granularity, except for timeval
    2828
    29 #include <time_t.h>                                                                             // Duration (constructors) / Time (constructors)
    3029
    3130//######################### Duration #########################
     
    6867
    6968static inline Duration abs( Duration rhs ) { return rhs.tv >= 0 ? rhs : -rhs; }
    70 
    71 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur );
    7269
    7370static inline Duration ?`ns( int64_t nsec ) { return (Duration)@{ nsec }; }
     
    136133
    137134
    138 //######################### C time #########################
    139 
    140 static inline char * ctime( time_t tp ) { char * buf = ctime( &tp ); buf[24] = '\0'; return buf; }
    141 static inline char * ctime_r( time_t tp, char * buf ) { ctime_r( &tp, buf ); buf[24] = '\0'; return buf; }
    142 static inline tm * gmtime( time_t tp ) { return gmtime( &tp ); }
    143 static inline tm * gmtime_r( time_t tp, tm * result ) { return gmtime_r( &tp, result ); }
    144 static inline tm * localtime( time_t tp ) { return localtime( &tp ); }
    145 static inline tm * localtime_r( time_t tp, tm * result ) { return localtime_r( &tp, result ); }
    146 
    147 
    148135//######################### Time #########################
    149136
     
    199186size_t strftime( char * buf, size_t size, const char * fmt, Time time );
    200187
    201 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time );
    202 
    203188//------------------------- timeval (cont) -------------------------
    204189
     
    215200} // ?{}
    216201
    217 
    218 //######################### Clock #########################
    219 
    220 struct Clock {                                                                                  // private
    221         Duration offset;                                                                        // for virtual clock: contains offset from real-time
    222         int clocktype;                                                                          // implementation only -1 (virtual), CLOCK_REALTIME
    223 };
    224 
    225 static inline void resetClock( Clock & clk ) with( clk ) {
    226         clocktype = CLOCK_REALTIME_COARSE;
    227 } // Clock::resetClock
    228 
    229 static inline void resetClock( Clock & clk, Duration adj ) with( clk ) {
    230         clocktype = -1;
    231         offset = adj + timezone`s;                                                      // timezone (global) is (UTC - local time) in seconds
    232 } // resetClock
    233 
    234 static inline void ?{}( Clock & clk ) { resetClock( clk ); }
    235 static inline void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); }
    236 
    237 static inline Duration getRes() {
    238         struct timespec res;
    239         clock_getres( CLOCK_REALTIME_COARSE, &res );
    240         return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
    241 } // getRes
    242 
    243 static inline Time getTimeNsec() {                                              // with nanoseconds
    244         timespec curr;
    245         clock_gettime( CLOCK_REALTIME_COARSE, &curr );
    246         return (Time){ curr };
    247 } // getTime
    248 
    249 static inline Time getTime() {                                                  // without nanoseconds
    250         timespec curr;
    251         clock_gettime( CLOCK_REALTIME_COARSE, &curr );
    252         curr.tv_nsec = 0;
    253         return (Time){ curr };
    254 } // getTime
    255 
    256 static inline Time getTime( Clock & clk ) with( clk ) {
    257         return getTime() + offset;
    258 } // getTime
    259 
    260 static inline Time ?()( Clock & clk ) with( clk ) {             // alternative syntax
    261         return getTime() + offset;
    262 } // getTime
    263 
    264 static inline timeval getTime( Clock & clk ) {
    265         return (timeval){ clk() };
    266 } // getTime
    267 
    268 static inline tm getTime( Clock & clk ) with( clk ) {
    269         tm ret;
    270         localtime_r( getTime( clk ).tv_sec, &ret );
    271         return ret;
    272 } // getTime
    273 
    274202// Local Variables: //
    275203// mode: c //
  • src/libcfa/time.c

    r2ae8507 r10a97ad  
    1010// Created On       : Tue Mar 27 13:33:14 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Apr  1 17:30:08 2018
    13 // Update Count     : 21
     12// Last Modified On : Thu Apr 12 14:41:00 2018
     13// Update Count     : 22
    1414//
    1515
    1616#include "time"
     17#include "iostream"
    1718#include <stdio.h>                                                                              // snprintf
    1819
Note: See TracChangeset for help on using the changeset viewer.