From 89d000be08997cd937a11d88a96c5ae09367327d Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Tue, 18 Dec 2012 14:32:12 -0700 Subject: [PATCH 1/6] fixed problems with ca clear channel protocol during reload of the access security file. See https://bugs.launchpad.net/epics-base/+bug/1091401. --- src/rsrv/camessage.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/rsrv/camessage.c b/src/rsrv/camessage.c index 09015f667..ba83af1b3 100644 --- a/src/rsrv/camessage.c +++ b/src/rsrv/camessage.c @@ -1992,6 +1992,15 @@ static int clear_channel_reply ( caHdrLargeArray *mp, cas_commit_msg ( client, 0u ); SEND_UNLOCK(client); + /* + * remove from access control list + */ + status = asRemoveClient(&pciu->asClientPVT); + if(status != 0 && status != S_asLib_asNotActive){ + errMessage(status, RECORD_NAME(&pciu->addr)); + return RSRV_ERROR; + } + epicsMutexMustLock ( client->chanListLock ); if ( pciu->state == rsrvCS_inService || pciu->state == rsrvCS_pendConnectResp ) { @@ -2011,15 +2020,6 @@ static int clear_channel_reply ( caHdrLargeArray *mp, } epicsMutexUnlock( client->chanListLock ); - /* - * remove from access control list - */ - status = asRemoveClient(&pciu->asClientPVT); - if(status != 0 && status != S_asLib_asNotActive){ - errMessage(status, RECORD_NAME(&pciu->addr)); - return RSRV_ERROR; - } - LOCK_CLIENTQ; status = bucketRemoveItemUnsignedId (pCaBucket, &pciu->sid); if(status != S_bucket_success){ From 038a1140f4aaaf809094975b0bfcb3431c361346 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 9 Jan 2013 18:12:30 -0600 Subject: [PATCH 2/6] Fix drift in periodic scan times. Method from Eric Norum, with warnings added by me. Fixes lp:597054 --- documentation/RELEASE_NOTES.html | 18 +++++++++++- src/db/dbScan.c | 48 ++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html index 75e082b9c..28558de46 100644 --- a/documentation/RELEASE_NOTES.html +++ b/documentation/RELEASE_NOTES.html @@ -9,10 +9,26 @@

EPICS Base Release 3.14.12.3

-

Changes between 3.14.12.2 and 3.14.12.3

+

Changes between 3.14.12.3 and 3.14.12.4

+

Time drift in periodic scans

+ +

The implementation of the periodic scan code has been modified to remove +long-term drift associated with OS thread sheduling. The new code keeps scan +times much more closely tied to the system clock tick, only allowing the scan +period to drift if the record processing time takes longer to execute than the +interval between scans. If this happens a 0.1 second penalty is given to the +scan thread (to allow lower priority threads time to process on preemptive +priority scheduled OSs). After 10 repeated over-runs a warning will be logged, +with an increasing delay between messages up to hourly.

+ +

This fixes launchpad bug +597054.

+ +

Changes between 3.14.12.2 and 3.14.12.3

+

Hex literals in CALC expressions

