Skip to content

Commit

Permalink
Import millisleep.h
Browse files Browse the repository at this point in the history
  • Loading branch information
gperciva committed Jan 1, 2024
1 parent 1207756 commit f848082
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions util/millisleep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef MILLISLEEP_H_
#define MILLISLEEP_H_

#include <stddef.h>

#include <time.h>

/**
* millisleep(msec):
* Wait up to ${msec} milliseconds. This duration can be interrupted by
* signals.
*/
static inline void
millisleep(size_t msec)
{
struct timespec ts;

ts.tv_sec = msec / 1000;
ts.tv_nsec = (msec % 1000) * 1000000;
nanosleep(&ts, NULL);
}

#endif /* !MILLISLEEP_H_ */

0 comments on commit f848082

Please sign in to comment.