11module stdlib_experimental_system
2- use , intrinsic :: iso_c_binding, only : c_int
2+ use , intrinsic :: iso_c_binding, only : c_int, c_long
33implicit none
44private
55
66interface
77#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
1113end subroutine system_sleep
1214#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
1418import 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
1721#endif
1822end interface
1923
@@ -23,15 +27,18 @@ end subroutine system_sleep
2327
2428subroutine sleep (millisec )
2529integer , intent (in ) :: millisec
26- integer (c_int) :: t
30+ integer (c_int) :: ierr
2731
2832#ifdef _WIN32
29- t = millisec
33+ ! ! PGI Windows, Ifort Windows, ....
34+ call system_sleep(int (millisec, c_long))
3035#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'
3239#endif
3340
34- call system_sleep( int (t, c_int))
41+
3542end subroutine sleep
3643
3744end module stdlib_experimental_system
0 commit comments