In previous releases, CALC expressions could contain hexadecimal literal diff --git a/src/db/dbScan.c b/src/db/dbScan.c index a6dec93a9..43303453d 100644 --- a/src/db/dbScan.c +++ b/src/db/dbScan.c @@ -85,6 +85,7 @@ typedef struct scan_element{ typedef struct periodic_scan_list { scan_list scan_list; double period; + unsigned long overruns; volatile enum ctl scanCtl; epicsEventId loopEvent; } periodic_scan_list; @@ -366,7 +367,8 @@ int scanppl(double period) /* print periodic list */ ppsl = papPeriodic[i]; if (ppsl == NULL) continue; if (period > 0.0 && (fabs(period - ppsl->period) >.05)) continue; - sprintf(message, "Scan Period = %g seconds ", ppsl->period); + sprintf(message, "Scan Period = %g seconds (%lu over-runs)", + ppsl->period, ppsl->overruns); printList(&ppsl->scan_list, message); } return 0; @@ -541,19 +543,47 @@ static void initOnce(void) static void periodicTask(void *arg) { periodic_scan_list *ppsl = (periodic_scan_list *)arg; - - epicsTimeStamp start_time, end_time; - double delay; + epicsTimeStamp next, reported; + unsigned int overruns = 0; + double report_delay = 10.0; taskwdInsert(0, NULL, NULL); epicsEventSignal(startStopEvent); + epicsTimeGetCurrent(&next); + reported = next; + while (ppsl->scanCtl != ctlExit) { - epicsTimeGetCurrent(&start_time); - if (ppsl->scanCtl == ctlRun) scanList(&ppsl->scan_list); - epicsTimeGetCurrent(&end_time); - delay = ppsl->period - epicsTimeDiffInSeconds(&end_time, &start_time); - if (delay <= 0.0) delay = 0.1; + double delay; + epicsTimeStamp now; + + if (ppsl->scanCtl == ctlRun) + scanList(&ppsl->scan_list); + + epicsTimeAddSeconds(&next, ppsl->period); + epicsTimeGetCurrent(&now); + delay = epicsTimeDiffInSeconds(&next, &now); + if (delay <= 0.0) { + delay = 0.1; + ppsl->overruns++; + next = now; + if (++overruns >= 10 && + epicsTimeDiffInSeconds(&now, &reported) > report_delay) { + errlogPrintf("dbScan warning: %g second scan over-ran %u times\n", + ppsl->period, overruns); + + reported = now; + if (report_delay < 1800.0) + report_delay *= 2; + else + report_delay = 3600.0; /* At most hourly */ + } + } + else { + overruns = 0; + report_delay = 10.0; + } + epicsEventWaitWithTimeout(ppsl->loopEvent, delay); } From 451c4cc8545baceb8118c118f600380378360445 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 23 Jan 2013 07:29:07 -0600 Subject: [PATCH 3/6] Unify #! line for Perl scripts /usr/bin/env exists on all current workstation OSs. --- src/cap5/caget.pl | 2 +- src/cap5/cainfo.pl | 2 +- src/cap5/camonitor.pl | 2 +- src/cap5/capr.pl | 2 +- src/cap5/caput.pl | 2 +- src/cap5/perlConfig.pl | 2 +- src/makeBaseApp/makeBaseApp.pl | 3 +-- src/makeBaseExt/makeBaseExt.pl | 3 +-- src/registry/registerRecordDeviceDriver.pl | 3 +-- src/tools/convertRelease.pl | 3 +-- src/tools/cvsclean.pl | 3 +-- src/tools/dos2unix.pl | 3 +-- src/tools/expandVars.pl | 2 +- src/tools/filterWarnings.pl | 3 +-- src/tools/fullPathName.pl | 3 +-- src/tools/installEpics.pl | 2 +- src/tools/makeIncludeDbd.pl | 2 +- src/tools/makeMakefile.pl | 2 +- src/tools/makeTestfile.pl | 2 +- src/tools/mkmf.pl | 2 +- src/tools/munch.pl | 2 +- src/tools/replaceVAR.pl | 3 +-- src/tools/useManifestTool.pl | 4 +--- 23 files changed, 23 insertions(+), 34 deletions(-) diff --git a/src/cap5/caget.pl b/src/cap5/caget.pl index 7fe60d8c5..df8cb6d25 100644 --- a/src/cap5/caget.pl +++ b/src/cap5/caget.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; diff --git a/src/cap5/cainfo.pl b/src/cap5/cainfo.pl index 2f8231494..2196655b1 100644 --- a/src/cap5/cainfo.pl +++ b/src/cap5/cainfo.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; diff --git a/src/cap5/camonitor.pl b/src/cap5/camonitor.pl index 559ec1233..4d19272b2 100644 --- a/src/cap5/camonitor.pl +++ b/src/cap5/camonitor.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; diff --git a/src/cap5/capr.pl b/src/cap5/capr.pl index 4f8abac3d..04f1caa97 100644 --- a/src/cap5/capr.pl +++ b/src/cap5/capr.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl ####################################################################### # diff --git a/src/cap5/caput.pl b/src/cap5/caput.pl index bc62eead4..8d2e6b4b3 100644 --- a/src/cap5/caput.pl +++ b/src/cap5/caput.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; diff --git a/src/cap5/perlConfig.pl b/src/cap5/perlConfig.pl index 11a524595..01b9b9fdd 100644 --- a/src/cap5/perlConfig.pl +++ b/src/cap5/perlConfig.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # This script is used to extract information about the Perl build # configuration, so the EPICS build system uses the same settings. diff --git a/src/makeBaseApp/makeBaseApp.pl b/src/makeBaseApp/makeBaseApp.pl index 7a816a0eb..cf65d290f 100755 --- a/src/makeBaseApp/makeBaseApp.pl +++ b/src/makeBaseApp/makeBaseApp.pl @@ -1,5 +1,4 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; # makeBaseApp +#!/usr/bin/env perl # Authors: Ralph Lange, Marty Kraimer, Andrew Johnson and Janet Anderson # $Revision-Id$ diff --git a/src/makeBaseExt/makeBaseExt.pl b/src/makeBaseExt/makeBaseExt.pl index 42855aa2f..307764823 100755 --- a/src/makeBaseExt/makeBaseExt.pl +++ b/src/makeBaseExt/makeBaseExt.pl @@ -1,5 +1,4 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; # makeBaseExt +#!/usr/bin/env perl # Authors: Ralph Lange, Marty Kraimer, Andrew Johnson and Janet Anderson # $Revision-Id$ diff --git a/src/registry/registerRecordDeviceDriver.pl b/src/registry/registerRecordDeviceDriver.pl index 3fa64cbe3..06698c867 100755 --- a/src/registry/registerRecordDeviceDriver.pl +++ b/src/registry/registerRecordDeviceDriver.pl @@ -1,5 +1,4 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; # registerRecordDeviceDriver +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne # National Laboratory. diff --git a/src/tools/convertRelease.pl b/src/tools/convertRelease.pl index f6eb50e73..586e5ee35 100644 --- a/src/tools/convertRelease.pl +++ b/src/tools/convertRelease.pl @@ -1,5 +1,4 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; # convertRelease.pl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne # National Laboratory. diff --git a/src/tools/cvsclean.pl b/src/tools/cvsclean.pl index 09ecdf77c..b1398fda5 100644 --- a/src/tools/cvsclean.pl +++ b/src/tools/cvsclean.pl @@ -1,5 +1,4 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; # cvsclean.pl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2002 The University of Chicago, as Operator of Argonne # National Laboratory. diff --git a/src/tools/dos2unix.pl b/src/tools/dos2unix.pl index c10282a3e..4940fd5f2 100644 --- a/src/tools/dos2unix.pl +++ b/src/tools/dos2unix.pl @@ -1,5 +1,4 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; # makeConfigAppInclude.pl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2002 The University of Chicago, as Operator of Argonne # National Laboratory. diff --git a/src/tools/expandVars.pl b/src/tools/expandVars.pl index 2100315da..5015fe07a 100644 --- a/src/tools/expandVars.pl +++ b/src/tools/expandVars.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # Tool to expand @VAR@ variables while copying a file. # The file will *not* be copied if it already exists. diff --git a/src/tools/filterWarnings.pl b/src/tools/filterWarnings.pl index 2e9153490..5f346cd46 100644 --- a/src/tools/filterWarnings.pl +++ b/src/tools/filterWarnings.pl @@ -1,5 +1,4 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; # filterWarnings.pl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2002 The University of Chicago, as Operator of Argonne # National Laboratory. diff --git a/src/tools/fullPathName.pl b/src/tools/fullPathName.pl index 27fc57a21..a553dbd3c 100644 --- a/src/tools/fullPathName.pl +++ b/src/tools/fullPathName.pl @@ -1,5 +1,4 @@ -eval 'exec perl -S -w $0 ${1+"$@"}' # -*- Mode: perl -*- - if 0; +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2009 UChicago Argonne LLC, as Operator of Argonne # National Laboratory. diff --git a/src/tools/installEpics.pl b/src/tools/installEpics.pl index 3340bd5c3..0dfec1144 100644 --- a/src/tools/installEpics.pl +++ b/src/tools/installEpics.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2011 UChicago Argonne LLC, as Operator of Argonne # National Laboratory. diff --git a/src/tools/makeIncludeDbd.pl b/src/tools/makeIncludeDbd.pl index b42f6f3d8..c0b8238db 100644 --- a/src/tools/makeIncludeDbd.pl +++ b/src/tools/makeIncludeDbd.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2002 The University of Chicago, as Operator of Argonne # National Laboratory. diff --git a/src/tools/makeMakefile.pl b/src/tools/makeMakefile.pl index 80383ab3f..ea48d1c9b 100644 --- a/src/tools/makeMakefile.pl +++ b/src/tools/makeMakefile.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2002 The University of Chicago, as Operator of Argonne # National Laboratory. diff --git a/src/tools/makeTestfile.pl b/src/tools/makeTestfile.pl index 7b4f010bb..80f6f4d38 100644 --- a/src/tools/makeTestfile.pl +++ b/src/tools/makeTestfile.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne # National Laboratory. diff --git a/src/tools/mkmf.pl b/src/tools/mkmf.pl index fa3c5055c..4334d298e 100644 --- a/src/tools/mkmf.pl +++ b/src/tools/mkmf.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2009 Helmholtz-Zentrum Berlin fuer Materialien und Energie. # Copyright (c) 2002 The University of Chicago, as Operator of Argonne diff --git a/src/tools/munch.pl b/src/tools/munch.pl index a51c079c5..2ed6567fb 100644 --- a/src/tools/munch.pl +++ b/src/tools/munch.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne # National Laboratory. diff --git a/src/tools/replaceVAR.pl b/src/tools/replaceVAR.pl index 4c50f1a19..82c76bb3d 100644 --- a/src/tools/replaceVAR.pl +++ b/src/tools/replaceVAR.pl @@ -1,5 +1,4 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; # replaceVAR.pl +#!/usr/bin/env perl #************************************************************************* # Copyright (c) 2002 The University of Chicago, as Operator of Argonne # National Laboratory. diff --git a/src/tools/useManifestTool.pl b/src/tools/useManifestTool.pl index 45986b662..9e59e9f1f 100644 --- a/src/tools/useManifestTool.pl +++ b/src/tools/useManifestTool.pl @@ -1,6 +1,4 @@ -eval 'exec perl -S -w $0 ${1+"$@"}' # -*- Mode: perl -*- - if 0; - +#!/usr/bin/env perl # # Use MS Visual C++ compiler version number to determine if # we want to use the Manifest Tool (status=1) or not (status=0) From 8400e74606e8280016174f64ebf478eb6607c8f3 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 29 Jan 2013 18:02:51 -0600 Subject: [PATCH 4/6] Fix epicsRingPointerGetSize() Definition name didn't match declaration. Fixes lp:1109785 reported by Martin Konrad. --- src/libCom/ring/epicsRingPointer.cpp | 7 +++---- src/libCom/ring/epicsRingPointer.h | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libCom/ring/epicsRingPointer.cpp b/src/libCom/ring/epicsRingPointer.cpp index 5118c9347..3a5cc8c72 100644 --- a/src/libCom/ring/epicsRingPointer.cpp +++ b/src/libCom/ring/epicsRingPointer.cpp @@ -3,9 +3,8 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ /*epicsRingPointer.cpp*/ /* Author: Marty Kraimer Date: 13OCT2000 */ @@ -63,7 +62,7 @@ epicsShareFunc int epicsShareAPI epicsRingPointerGetUsed(epicsRingPointerId id) return(pvoidPointer->getUsed()); } -epicsShareFunc int epicsShareAPI epicsRingPointerSize(epicsRingPointerId id) +epicsShareFunc int epicsShareAPI epicsRingPointerGetSize(epicsRingPointerId id) { voidPointer *pvoidPointer = reinterpret_cast(id); return(pvoidPointer->getSize()); diff --git a/src/libCom/ring/epicsRingPointer.h b/src/libCom/ring/epicsRingPointer.h index 57534586a..3332782a4 100644 --- a/src/libCom/ring/epicsRingPointer.h +++ b/src/libCom/ring/epicsRingPointer.h @@ -3,9 +3,8 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ /*epicsRingPointer.h */ @@ -67,6 +66,9 @@ epicsShareFunc int epicsShareAPI epicsRingPointerGetSize(epicsRingPointerId id) epicsShareFunc int epicsShareAPI epicsRingPointerIsEmpty(epicsRingPointerId id); epicsShareFunc int epicsShareAPI epicsRingPointerIsFull(epicsRingPointerId id); +/* This routine was incorrectly named in previous releases */ +#define epicsRingPointerSize epicsRingPointerGetSize + #ifdef __cplusplus } #endif From c767958539882f127fb4d4551ce3279a5a175699 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 11 Feb 2013 17:49:05 -0600 Subject: [PATCH 5/6] gdd: Build tweaks Remove obselete HPUX warning flags Disable strict-aliasing to suppress warnings (RTEMS, Linux) --- src/gdd/Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/gdd/Makefile b/src/gdd/Makefile index e6c58c1d2..1b923cb35 100644 --- a/src/gdd/Makefile +++ b/src/gdd/Makefile @@ -62,12 +62,8 @@ genApps_SYS_LIBS_WIN32 = ws2_32 # aitGen.c doesn't compile for linux-arm at -O3 when using gcc-3.4.5 aitGen_CFLAGS_linux-arm = -O2 -# Switch off potentially bogus warnings on HPUX 11 - detailed warning -# suppression in the source code would be too much effort with respect -# to gdd's limited future - -HPWARNFLAGS_NO = +W361 +W392 +W655 +W749 +W818 +W930 -USR_CXXFLAGS_hpux = $(HPWARNFLAGS_$(GNU)) +USR_CXXFLAGS_Linux = -fno-strict-aliasing +USR_CXXFLAGS_RTEMS = -fno-strict-aliasing include $(TOP)/configure/RULES From 738b8ca55f3d4e67c7247ccb4de1745bc144fdfe Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 13 Mar 2013 14:48:34 -0500 Subject: [PATCH 6/6] libCom: Add a High-Resolution Time Provider on MacOS Since Apple don't support clock_gettime(CLOCK_REALTIME) I added a new time provider that uses the Mach kernel Clock service to get nanosecond resolution time. --- documentation/RELEASE_NOTES.html | 10 ++++ src/libCom/osi/os/Darwin/osdTime.cpp | 86 ++++++++++++++++++++++++++++ src/libCom/osi/os/posix/osdTime.cpp | 2 +- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/libCom/osi/os/Darwin/osdTime.cpp diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html index 28558de46..98c9415b1 100644 --- a/documentation/RELEASE_NOTES.html +++ b/documentation/RELEASE_NOTES.html @@ -13,6 +13,16 @@ +

High-Resolution Time Provider on MacOS

+ +

MacOS does not provide the clock_gettime() API with CLOCK_REALTIME that other +Posix systems implement, so we previously used gettimeofday() to fetch the +current date & time from the OS. That older routine only provides the time with +a resolution of 1 microsecond though, whereas clock_gettime() gives results with +a nanosecond resolution. This release uses a new MachTime time provider on +MacOS which uses the Mach Kernel's CALENDAR_CLOCK service to fetch the time, and +provides nanosecond resolution.

+

Time drift in periodic scans

The implementation of the periodic scan code has been modified to remove diff --git a/src/libCom/osi/os/Darwin/osdTime.cpp b/src/libCom/osi/os/Darwin/osdTime.cpp new file mode 100644 index 000000000..f3e6db5dd --- /dev/null +++ b/src/libCom/osi/os/Darwin/osdTime.cpp @@ -0,0 +1,86 @@ +/*************************************************************************\ +* Copyright (c) 2013 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2002 The Regents of the University of California, as +* Operator of Los Alamos National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "osiSock.h" + +#define epicsExportSharedSymbols +#include "cantProceed.h" +#include "epicsTime.h" +#include "generalTimeSup.h" + +static clock_serv_t host_clock; + +extern "C" { +static int osdTimeGetCurrent (epicsTimeStamp *pDest) +{ + mach_timespec_t mts; + struct timespec ts; + + clock_get_time(host_clock, &mts); + ts.tv_sec = mts.tv_sec; + ts.tv_nsec = mts.tv_nsec; + *pDest = epicsTime(ts); + return epicsTimeOK; +} +} // extern "C" + + +static int timeRegister(void) +{ + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &host_clock); + + generalTimeCurrentTpRegister("MachTime", \ + LAST_RESORT_PRIORITY, osdTimeGetCurrent); + return 1; +} +static int done = timeRegister(); + + +int epicsTime_gmtime(const time_t *pAnsiTime, struct tm *pTM) +{ + return gmtime_r(pAnsiTime, pTM) ? + epicsTimeOK : epicsTimeERROR; +} + +int epicsTime_localtime(const time_t *clock, struct tm *result) +{ + return localtime_r(clock, result) ? + epicsTimeOK : epicsTimeERROR; +} + +extern "C" epicsShareFunc void +convertDoubleToWakeTime(double timeout, struct timespec *wakeTime) +{ + mach_timespec_t now; + struct timespec wait; + + clock_get_time(host_clock, &now); + + if (timeout<0.0) + timeout = 0.0; + else if(timeout>3600.0) + timeout = 3600.0; + + wait.tv_sec = static_cast< long >(timeout); + wait.tv_nsec = static_cast< long >((timeout - (double)wait.tv_sec) * 1e9); + + wakeTime->tv_sec = now.tv_sec + wait.tv_sec; + wakeTime->tv_nsec = now.tv_nsec + wait.tv_nsec; + if (wakeTime->tv_nsec >= 1000000000L) { + wakeTime->tv_nsec -= 1000000000L; + ++wakeTime->tv_sec; + } +} diff --git a/src/libCom/osi/os/posix/osdTime.cpp b/src/libCom/osi/os/posix/osdTime.cpp index 62939a427..987629f51 100644 --- a/src/libCom/osi/os/posix/osdTime.cpp +++ b/src/libCom/osi/os/posix/osdTime.cpp @@ -24,7 +24,7 @@ #define TIME_INIT ClockTime_Init(CLOCKTIME_NOSYNC) #else - /* Some posix systems like Darwin don't have CLOCK_REALTIME */ + /* Some posix systems may not have CLOCK_REALTIME */ #define TIME_INIT generalTimeCurrentTpRegister("GetTimeOfDay", \ LAST_RESORT_PRIORITY, osdTimeGetCurrent)