1
1
module stdlib_experimental_system
2
- use , intrinsic :: iso_c_binding, only : c_int
2
+ use , intrinsic :: iso_c_binding, only : c_int, c_long
3
3
implicit none
4
4
private
5
5
6
6
interface
7
7
#ifdef _WIN32
8
- subroutine system_sleep (ms ) bind (C, name= ' Sleep' )
9
- import c_int
10
- integer (c_int), value, intent (in ) :: ms
8
+ subroutine system_sleep (dwMilliseconds ) bind (C, name= ' Sleep' )
9
+ ! ! void Sleep(DWORD dwMilliseconds)
10
+ ! ! https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleep
11
+ import c_long
12
+ integer (c_long), value, intent (in ) :: dwMilliseconds
11
13
end subroutine system_sleep
12
14
#else
13
- subroutine system_sleep (us ) bind (C, name= ' usleep' )
15
+ integer (c_int) function system_sleep(usec) bind (C, name= ' usleep' )
16
+ ! ! int usleep(useconds_t usec);
17
+ ! ! https://linux.die.net/man/3/usleep
14
18
import c_int
15
- integer (c_int), value, intent (in ) :: us
16
- end subroutine system_sleep
19
+ integer (c_int), value, intent (in ) :: usec
20
+ end function system_sleep
17
21
#endif
18
22
end interface
19
23
@@ -23,15 +27,18 @@ end subroutine system_sleep
23
27
24
28
subroutine sleep (millisec )
25
29
integer , intent (in ) :: millisec
26
- integer (c_int) :: t
30
+ integer (c_int) :: ierr
27
31
28
32
#ifdef _WIN32
29
- t = millisec
33
+ ! ! PGI Windows, Ifort Windows, ....
34
+ call system_sleep(int (millisec, c_long))
30
35
#else
31
- t = millisec * 1000
36
+ ! ! Linux, Unix, MacOS, MSYS2, ...
37
+ ierr = system_sleep(int (millisec * 1000 , c_int))
38
+ if (ierr/= 0 ) error stop ' problem with usleep() system call'
32
39
#endif
33
40
34
- call system_sleep( int (t, c_int))
41
+
35
42
end subroutine sleep
36
43
37
44
end module stdlib_experimental_system
0 commit comments