Skip to content

Commit

Permalink
try this
Browse files Browse the repository at this point in the history
  • Loading branch information
azimafroozeh committed Sep 11, 2024
1 parent 54ef17c commit 7ffcbe9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
3 changes: 0 additions & 3 deletions include/fls/io/mmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
namespace fastlanes {
class Mmap {
public:
static std::byte* Open(bsz_t bsz, int& fd, const std::filesystem::path& path);
template <typename T>
static T* Open(bsz_t bsz, int& fd, const std::filesystem::path& path);
static std::byte* Resize(bsz_t bsz, int& fd);
template <typename T>
static T* Resize(bsz_t bsz, int& fd);
Expand Down
36 changes: 0 additions & 36 deletions src/io/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,6 @@
#include <unistd.h>

namespace fastlanes {
/*
*
* */
std::byte* Mmap::Open(bsz_t init_bsz, int& fd, const std::filesystem::path& path) {
/**/
#if defined(_WIN32)
// Use _open() on Windows
fd = open(path.c_str(), _O_RDWR | _O_CREAT, _S_IREAD | _S_IWRITE);
#else
// Use POSIX open() on Linux/macOS
fd = open(path.c_str(), O_RDWR | O_CREAT, 0777);
#endif

if (fd == -1) {
/**/
throw std::runtime_error(strerror(errno));
}

struct stat file_info {};
if (stat(path.c_str(), &file_info) == -1) { throw std::runtime_error("stat"); }

if (file_info.st_size == 0) {
if (ftruncate(fd, static_cast<off_t>(init_bsz)) == -1) { throw std::runtime_error("Error resizing the file"); }
if (stat(path.c_str(), &file_info) == -1) { throw std::runtime_error("stat"); }
}

auto* p = reinterpret_cast<std::byte*>(
mmap(nullptr, static_cast<size_t>(file_info.st_size), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
return p;
}

void Mmap::Close(void* p, bsz_t bsz, int& fd) {
/**/
Expand All @@ -60,12 +30,6 @@ T* Mmap::Resize(bsz_t bsz, int& fd) {
return reinterpret_cast<T*>(Resize(bsz, fd));
}

template <typename T>
T* Mmap::Open(bsz_t bsz, int& fd, const std::filesystem::path& path) {
return reinterpret_cast<T*>(Open(bsz, fd, path));
}

template int64_t* Mmap::Open<>(bsz_t bsz, int& fd, const std::filesystem::path& path);
template uint64_t* Mmap::Resize<>(bsz_t bsz, int& fd);

} // namespace fastlanes

0 comments on commit 7ffcbe9

Please sign in to comment.