Skip to content

Commit 1c6673c

Browse files
author
Carlos Une
committed
Cache get_os_type() return value using the save attribute
1 parent e18017d commit 1c6673c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/fpm_environment.f90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,24 @@ integer function get_os_type() result(r)
4040
character(len=32) :: val
4141
integer :: length, rc
4242
logical :: file_exists
43+
logical, save :: first_run = .true.
44+
integer, save :: ret = OS_UNKNOWN
45+
!omp threadprivate(ret, first_run)
4346

47+
if (.not. first_run) then
48+
r = ret
49+
return
50+
end if
51+
52+
first_run = .false.
4453
r = OS_UNKNOWN
4554

4655
! Check environment variable `OS`.
4756
call get_environment_variable('OS', val, length, rc)
4857

4958
if (rc == 0 .and. length > 0 .and. index(val, 'Windows_NT') > 0) then
5059
r = OS_WINDOWS
60+
ret = r
5161
return
5262
end if
5363

@@ -58,42 +68,49 @@ integer function get_os_type() result(r)
5868
! Linux
5969
if (index(val, 'linux') > 0) then
6070
r = OS_LINUX
71+
ret = r
6172
return
6273
end if
6374

6475
! macOS
6576
if (index(val, 'darwin') > 0) then
6677
r = OS_MACOS
78+
ret = r
6779
return
6880
end if
6981

7082
! Windows, MSYS, MinGW, Git Bash
7183
if (index(val, 'win') > 0 .or. index(val, 'msys') > 0) then
7284
r = OS_WINDOWS
85+
ret = r
7386
return
7487
end if
7588

7689
! Cygwin
7790
if (index(val, 'cygwin') > 0) then
7891
r = OS_CYGWIN
92+
ret = r
7993
return
8094
end if
8195

8296
! Solaris, OpenIndiana, ...
8397
if (index(val, 'SunOS') > 0 .or. index(val, 'solaris') > 0) then
8498
r = OS_SOLARIS
99+
ret = r
85100
return
86101
end if
87102

88103
! FreeBSD
89104
if (index(val, 'FreeBSD') > 0 .or. index(val, 'freebsd') > 0) then
90105
r = OS_FREEBSD
106+
ret = r
91107
return
92108
end if
93109

94110
! OpenBSD
95111
if (index(val, 'OpenBSD') > 0 .or. index(val, 'openbsd') > 0) then
96112
r = OS_OPENBSD
113+
ret = r
97114
return
98115
end if
99116
end if
@@ -103,6 +120,7 @@ integer function get_os_type() result(r)
103120

104121
if (file_exists) then
105122
r = OS_LINUX
123+
ret = r
106124
return
107125
end if
108126

@@ -111,6 +129,7 @@ integer function get_os_type() result(r)
111129

112130
if (file_exists) then
113131
r = OS_MACOS
132+
ret = r
114133
return
115134
end if
116135

@@ -119,6 +138,7 @@ integer function get_os_type() result(r)
119138

120139
if (file_exists) then
121140
r = OS_FREEBSD
141+
ret = r
122142
return
123143
end if
124144
end function get_os_type

0 commit comments

Comments
 (0)