From 528d778d9ac2963d4d0ae814278ce1d19d34a190 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Tue, 21 Mar 2017 10:06:22 -0700 Subject: [PATCH] osx compile files --- src/buffer.cc | 4 +++- src/platform_linux.cc | 27 +++++++++++++++------------ src/resizable_buffer.h | 4 +++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 5d777dd1..98b01700 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -1,6 +1,8 @@ #include "buffer.h" +#include #include +#include #include "platform.h" #include "../utils.h" @@ -116,4 +118,4 @@ TEST_CASE("lock") { } } -TEST_SUITE_END(); \ No newline at end of file +TEST_SUITE_END(); diff --git a/src/platform_linux.cc b/src/platform_linux.cc index 7439c928..8b556c08 100644 --- a/src/platform_linux.cc +++ b/src/platform_linux.cc @@ -1,7 +1,7 @@ #if defined(__linux__) || defined(__APPLE__) #include "platform.h" -#include "utils.h" +#include "../utils.h" #include #include @@ -64,17 +64,19 @@ int checked(int result, const char* expr) { struct PlatformSharedMemoryLinux : public PlatformSharedMemory { std::string name_; + size_t size_; int fd_; - PlatformSharedMemoryLinux(const std::string& name) : name_(name) { - std::cerr << "PlatformSharedMemoryLinux name=" << name << std::endl; + PlatformSharedMemoryLinux(const std::string& name, size_t size) + : name_(name), size_(size) { + std::cerr << "PlatformSharedMemoryLinux name=" << name << ", size=" << size << std::endl; // Try to create shared memory but only if it does not already exist. Since // we created the memory, we need to initialize it. fd_ = shm_open(name_.c_str(), O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); if (fd_ >= 0) { std::cerr << "Calling ftruncate fd_=" << fd_ << std::endl; - CHECKED(ftruncate(fd_, shmem_size)); + CHECKED(ftruncate(fd_, size)); } // Otherwise, we just open existing shared memory. We don't need to @@ -86,19 +88,20 @@ struct PlatformSharedMemoryLinux : public PlatformSharedMemory { } // Map the shared memory to an address. - shared = - CHECKED(mmap(nullptr /*kernel assigned starting address*/, shmem_size, + data = + CHECKED(mmap(nullptr /*kernel assigned starting address*/, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0 /*offset*/)); + capacity = size; std::cout << "Open shared memory name=" << name << ", fd=" << fd_ - << ", shared=" << shared << std::endl; + << ", shared=" << data << ", capacity=" << capacity << std::endl; } ~PlatformSharedMemoryLinux() override { - CHECKED(munmap(shared, shmem_size)); + CHECKED(munmap(data, size_)); CHECKED(shm_unlink(name_.c_str())); - shared = nullptr; + data = nullptr; } }; @@ -116,8 +119,8 @@ std::unique_ptr CreatePlatformScopedMutexLock( } std::unique_ptr CreatePlatformSharedMemory( - const std::string& name) { + const std::string& name, size_t size) { std::string name2 = "/" + name; - return MakeUnique(name2); + return MakeUnique(name2, size); } -#endif \ No newline at end of file +#endif diff --git a/src/resizable_buffer.h b/src/resizable_buffer.h index f4aa40b0..23abde1d 100644 --- a/src/resizable_buffer.h +++ b/src/resizable_buffer.h @@ -1,5 +1,7 @@ #pragma once +#include + // Points to a generic block of memory that can be resized. This class owns // and has the only pointer to the underlying memory buffer. struct ResizableBuffer { @@ -18,4 +20,4 @@ struct ResizableBuffer { private: size_t capacity_; -}; \ No newline at end of file +};