Added silc_usleep.
authorPekka Riikonen <priikone@silcnet.org>
Sun, 11 Feb 2007 18:06:01 +0000 (18:06 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 11 Feb 2007 18:06:01 +0000 (18:06 +0000)
lib/silcutil/silctime.h

index a57830f6444a90006491b6866f5e30fa9f1b6097..17912fe3b365aed4c257458ebb09c129400e4497 100644 (file)
@@ -254,4 +254,47 @@ SilcBool silc_compare_timeval(struct timeval *smaller,
  ***/
 int silc_gettimeofday(struct timeval *p);
 
+/****f* silcutil/SilcTimeAPI/silc_usleep
+ *
+ * SYNOPSIS
+ *
+ *    void silc_usleep(long microseconds);
+ *
+ * DESCRIPTION
+ *
+ *    Delays the execution of process/thread for the specified amount of
+ *    time, which is in microseconds.
+ *
+ * NOTES
+ *
+ *    The delay is only approximate and on some platforms the resolution is
+ *    in fact milliseconds.
+ *
+ ***/
+static inline
+void silc_usleep(long microseconds)
+{
+#ifdef SILC_UNIX
+#ifdef HAVE_NANOSLEEP
+  struct timespec tv;
+  tv.tv_sec = 0;
+  tv.tv_nsec = microseconds * 1000;
+#endif /* HAVE_NANOSLEEP */
+#endif /* SILC_UNIX */
+
+#ifdef SILC_UNIX
+#ifdef HAVE_NANOSLEEP
+  nanosleep(&tv, NULL);
+#else
+  usleep(microseconds);
+#endif /* HAVE_NANOSLEEP */
+#endif /* SILC_UNIX */
+#ifdef SILC_WIN32
+  Sleep(microseconds / 1000);
+#endif /* SILC_WIN32 */
+#ifdef SILC_SYMBIAN
+  User::After(microseconds / 1000);
+#endif /* SILC_SYMBIAN */
+}
+
 #endif /* SILCTIME_H */