• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright JS Foundation and other contributors, http://js.foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #if !defined (_XOPEN_SOURCE) || _XOPEN_SOURCE < 500
17 #undef _XOPEN_SOURCE
18 /* Required macro for sleep functions (nanosleep or usleep) */
19 #define _XOPEN_SOURCE 500
20 #endif
21 
22 #ifdef _WIN32
23 #include <windows.h>
24 #elif defined (HAVE_TIME_H)
25 #include <time.h>
26 #elif defined (HAVE_UNISTD_H)
27 #include <unistd.h>
28 #endif /* _WIN32 */
29 
30 #include "jerryscript-port.h"
31 #include "jerryscript-port-default.h"
32 
33 /**
34  * Default implementation of jerry_port_sleep. Uses 'nanosleep' or 'usleep' if
35  * available on the system, does nothing otherwise.
36  */
jerry_port_sleep(uint32_t sleep_time)37 void jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
38 {
39 #ifdef _WIN32
40   Sleep (sleep_time);
41 #elif defined (HAVE_TIME_H)
42   struct timespec sleep_timespec;
43   sleep_timespec.tv_sec = (time_t) sleep_time / 1000;
44   sleep_timespec.tv_nsec = ((long int) sleep_time % 1000) * 1000000L;
45 
46   nanosleep (&sleep_timespec, NULL);
47 #elif defined (HAVE_UNISTD_H)
48   usleep ((useconds_t) sleep_time * 1000);
49 #else
50   (void) sleep_time;
51 #endif /* HAVE_TIME_H */
52 } /* jerry_port_sleep */
53