1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (retro_timers.h).
5 * ---------------------------------------------------------------------------------------
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __LIBRETRO_COMMON_TIMERS_H
24 #define __LIBRETRO_COMMON_TIMERS_H
29 #include <time/time.h>
30 #elif !defined(__PSL1GHT__) && defined(__PS3__)
31 #include <sys/timer.h>
32 #elif defined(GEKKO) || defined(__PSL1GHT__) || defined(__QNX__)
35 #include <wiiu/os/thread.h>
37 #include <pspthreadman.h>
39 #include <psp2/kernel/threadmgr.h>
46 #if defined(_WIN32) && !defined(_XBOX)
47 #define WIN32_LEAN_AND_MEAN
49 #elif defined(_WIN32) && defined(_XBOX)
56 #include <compat/msvc.h>
58 #include <retro_inline.h>
61 #define timespec timeval
62 #define tv_nsec tv_usec
65 extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
67 static int nanosleepDOS(const struct timespec *rqtp, struct timespec *rmtp)
69 usleep(1000000L * rqtp->tv_sec + rqtp->tv_nsec / 1000);
72 rmtp->tv_sec = rmtp->tv_nsec=0;
77 #define nanosleep nanosleepDOS
82 * @msec : amount in milliseconds to sleep
84 * Sleeps for a specified amount of milliseconds (@msec).
87 #define retro_sleep(msec) (sceKernelDelayThread(1000 * (msec)))
89 #define retro_sleep(msec) (svcSleepThread(1000000 * (s64)(msec)))
90 #elif defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
91 #define retro_sleep(msec) (SleepEx((msec), FALSE))
93 #define retro_sleep(msec) (Sleep((msec)))
95 #define retro_sleep(msec) (udelay(1000 * (msec)))
96 #elif !defined(__PSL1GHT__) && defined(__PS3__)
97 #define retro_sleep(msec) (sys_timer_usleep(1000 * (msec)))
98 #elif defined(GEKKO) || defined(__PSL1GHT__) || defined(__QNX__)
99 #define retro_sleep(msec) (usleep(1000 * (msec)))
101 #define retro_sleep(msec) (OSSleepTicks(ms_to_ticks((msec))))
103 static INLINE void retro_sleep(unsigned msec)
106 tv.tv_sec = msec / 1000;
107 tv.tv_nsec = (msec % 1000) * 1000000;
108 nanosleep(&tv, NULL);