[Groonga-commit] groonga/groonga [master] Define grn_sleep/nanosleep() for replacing sleep/usleep().

Back to archive index

null+****@clear***** null+****@clear*****
2012年 5月 8日 (火) 12:55:56 JST


Susumu Yata	2012-05-08 12:55:56 +0900 (Tue, 08 May 2012)

  New Revision: 953a2fcd776dd79005769dc3ab8227ad6939436e

  Log:
    Define grn_sleep/nanosleep() for replacing sleep/usleep().

  Modified files:
    lib/ctx.c
    lib/groonga_in.h

  Modified: lib/ctx.c (+19 -0)
===================================================================
--- lib/ctx.c    2012-05-07 21:20:31 +0900 (7b384d8)
+++ lib/ctx.c    2012-05-08 12:55:56 +0900 (79d33d0)
@@ -56,6 +56,25 @@ uint32_t grn_gtick;
 int grn_uyield_count = 0;
 #endif
 
+void grn_sleep(uint32_t seconds) {
+#ifdef WIN32
+  Sleep(seconds * 1000);
+#else  // WIN32
+  sleep(seconds);
+#endif  // WIN32
+}
+
+void grn_nanosleep(uint64_t nanoseconds) {
+#ifdef WIN32
+  Sleep((DWORD)(nanoseconds / 1000000));
+#else  // WIN32
+  struct timespec interval;
+  interval.tv_sec = (time_t)(nanoseconds / 1000000000);
+  interval.tv_nsec = (long)(nanoseconds % 1000000000);
+  nanosleep(&interval, NULL);
+#endif  // WIN32
+}
+
 /* fixme by 2038 */
 
 grn_rc

  Modified: lib/groonga_in.h (+3 -0)
===================================================================
--- lib/groonga_in.h    2012-05-07 21:20:31 +0900 (521aa20)
+++ lib/groonga_in.h    2012-05-08 12:55:56 +0900 (cb907a4)
@@ -150,6 +150,9 @@
 #define pid_t int
 #endif
 
+GRN_API void grn_sleep(uint32_t seconds);
+GRN_API void grn_nanosleep(uint64_t nanoseconds);
+
 #undef MSG_WAITALL
 #define MSG_WAITALL 0 /* before Vista, not supported... */
 #define SHUT_RDWR SD_BOTH




Groonga-commit メーリングリストの案内
Back to archive index