]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/compat/posix/v2_0/src/time.cxx
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / compat / posix / v2_0 / src / time.cxx
index c4f5d701d52886ad92e6d206c487325ec15fb496..77f4fe175e1639709c0b2af6acc9ecdda2b8f402 100644 (file)
@@ -55,8 +55,6 @@
 
 #include <pkgconf/posix.h>
 
-#ifdef CYGPKG_POSIX_CLOCKS
-
 #include <pkgconf/hal.h>
 #include <pkgconf/kernel.h>
 
 #include "pprivate.h"                   // POSIX private header
 
 #include <time.h>                       // our header
+#include <sys/time.h>
 
 #include <cyg/kernel/thread.hxx>
 #include <cyg/kernel/clock.hxx>
+#include <cyg/kernel/kapi.h>
 
 #include <cyg/kernel/thread.inl>
 #include <cyg/kernel/clock.inl>
@@ -665,6 +665,11 @@ externC int nanosleep( const struct timespec *rqtp,
         ticks -= (now-then);
 
         cyg_ticks_to_timespec( ticks, rmtp );
+
+        // Check for cancellation and then notify the caller that we
+        // were interrupted.
+        PTHREAD_TESTCANCEL();
+        TIME_RETURN(EINTR);
     }
     
     // check if we were woken up because we were cancelled.
@@ -694,7 +699,20 @@ externC unsigned int sleep( unsigned int seconds )
     TIME_RETURN(0);
 } 
 
-#endif // ifdef CYGPKG_POSIX_CLOCKS
+// -------------------------------------------------------------------------
+// gettimeofday()
+// Get the current time in a struct timeval
+externC int gettimeofday(struct timeval* tv, struct timezone* tz)
+{
+    int ticks_per_second = 1000000000/
+      (CYGNUM_HAL_RTC_NUMERATOR/CYGNUM_HAL_RTC_DENOMINATOR);    
+    cyg_tick_count_t cur_time = cyg_current_time();
+    int tix = cur_time % ticks_per_second;
+    tv->tv_sec = cur_time / ticks_per_second;
+    tv->tv_usec = (tix * 1000000)/ticks_per_second;
+    return 0;
+}
+
 
 // -------------------------------------------------------------------------
 // EOF time.cxx