From 52c588287e55342e3c6df9b1a34480baa0747f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Sat, 15 Apr 2017 21:19:51 +0200 Subject: [PATCH] 2017-04-15 21:19 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/common/hbdate.c * implemented monotonic timers in POSIX and MS-Windows builds * config/wce/global.mk * config/wce/mingwarm.mk * config/win/global.mk * utils/hbmk2/hbmk2.prg * added winmm/mmtimer to list of system libraries - required for timeGetTime() * ChangeLog.txt ! typos --- ChangeLog.txt | 20 ++++++++++++--- config/aix/libs.mk | 3 +-- config/cygwin/libs.mk | 4 +-- config/hpux/libs.mk | 3 +-- config/linux/libs.mk | 4 +-- config/sunos/libs.mk | 4 +-- config/wce/global.mk | 2 +- config/wce/mingwarm.mk | 2 ++ config/win/global.mk | 2 +- src/common/hbdate.c | 57 ++++++++++++++++++++++++++++++++++++++++-- utils/hbmk2/hbmk2.prg | 5 +++- 11 files changed, 88 insertions(+), 18 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index cff18e4b50..0b40bd6ca3 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,20 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2017-04-15 21:19 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/common/hbdate.c + * implemented monotonic timers in POSIX and MS-Windows builds + + * config/wce/global.mk + * config/wce/mingwarm.mk + * config/win/global.mk + * utils/hbmk2/hbmk2.prg + * added winmm/mmtimer to list of system libraries - required + for timeGetTime() + + * ChangeLog.txt + ! typos + 2017-04-14 17:17 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/harbour.def * removed hb_fsPoll() added by mistake - it's only in *nix builds @@ -18,8 +32,8 @@ * include/hbapifs.h * src/rtl/filesys.c + added new C functions for UNIX and DJGPP builds: - int hb_fsPollFD( PHB_POLLFD pPollSet, int iCount, - HB_MAXINT nTimeOut ); + int hb_fsPoll( PHB_POLLFD pPollSet, int iCount, + HB_MAXINT nTimeOut ); int hb_fsCanRead( HB_FHANDLE hFileHandle, HB_MAXINT nTimeOut ); int hb_fsCanWrite( HB_FHANDLE hFileHandle, HB_MAXINT nTimeOut ); These functions should be used instead of select() in C code to hide @@ -38,7 +52,7 @@ corresponding hb_socket*() and hb_fsPipe*() API but not for all other cases. This one is for POSIX compilant code which needs pure POSIX select()/poll() functionality. - Please note that HB_POLLFD structure should is compatible with + Please note that HB_POLLFD structure should be compatible with struct pollfd defined by POSIX.1-2001 anyhow not all platforms confirm this standard so portable Harbour code should always use HB_POLLFD and HB_POLL* constant values instead of POLL* ones. diff --git a/config/aix/libs.mk b/config/aix/libs.mk index fe0450b4ad..42d5d2c51d 100644 --- a/config/aix/libs.mk +++ b/config/aix/libs.mk @@ -30,11 +30,10 @@ ifneq ($(HB_LINKING_RTL),) ifeq ($(HB_HAS_ZLIB_LOCAL),) SYSLIBS += z endif - SYSLIBS += rt ifneq ($(HB_LINKING_VMMT),) SYSLIBS += pthread endif endif -SYSLIBS += m +SYSLIBS += m rt diff --git a/config/cygwin/libs.mk b/config/cygwin/libs.mk index 54ceeb3b3a..063130eb9b 100644 --- a/config/cygwin/libs.mk +++ b/config/cygwin/libs.mk @@ -21,11 +21,11 @@ ifneq ($(HB_LINKING_RTL),) ifeq ($(HB_HAS_ZLIB_LOCAL),) SYSLIBS += z endif - SYSLIBS += rt dl + SYSLIBS += dl # Don't seem to be needed here, but added it for reference to move/copy it to *nix platforms where this is required ifneq ($(HB_LINKING_VMMT),) SYSLIBS += pthread endif endif -SYSLIBS += m +SYSLIBS += m rt diff --git a/config/hpux/libs.mk b/config/hpux/libs.mk index c5d77fd753..8b765e34ea 100644 --- a/config/hpux/libs.mk +++ b/config/hpux/libs.mk @@ -22,7 +22,6 @@ ifneq ($(HB_LINKING_RTL),) ifeq ($(HB_HAS_ZLIB_LOCAL),) SYSLIBS += z endif - SYSLIBS += rt endif -SYSLIBS += m +SYSLIBS += m rt diff --git a/config/linux/libs.mk b/config/linux/libs.mk index 0350e6d0d8..26d00cf045 100644 --- a/config/linux/libs.mk +++ b/config/linux/libs.mk @@ -29,7 +29,7 @@ ifneq ($(HB_LINKING_RTL),) ifeq ($(HB_HAS_ZLIB_LOCAL),) SYSLIBS += z endif - SYSLIBS += rt dl + SYSLIBS += dl # Don't seem to be needed here, but added it for reference to move/copy it to *nix platforms where this is required ifneq ($(HB_LINKING_VMMT),) SYSLIBS += pthread @@ -40,4 +40,4 @@ else endif endif -SYSLIBS += m +SYSLIBS += m rt diff --git a/config/sunos/libs.mk b/config/sunos/libs.mk index 6d74cbcbbd..6426b08ec0 100644 --- a/config/sunos/libs.mk +++ b/config/sunos/libs.mk @@ -22,7 +22,7 @@ ifneq ($(HB_LINKING_RTL),) ifeq ($(HB_HAS_ZLIB_LOCAL),) SYSLIBS += z endif - SYSLIBS += rt socket nsl resolv + SYSLIBS += socket nsl resolv endif -SYSLIBS += m +SYSLIBS += m rt diff --git a/config/wce/global.mk b/config/wce/global.mk index d6cd39baa3..edc7ec963c 100644 --- a/config/wce/global.mk +++ b/config/wce/global.mk @@ -9,4 +9,4 @@ HB_CFLAGS += -DUNDER_CE HB_GT_LIBS += gtwvt gtgui -SYSLIBS += coredll ws2 iphlpapi +SYSLIBS += coredll ws2 iphlpapi winmm diff --git a/config/wce/mingwarm.mk b/config/wce/mingwarm.mk index 9ab512b24f..39e5c9ceb3 100644 --- a/config/wce/mingwarm.mk +++ b/config/wce/mingwarm.mk @@ -50,6 +50,8 @@ endif LD := $(CC) LD_OUT := -o$(subst x,x, ) +SYSLIBS := $(subst winmm,mmtimer,$(SYSLIBS)) + LIBPATHS := $(foreach dir,$(LIB_DIR),-L$(dir)) LDLIBS := $(foreach lib,$(HB_USER_LIBS) $(LIBS) $(SYSLIBS),-l$(lib)) diff --git a/config/win/global.mk b/config/win/global.mk index 8a173f73a5..a7588a0d2d 100644 --- a/config/win/global.mk +++ b/config/win/global.mk @@ -22,4 +22,4 @@ ifneq ($(wildcard $(TOP)$(ROOT)lib/3rd/$(HB_PLATFORM)/$(HB_COMPILER)),) 3RDLIBS := unicows endif -SYSLIBS += kernel32 user32 ws2_32 iphlpapi advapi32 gdi32 +SYSLIBS += kernel32 user32 ws2_32 iphlpapi advapi32 gdi32 winmm diff --git a/src/common/hbdate.c b/src/common/hbdate.c index 40e76200f4..5d9a9b2f9f 100644 --- a/src/common/hbdate.c +++ b/src/common/hbdate.c @@ -1118,9 +1118,62 @@ double hb_timeLocalToUTC( double dTimeStamp ) HB_MAXUINT hb_timerGet( void ) { - HB_TRACE( HB_TR_DEBUG, ( "hb_timerInit()" ) ); + HB_TRACE( HB_TR_DEBUG, ( "hb_timerGet()" ) ); - return hb_dateMilliSeconds(); +#if defined( _POSIX_C_SOURCE ) && _POSIX_C_SOURCE >= 199309L && defined( CLOCK_REALTIME ) + static int s_iClkId = -1; + struct timespec ts; + + if( s_iClkId < 0 ) + { + int i, piClkId[] = { +# if defined( CLOCK_MONOTONIC ) + CLOCK_MONOTONIC, +# endif +# if defined( CLOCK_MONOTONIC_COARSE ) + CLOCK_MONOTONIC_COARSE, +# endif +# if defined( CLOCK_REALTIME ) + CLOCK_REALTIME, +# endif +# if defined( CLOCK_REALTIME_COARSE ) + CLOCK_REALTIME_COARSE, +# endif + 0 }; + + for( i = 0; i < ( int ) HB_SIZEOFARRAY( piClkId ); ++i ) + { + s_iClkId = piClkId[ i ]; + if( s_iClkId == 0 || clock_getres( s_iClkId, &ts ) == 0 ) + break; + } + } + if( s_iClkId != 0 && clock_gettime( s_iClkId, &ts ) == 0 ) + return ( HB_MAXUINT ) ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +#endif +#if defined( HB_OS_UNIX ) || defined( HB_OS_OS2 ) + { + struct timeval tv; + gettimeofday( &tv, NULL ); + return ( HB_MAXUINT ) tv.tv_sec * 1000 + tv.tv_usec / 1000; + } +#elif defined( HB_OS_WIN ) + { + static DWORD s_dwCounter = 0, s_dwLast = 0; + DWORD dwTime = timeGetTime(); + + if( dwTime < s_dwLast ) + ++s_dwCounter; + s_dwLast = dwTime; + return ( ( HB_MAXUINT ) s_dwCounter << 32 ) + dwTime; + } +#else + { + struct timeb tb; + ftime( &tb ); + return ( HB_MAXUINT ) tb.time * 1000 + tb.millitm; + } +#endif } HB_MAXUINT hb_timerInit( HB_MAXINT nTimeOut ) diff --git a/utils/hbmk2/hbmk2.prg b/utils/hbmk2/hbmk2.prg index 317404f20d..21be013941 100644 --- a/utils/hbmk2/hbmk2.prg +++ b/utils/hbmk2/hbmk2.prg @@ -4453,14 +4453,15 @@ STATIC FUNCTION __hbmk( aArgs, nArgTarget, nLevel, /* @ */ lPause, /* @ */ lExit ELSE AAdd( hbmk[ _HBMK_aOPTL ], "-o{OE}" ) ENDIF - l_aLIBSYS := ArrayAJoin( { l_aLIBSYS, l_aLIBSYSCORE, l_aLIBSYSMISC } ) IF hbmk[ _HBMK_lWINUNI ] AAdd( hbmk[ _HBMK_aOPTC ], "-DUNICODE" ) ENDIF IF hbmk[ _HBMK_cPLAT ] == "wce" + AAdd( l_aLIBSYS, "mmtimer" ) AAdd( hbmk[ _HBMK_aOPTC ], "-DUNDER_CE" ) AAdd( hbmk[ _HBMK_aOPTRES ], "-DUNDER_CE" ) ENDIF + l_aLIBSYS := ArrayAJoin( { l_aLIBSYS, l_aLIBSYSCORE, l_aLIBSYSMISC } ) DO CASE CASE _HBMODE_IS_XHB( hbmk[ _HBMK_nHBMODE ] ) /* NOTE: Newer xhb versions use "-x.y.z" version numbers. */ @@ -5207,6 +5208,7 @@ STATIC FUNCTION __hbmk( aArgs, nArgTarget, nLevel, /* @ */ lPause, /* @ */ lExit AAdd( hbmk[ _HBMK_aOPTC ], "-DUNICODE" ) ENDIF IF hbmk[ _HBMK_cPLAT ] == "wce" + AAdd( l_aLIBSYS, "winmm" ) AAdd( hbmk[ _HBMK_aOPTC ], "-DUNDER_CE" ) AAdd( hbmk[ _HBMK_aOPTRES ], "-DUNDER_CE" ) DO CASE @@ -5311,6 +5313,7 @@ STATIC FUNCTION __hbmk( aArgs, nArgTarget, nLevel, /* @ */ lPause, /* @ */ lExit AAdd( hbmk[ _HBMK_aOPTC ], "-DUNICODE" ) ENDIF IF hbmk[ _HBMK_cPLAT ] == "wce" + AAdd( l_aLIBSYS, "winmm" ) AAdd( hbmk[ _HBMK_aOPTC ], "-D_WINCE" ) /* Required by pocc Windows headers */ AAdd( hbmk[ _HBMK_aOPTC ], "-DUNDER_CE" ) AAdd( hbmk[ _HBMK_aOPTRES ], "-DUNDER_CE" )