OSDN Git Service

Declare the nanosleep() function where POSIX expects it.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Tue, 16 Feb 2016 16:05:39 +0000 (16:05 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Tue, 16 Feb 2016 16:05:39 +0000 (16:05 +0000)
mingwrt/ChangeLog
mingwrt/include/time.h
mingwrt/include/unistd.h

index d91fd87..22ecbf7 100644 (file)
@@ -1,3 +1,14 @@
+2016-02-16  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Declare the nanosleep() function where POSIX expects it.
+
+       * include/time.h (__mingw_sleep): Declare function prototype.
+       (nanosleep): Declare prototype, and provide in-line implementation;
+       this is a reproduction of the original implementation, relocated...
+       * include/unistd.h (nanosleep): ...from here; remove it; hence...
+       (struct timespec): ...this need not be declared here, and there is
+       no need to include <parts/time.h>; remove reference.
+
 2016-02-15  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Refactor <time.h> vs. <wchar.h> to avoid duplication.
index 48b5db6..6d0c019 100644 (file)
@@ -325,6 +325,47 @@ __MINGW_IMPORT char        *tzname[2];
 
 #endif /* ! __MSVCRT__ */
 #endif /* ! _NO_OLDNAMES */
+
+#if _POSIX_C_SOURCE
+/* The nanosleep() function provides the most general purpose API for
+ * process/thread suspension; it provides for specification of periods
+ * ranging from ~7.5 ms mean, (on WinNT derivatives; ~27.5 ms on Win9x),
+ * extending up to ~136 years, (effectively eternity).
+ */
+__cdecl __MINGW_NOTHROW
+int nanosleep( const struct timespec *, struct timespec * );
+/*
+ * NOTE:
+ *
+ * Structure timespec is mandated by POSIX, for specification of
+ * intervals with the greatest precision supported by the OS kernel.
+ * Although this allows for specification to nanosecond precision, do
+ * not be deluded into any false expectation that such short intervals
+ * can be realized on Windows; on Win9x derivatives, the metronome used
+ * by the process scheduler has a period of ~55 milliseconds, while for
+ * WinNT derivatives, the corresponding period is ~15 milliseconds; thus,
+ * the shortest intervals which can be realistically timed will range
+ * from 0..55 milliseconds on Win9x hosts, and from 0..15 ms on WinNT,
+ * with period values normally distributed around means of ~27.5 ms
+ * and ~7.5 ms, for the two system types respectively.
+ */
+#ifndef __NO_INLINE__
+/* We may conveniently provide an in-line implementation here,
+ * in terms of the __mingw_sleep() helper function.
+ */
+__cdecl __MINGW_NOTHROW
+int __mingw_sleep( unsigned long, unsigned long );
+
+__CRT_INLINE __LIBIMPL__(( FUNCTION = nanosleep ))
+int nanosleep( const struct timespec *period, struct timespec *residual )
+{
+  if( residual != (void *)(0) )
+    residual->tv_sec = (__time64_t)(residual->tv_nsec = 0);
+  return __mingw_sleep((unsigned)(period->tv_sec), (period->tv_sec < 0LL)
+    ? (unsigned)(-1) : (unsigned)(period->tv_nsec));
+}
+#endif /* !__NO_INLINE__ */
+#endif /* _POSIX_C_SOURCE */
 #endif /* _TIME_H included in its own right */
 
 #if __need_wchar_decls && ! (defined _TIME_H && defined _WCHAR_H)
index 93cca4d..495f3af 100644 (file)
@@ -1,4 +1,3 @@
-#ifndef _UNISTD_H
 /*
  * unistd.h
  *
@@ -12,7 +11,7 @@
  *   Ramiro Polla <ramiro@lisha.ufsc.br>
  *   Gregory McGarry  <gregorymcgarry@users.sourceforge.net>
  *   Keith Marshall  <keithmarshall@users.sourceforge.net>
- * Copyright (C) 1997, 1999, 2002-2004, 2007-2009, 2014-2015,
+ * Copyright (C) 1997, 1999, 2002-2004, 2007-2009, 2014-2016,
  *   MinGW.org Project.
  *
  *
@@ -36,6 +35,7 @@
  * DEALINGS IN THE SOFTWARE.
  *
  */
+#ifndef _UNISTD_H
 #define _UNISTD_H  1
 #pragma GCC system_header
 
@@ -44,8 +44,8 @@
  */
 #include <_mingw.h>
 
-/* unistd.h maps (roughly) to io.h
- * Other headers included by unistd.h may be selectively processed;
+/* unistd.h maps (roughly) to Microsoft's <io.h>
+ * Other headers included by <unistd.h> may be selectively processed;
  * __UNISTD_H_SOURCED__ enables such selective processing.
  */
 #define __UNISTD_H_SOURCED__ 1
 #define SEEK_END   2
 
 #if _POSIX_C_SOURCE
-/*
- * POSIX process/thread suspension functions; all are supported by a
+/* POSIX process/thread suspension functions; all are supported by a
  * common MinGW API in libmingwex.a, providing for suspension periods
- * ranging from mean values of ~7.5 milliseconds, (see comments below),
- * extending up to a maximum of ~136 years.
+ * ranging from mean values of ~7.5 milliseconds, (see the comments in
+ * <time.h>), extending up to a maximum of ~136 years.
  *
  * Note that, whereas POSIX supports early wake-up of any suspended
  * process/thread, in response to a signal, this implementation makes
  * argument, this implementation always returns an indication as if
  * the sleeping period ran to completion.
  */
-_EXTERN_C __cdecl __MINGW_NOTHROW
-int __mingw_sleep( unsigned long, unsigned long );
-
-/* Structure timespec is mandated by POSIX, for specification of
- * intervals with the greatest precision supported by the OS kernel.
- * Although this allows for specification to nanosecond precision, do
- * not be deluded into any false expectation that such short intervals
- * can be realized on Windows; on Win9x derivatives, the metronome used
- * by the process scheduler has a period of ~55 milliseconds, while for
- * WinNT derivatives, the corresponding period is ~15 milliseconds; thus,
- * the shortest intervals which can be realistically timed will range
- * from 0..55 milliseconds on Win9x hosts, and from 0..15 ms on WinNT,
- * with period values normally distributed around means of ~27.5 ms
- * and ~7.5 ms, for the two system types respectively.
- */
-#define _FAKE_TIME_H_SOURCED 1
-#define __need_struct_timespec
-#include <parts/time.h>
-
 _BEGIN_C_DECLS
 
-/* The nanosleep() function provides the most general purpose API for
- * process/thread suspension; it provides for specification of periods
- * ranging from ~7.5 ms mean, (on WinNT derivatives; ~27.5 ms on Win9x),
- * extending up to ~136 years, (effectively eternity).
- */
 __cdecl __MINGW_NOTHROW
-int nanosleep( const struct timespec *, struct timespec * );
-
-#ifndef __NO_INLINE__
-__CRT_INLINE __LIBIMPL__(( FUNCTION = nanosleep ))
-int nanosleep( const struct timespec *period, struct timespec *residual )
-{
-  if( residual != (void *)(0) )
-    residual->tv_sec = (__time64_t)(residual->tv_nsec = 0);
-  return __mingw_sleep((unsigned)(period->tv_sec), (period->tv_sec < 0LL)
-    ? (unsigned)(-1) : (unsigned)(period->tv_nsec));
-}
-#endif
+int __mingw_sleep( unsigned long, unsigned long );
 
-/* The usleep() function, and its associated useconds_t type specifier
+/* The nanosleep() function provides the most general purpose API for
+ * process/thread suspension; it is declared in <time.h>, (where it is
+ * accompanied by an in-line implementation), rather than here, and it
+ * provides for specification of suspension periods in the range from
+ * ~7.5 ms mean, (on WinNT derivatives; ~27.5 ms on Win9x), extending
+ * up to ~136 years, (effectively eternity).
+ *
+ * The usleep() function, and its associated useconds_t type specifier
  * were made obsolete in POSIX.1-2008; declared here, only for backward
  * compatibility, its continued use is not recommended.  (It is limited
  * to specification of suspension periods ranging from ~7.5 ms mean up