From: Pekka Riikonen Date: Sun, 11 Feb 2007 18:06:01 +0000 (+0000) Subject: Added silc_usleep. X-Git-Tag: silc.client.1.1.beta1~28 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=0b7b11022f365d8aa41c07f3b62197ed5c873d4e Added silc_usleep. --- diff --git a/lib/silcutil/silctime.h b/lib/silcutil/silctime.h index a57830f6..17912fe3 100644 --- a/lib/silcutil/silctime.h +++ b/lib/silcutil/silctime.h @@ -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 */