Ticket #7938: vxworks.hpp.diff

File vxworks.hpp.diff, 4.0 KB (added by Peter Brockamp <p.brockamp@…>, 10 years ago)

Further patches regarding the missing gettimeofday-function

  • C:/Daten/Libraries/Boost/boost/config/platform/vxworks.hpp

     
    7373// Generally available functionality:
    7474#define BOOST_HAS_THREADS
    7575#define BOOST_HAS_NANOSLEEP
     76#define BOOST_HAS_GETTIMEOFDAY
    7677#define BOOST_HAS_CLOCK_GETTIME
    7778#define BOOST_HAS_MACRO_USE_FACET
    7879
     
    8889
    8990// Functionality available for RTPs only:
    9091#ifdef __RTP__
    91 //#  define BOOST_HAS_GETTIMEOFDAY
    9292#  define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE
    9393#  define BOOST_HAS_LOG1P
    9494#  define BOOST_HAS_EXPM1
     
    122122//                 miserably fails to #include the required <sysLib.h> to make
    123123//                 sysClkRateGet() available! So we manually include it here.
    124124#ifdef __RTP__
     125#  include <time.h>
    125126#  include <sysLib.h>
    126127#endif
    127128
     
    151152// #include Libraries required for the following function adaption
    152153#include <ioLib.h>
    153154#include <tickLib.h>
     155#include <sys/time.h>
    154156
    155157// Use C-linkage for the following helper functions
    156158extern "C" {
     
    203205  return -1;
    204206}
    205207
     208// vxWorks claims to implement gettimeofday in sys/time.h
     209// but nevertheless does not provide it! See
     210// https://support.windriver.com/olsPortal/faces/maintenance/techtipDetail_noHeader.jspx?docId=16442&contentId=WR_TECHTIP_006256
     211// We implement a surrogate version here via clock_gettime:
     212inline int gettimeofday(struct timeval *tv, void * /*tzv*/) {
     213  struct timespec ts;
     214  clock_gettime(CLOCK_MONOTONIC, &ts);
     215  tv->tv_sec  = ts.tv_sec;
     216  tv->tv_usec = ts.tv_nsec / 1000;
     217  return 0;
     218}
     219
    206220// vxWorks does provide neither struct tms nor function times()!
    207221// We implement an empty dummy-function, simply setting the user
    208222// and system time to the half of thew actual system ticks-value
     
    221235};
    222236
    223237inline clock_t times(struct tms *t){
    224   clock_t ticks = static_cast<clock_t>(tickGet());
     238  struct timespec ts;
     239  clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
     240  clock_t ticks(static_cast<clock_t>(static_cast<double>(ts.tv_sec)  * CLOCKS_PER_SEC +
     241                                     static_cast<double>(ts.tv_nsec) * CLOCKS_PER_SEC / 1000000.0));
    225242  t->tms_utime  = ticks/2U;
    226243  t->tms_stime  = ticks/2U;
    227   t->tms_cutime = 0;
    228   t->tms_cstime = 0;
     244  t->tms_cutime = 0; // vxWorks is lacking the concept of a child process!
     245  t->tms_cstime = 0; // -> Set the wait times for childs to 0
    229246  return ticks;
    230247}
    231248
     
    241258  using ::symlink;
    242259  using ::readlink;
    243260  using ::times;
     261  using ::gettimeofday;
    244262}
    245263
    246264// Some more macro-magic:
    247265// vxWorks-around: Some functions are not present or broken in vxWorks
    248266//                 but may be patched to life via helper macros...
    249267
    250 // Include signal.h which contains a typo to be corrected here
     268// Include signal.h which might contain a typo to be corrected here
    251269#include <signal.h>
    252270
    253271#define getpagesize()    sysconf(_SC_PAGESIZE)         // getpagesize is deprecated anyway!
     
    259277#  define FPE_FLTINV     (FPE_FLTSUB+1)                // vxWorks has no FPE_FLTINV, so define one as a dummy
    260278#endif
    261279#if !defined(BUS_ADRALN) && defined(BUS_ADRALNR)
    262 #  define BUS_ADRALN     BUS_ADRALNR                   // Correct a supposed typo in vxWorks' <signal.h>?
     280#  define BUS_ADRALN     BUS_ADRALNR                   // Correct a supposed typo in vxWorks' <signal.h>
    263281#endif
    264282//typedef int              locale_t;                     // locale_t is a POSIX-extension, currently unpresent in vxWorks!
    265283
     
    268286
    269287// vxWorks lies about XSI conformance, there is no nl_types.h:
    270288#undef BOOST_HAS_NL_TYPES_H
    271 
    272 // vxWorks blatantly lies about implementing gettimeofday:
    273 // Though it even declares a prototype in sys/time.h, linking it fails!
    274 #undef BOOST_HAS_GETTIMEOFDAY
    275  Kein Zeilenumbruch am Ende der Datei