Repairing Windows build.

This commit is contained in:
jmsgrogan 2022-08-17 09:04:52 +01:00
parent 877d96462d
commit a95439d419
12 changed files with 144 additions and 55 deletions

View file

@ -2,11 +2,13 @@
#include "RandomUtils.h"
#ifdef __linux__
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
void SharedMemory::allocate(const std::string& namePrefix, std::size_t size)
{
@ -17,6 +19,7 @@ void SharedMemory::allocate(const std::string& namePrefix, std::size_t size)
return;
}
#ifdef __linux__
int ret{-1};
do {
ret = ftruncate(mFileDescriptor, size);
@ -27,6 +30,7 @@ void SharedMemory::allocate(const std::string& namePrefix, std::size_t size)
close(mFileDescriptor);
mIsValid = false;
}
#endif
}
int SharedMemory::getFileDescriptor() const
@ -41,6 +45,7 @@ bool SharedMemory::isValid() const
void SharedMemory::createFile(const std::string& namePrefix)
{
#ifdef __linux__
unsigned retries = 100;
do {
const auto name = getRandomName(namePrefix);
@ -55,6 +60,7 @@ void SharedMemory::createFile(const std::string& namePrefix)
break;
}
} while (retries > 0 && errno == EEXIST);
#endif
}
std::string SharedMemory::getRandomName(const std::string& namePrefix) const