Skip to content

Commit 688cb98

Browse files
committed
use more correct data type to C
1 parent c513abf commit 688cb98

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/stdlib_experimental_system.F90

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
module stdlib_experimental_system
2-
use, intrinsic :: iso_c_binding, only : c_int
2+
use, intrinsic :: iso_c_binding, only : c_int, c_long
33
implicit none
44
private
55

66
interface
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
1113
end 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
1418
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
1721
#endif
1822
end interface
1923

@@ -23,15 +27,18 @@ end subroutine system_sleep
2327

2428
subroutine sleep(millisec)
2529
integer, 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+
3542
end subroutine sleep
3643

3744
end module stdlib_experimental_system

0 commit comments

Comments
 (0)