X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilctime.h;h=17912fe3b365aed4c257458ebb09c129400e4497;hb=0b7b11022f365d8aa41c07f3b62197ed5c873d4e;hp=a57830f6444a90006491b6866f5e30fa9f1b6097;hpb=d6c19226261ef77f97358bdae5787f4950c378db;p=silc.git 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 */