16#if __has_include(<sys/file.h>) 
   25#if __has_include(<fcntl.h>) 
   29#if __has_include(<sys/mount.h>) 
   38  static std::once_flag Flag;
 
   40  std::call_once(Flag, [&Err] {
 
   42    constexpr const char *EnvVar = 
"LLVM_CAS_MAX_MAPPING_SIZE";
 
   50                              "invalid value for %s: expected integer", EnvVar);
 
   55    return std::move(Err);
 
 
   71    return std::error_code();
 
   72  return std::error_code(errno, std::generic_category());
 
 
   83  if (flock(FD, LOCK_UN) == 0)
 
   84    return std::error_code();
 
   85  return std::error_code(errno, std::generic_category());
 
 
   98  auto Start = std::chrono::steady_clock::now();
 
  103      return std::error_code();
 
  105    if (
Error == EWOULDBLOCK) {
 
  107      std::this_thread::sleep_for(std::chrono::milliseconds(1));
 
  110    return std::error_code(
Error, std::generic_category());
 
  111  } 
while (std::chrono::steady_clock::now() < End);
 
 
  124    if (EC == std::errc::not_supported)
 
  127#if defined(HAVE_POSIX_FALLOCATE) 
  128    if (EC == std::errc::invalid_argument && CurrentSize < NewSize && // len > 0
 
  129        NewSize < std::numeric_limits<off_t>::max()) 
 
  136                             "failed to allocate to CAS file: " + EC.message());
 
  138#if defined(HAVE_POSIX_FALLOCATE) 
  140  if (
int Err = posix_fallocate(FD, CurrentSize, NewSize - CurrentSize))
 
  141    return CreateError(std::error_code(Err, std::generic_category()));
 
  143#elif defined(__APPLE__) 
  145  FAlloc.fst_flags = F_ALLOCATEALL;
 
  146#if defined(F_ALLOCATEPERSIST) &&                                              \ 
  147    defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                  \ 
  148    __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 130000 
  150  FAlloc.fst_flags |= F_ALLOCATEPERSIST;
 
  152  FAlloc.fst_posmode = F_PEOFPOSMODE;
 
  153  FAlloc.fst_offset = 0;
 
  154  FAlloc.fst_length = NewSize - CurrentSize;
 
  155  FAlloc.fst_bytesalloc = 0;
 
  156  if (fcntl(FD, F_PREALLOCATE, &FAlloc))
 
  158  assert(CurrentSize + FAlloc.fst_bytesalloc >= NewSize);
 
  159  return CurrentSize + FAlloc.fst_bytesalloc;
 
 
  168#if defined(__APPLE__) && __has_include(<sys/mount.h>) 
  171  StringRef Path = 
P.toNullTerminatedStringRef(PathStorage);
 
  172  struct statfs StatFS;
 
  173  if (statfs(Path.data(), &StatFS) != 0)
 
  176  if (strcmp(StatFS.f_fstypename, 
"tmpfs") == 0)
 
 
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static uint64_t OnDiskCASMaxMappingSize
Provides a library for accessing information about this process and other processes on the operating ...
Helper for Errors used as out-parameters.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
static LLVM_ABI std::optional< std::string > GetEnv(StringRef name)
void setMaxMappingSize(uint64_t Size)
Set MaxMappingSize for ondisk CAS.
Expected< std::optional< uint64_t > > getOverriddenMaxMappingSize()
Retrieves an overridden maximum mapping size for CAS files, if any, speicified by LLVM_CAS_MAX_MAPPIN...
std::error_code lockFileThreadSafe(int FD, llvm::sys::fs::LockKind Kind)
Thread-safe alternative to sys::fs::lockFile.
std::error_code unlockFileThreadSafe(int FD)
Thread-safe alternative to sys::fs::unlockFile.
std::error_code tryLockFileThreadSafe(int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0), llvm::sys::fs::LockKind Kind=llvm::sys::fs::LockKind::Exclusive)
Thread-safe alternative to sys::fs::tryLockFile.
Expected< size_t > preallocateFileTail(int FD, size_t CurrentSize, size_t NewSize)
Allocate space for the file FD on disk, if the filesystem supports it.
bool useSmallMappingSize(const Twine &Path)
Whether to use a small file mapping for ondisk databases created in Path.
LLVM_ABI std::error_code lockFile(int FD, LockKind Kind=LockKind::Exclusive)
Lock the file.
LLVM_ABI std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0), LockKind Kind=LockKind::Exclusive)
Try to locks the file during the specified time.
LockKind
An enumeration for the lock kind.
LLVM_ABI std::error_code unlockFile(int FD)
Unlock the file.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code make_error_code(BitcodeError E)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
@ Timeout
Reached timeout while waiting for the owner to release the lock.
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.