Coverage Report

Created: 2023-09-12 09:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Host/posix/LockFilePosix.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- LockFilePosix.cpp -------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/Host/posix/LockFilePosix.h"
10
11
#include "llvm/Support/Errno.h"
12
13
#include <fcntl.h>
14
#include <unistd.h>
15
16
using namespace lldb;
17
using namespace lldb_private;
18
19
static Status fileLock(int fd, int cmd, int lock_type, const uint64_t start,
20
36
                       const uint64_t len) {
21
36
  struct flock fl;
22
23
36
  fl.l_type = lock_type;
24
36
  fl.l_whence = SEEK_SET;
25
36
  fl.l_start = start;
26
36
  fl.l_len = len;
27
36
  fl.l_pid = ::getpid();
28
29
36
  Status error;
30
36
  if (llvm::sys::RetryAfterSignal(-1, ::fcntl, fd, cmd, &fl) == -1)
31
0
    error.SetErrorToErrno();
32
33
36
  return error;
34
36
}
35
36
18
LockFilePosix::LockFilePosix(int fd) : LockFileBase(fd) {}
37
38
18
LockFilePosix::~LockFilePosix() { Unlock(); }
39
40
18
Status LockFilePosix::DoWriteLock(const uint64_t start, const uint64_t len) {
41
18
  return fileLock(m_fd, F_SETLKW, F_WRLCK, start, len);
42
18
}
43
44
0
Status LockFilePosix::DoTryWriteLock(const uint64_t start, const uint64_t len) {
45
0
  return fileLock(m_fd, F_SETLK, F_WRLCK, start, len);
46
0
}
47
48
0
Status LockFilePosix::DoReadLock(const uint64_t start, const uint64_t len) {
49
0
  return fileLock(m_fd, F_SETLKW, F_RDLCK, start, len);
50
0
}
51
52
0
Status LockFilePosix::DoTryReadLock(const uint64_t start, const uint64_t len) {
53
0
  return fileLock(m_fd, F_SETLK, F_RDLCK, start, len);
54
0
}
55
56
18
Status LockFilePosix::DoUnlock() {
57
18
  return fileLock(m_fd, F_SETLK, F_UNLCK, m_start, m_len);
58
18
}