Skip to contentSkip to conversation

implement grub_millisleep in util/misc.c for grub-emu

PATCH In review Felix Zielcke 3 participants 5 messages Feb 15, 2009 – Mar 4, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 implement grub_millisleep in util/misc.c for grub-emu

Here's a small patch which implements grub_millisleep () using nanosleep () in util/misc.c.
I hope it's correct.

Signature · 1 line
Felix Zielcke

2009-02-15 Felix Zielcke <[email protected]>

* util/misc.c: Define _POSIX_C_SOURCE 199309L. Include <time.h>.
(grub_millisleep): New function.

misc.c +13 -0
Index: util/misc.c
===================================================================
@@ -27,6 +27,9 @@
 #include <sys/time.h>
 #include <unistd.h>
 
+#define _POSIX_C_SOURCE 199309L
+#include <time.h>
+
 #include <grub/kernel.h>
 #include <grub/misc.h>
 #include <grub/cache.h>
@@ -310,6 +313,16 @@ grub_get_time_ms (void)
   return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
 }
 
+void
+grub_millisleep (grub_uint32_t ms)
+{
+  struct timespec ts;
+
+  ts.tv_sec = ms / 1000;
+  ts.tv_nsec = (ms % 1000) * 1000000;
+  nanosleep (&ts, NULL);
+}
+
 void 
 grub_arch_sync_caches (void *address __attribute__ ((unused)),
 		       grub_size_t len __attribute__ ((unused)))
#1 lore raw

misc.c line 31

Quoted 8 lines · Felix Zielcke
misc.c +2 -0
@@ -27,6 +27,9 @@
 #include <sys/time.h>
 #include <unistd.h>
 
+#define _POSIX_C_SOURCE 199309L
+#include <time.h>

I'm not sure this is garanteed to work unless it's defined before any header is included. Did it compile without warnings?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#2 lore raw
Quoted 8 lines · Robert Millan
Quoted 6 lines · Felix Zielcke
misc.c +0 -0
@@ -27,6 +27,9 @@
 #include <sys/time.h>
 #include <unistd.h>
 
Quoted 8 lines

misc.c

Quoted 3 lines
misc.c +2 -0
+#define _POSIX_C_SOURCE 199309L
+#include <time.h>
 

I'm not sure this is garanteed to work unless it's defined before any header is included. Did it compile without warnings?

At least with glibc headers, the #define from the patch has no effect, because at least unistd.h has already included features.h which handles these settings. There is no warning, because none of the headers define _POSIX_C_SOURCE.

From features.h:
/* If none of the ANSI/POSIX macros are defined, use POSIX.1 and POSIX.2
(and IEEE Std 1003.1b-1993 unless _XOPEN_SOURCE is defined). */
#if (...!defined (_POSIX_C_SOURCE)...)

# define _POSIX_SOURCE  1
# if defined _XOPEN_SOURCE ...
#  ...
# else
#  define _POSIX_C_SOURCE       200112L
# endif
#endif

I would suggest to remove the #define and commit the patch.

BTW: compiles fine on Cygwin, with or without the #define.

Signature · 1 line
Christian Franke
#3 lore raw
Quoted 1 line · Christian Franke

There is no warning, because none of the headers define _POSIX_C_SOURCE.

This should read: There is a warning, because features.h defines _POSIX_C_SOURCE :-)

Signature · 1 line
Christian Franke
#4 lore raw
In reply to Christian Franke

Am Samstag, den 28.02.2009, 21:51 +0100 schrieb Christian Franke:

Quoted 2 lines

I would suggest to remove the #define and commit the patch.

Ok commited.

Signature · 1 line
Felix Zielcke