Skip to content

Commit b66b324

Browse files
committed
[Support] Use posix_madvise() if available
This is a followup to D119695 using the suggestion by joerg. Rather than manually declaring madvise() on __sun__, this uses posix_madvise() if available, which does get declared properly on Illumos. Differential Revision: https://reviews.llvm.org/D119856
1 parent e30efa0 commit b66b324

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

llvm/lib/Support/Unix/Path.inc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ typedef uint_t uint;
118118
#define STATVFS_F_FLAG(vfs) (vfs).f_flags
119119
#endif
120120

121-
#if defined(__sun__) && defined(__svr4__)
122-
// The madvise() declaration on Illumos cannot be made visible if _XOPEN_SOURCE
123-
// is defined. This declaration is also compatible with Solaris 11.4.
124-
extern "C" int madvise(void *, size_t, int);
125-
#endif
126-
127121
using namespace llvm;
128122

129123
namespace llvm {
@@ -880,12 +874,14 @@ void mapped_file_region::unmapImpl() {
880874

881875
void mapped_file_region::dontNeedImpl() {
882876
assert(Mode == mapped_file_region::readonly);
877+
if (!Mapping)
878+
return;
883879
#if defined(__MVS__) || defined(_AIX)
884880
// If we don't have madvise, or it isn't beneficial, treat this as a no-op.
885-
return;
881+
#elif defined(POSIX_MADV_DONTNEED)
882+
::posix_madvise(Mapping, Size, POSIX_MADV_DONTNEED);
886883
#else
887-
if (Mapping)
888-
::madvise(Mapping, Size, MADV_DONTNEED);
884+
::madvise(Mapping, Size, MADV_DONTNEED);
889885
#endif
890886
}
891887

0 commit comments

Comments
 (0)