diff options
author | Xinliang David Li <davidxl@google.com> | 2016-06-06 18:31:29 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-06-06 18:31:29 +0000 |
commit | 3f4698f10f58b1ba944a14100ec46314f26cbd81 (patch) | |
tree | cca2b8e996fa7ae0ea982e50ef32e157574accad /lib/profile/InstrProfilingUtil.c | |
parent | 4af8674a2233f62cb385d0e47ddb1fd7d6134141 (diff) |
[profile] code cleanup /NFC
Address review feedback for better
readability.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271922 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingUtil.c')
-rw-r--r-- | lib/profile/InstrProfilingUtil.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/profile/InstrProfilingUtil.c b/lib/profile/InstrProfilingUtil.c index 24e302d4a..4c3623712 100644 --- a/lib/profile/InstrProfilingUtil.c +++ b/lib/profile/InstrProfilingUtil.c @@ -90,35 +90,43 @@ FILE *lprofOpenFileEx(const char *ProfileName) { s_flock.l_type = F_WRLCK; fd = open(ProfileName, O_RDWR | O_CREAT, 0666); if (fd < 0) - return 0; - - while (fcntl(fd, F_SETLKW, &s_flock) && errno == EINTR) - continue; + return NULL; + + while (fcntl(fd, F_SETLKW, &s_flock) == -1) { + if (errno != EINTR) { + if (errno == ENOLCK) { + PROF_WARN("Data may be corrupted during profile merging : %s\n", + "Fail to obtain file lock due to system limit."); + } + break; + } + } f = fdopen(fd, "r+b"); #elif defined(_WIN32) HANDLE h = CreateFile(ProfileName, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (h == INVALID_HANDLE_VALUE) - return 0; + return NULL; fd = _open_osfhandle((intptr_t)h, 0); if (fd == -1) { CloseHandle(h); - return 0; + return NULL; } f = _fdopen(fd, "r+b"); if (f == 0) { CloseHandle(h); - return 0; + return NULL; } #else /* Worst case no locking applied. */ - PROF_WARN("Concurrent file access is not supported : %s\n", "lack file locking"); + PROF_WARN("Concurrent file access is not supported : %s\n", + "lack file locking"); fd = open(ProfileName, O_RDWR | O_CREAT, 0666); if (fd < 0) - return 0; + return NULL; f = fdopen(fd, "r+b"); #endif |