mirror of
https://github.com/guezoloic/t3dsr.git
synced 2026-01-25 15:34:24 +00:00
feat: add sleep ms function
This commit is contained in:
24
src/sleepms.c
Normal file
24
src/sleepms.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "sleepms.h"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#elif _POSIX_C_SOURCE >= 199309L
|
||||||
|
#include <time.h> // for nanosleep
|
||||||
|
#else
|
||||||
|
#include <unistd.h> // for usleep
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void sleep_ms(int milliseconds){ // cross-platform sleep function
|
||||||
|
#ifdef WIN32
|
||||||
|
Sleep(milliseconds);
|
||||||
|
#elif _POSIX_C_SOURCE >= 199309L
|
||||||
|
struct timespec ts;
|
||||||
|
ts.tv_sec = milliseconds / 1000;
|
||||||
|
ts.tv_nsec = (milliseconds % 1000) * 1000000;
|
||||||
|
nanosleep(&ts, NULL);
|
||||||
|
#else
|
||||||
|
if (milliseconds >= 1000)
|
||||||
|
sleep(milliseconds / 1000);
|
||||||
|
usleep((milliseconds % 1000) * 1000);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
6
src/sleepms.h
Normal file
6
src/sleepms.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef SLEEPMS_H
|
||||||
|
#define SLEEPMS_H
|
||||||
|
|
||||||
|
void sleep_ms(int milliseconds);
|
||||||
|
|
||||||
|
#endif // SLEEPMS_H
|
||||||
Reference in New Issue
Block a user