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 7ffcbe9 commit 16d66ab
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 34 deletions.
4 changes: 0 additions & 4 deletions include/fls/io/mmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
namespace fastlanes {
class Mmap {
public:
static std::byte* Resize(bsz_t bsz, int& fd);
template <typename T>
static T* Resize(bsz_t bsz, int& fd);
static void Close(void* p, bsz_t bsz, int& fd);
};
} // namespace fastlanes

Expand Down
31 changes: 1 addition & 30 deletions src/io/mmap.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
#include "fls/io/mmap.hpp"
#include <cstring>
#include <sys/fcntl.h>
#if defined(_WIN32)
#include <windows.h> // For Windows memory-mapping
#define open _open
#define close _close
#else
#include <sys/mman.h> // For POSIX memory-mapping
#endif
#include <sys/stat.h>
#include <unistd.h>

namespace fastlanes {

void Mmap::Close(void* p, bsz_t bsz, int& fd) {
/**/
if (munmap(p, bsz) == -1) { throw std::runtime_error(strerror(errno)); }
close(fd);
}

std::byte* Mmap::Resize(bsz_t bsz, int& fd) {
if (ftruncate(fd, static_cast<off_t>(bsz)) == -1) { throw std::runtime_error("Error resizing the file"); }
auto* p = reinterpret_cast<std::byte*>(mmap(nullptr, bsz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
return p;
}

template <typename T>
T* Mmap::Resize(bsz_t bsz, int& fd) {
return reinterpret_cast<T*>(Resize(bsz, fd));
}

template uint64_t* Mmap::Resize<>(bsz_t bsz, int& fd);
namespace fastlanes {

} // namespace fastlanes

0 comments on commit 16d66ab

Please sign in to comment.