mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
osx compile files
This commit is contained in:
parent
cd4d63dd9c
commit
528d778d9a
@ -1,6 +1,8 @@
|
||||
#include "buffer.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include "platform.h"
|
||||
#include "../utils.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
#include "platform.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include "../utils.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
@ -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<PlatformScopedMutexLock> CreatePlatformScopedMutexLock(
|
||||
}
|
||||
|
||||
std::unique_ptr<PlatformSharedMemory> CreatePlatformSharedMemory(
|
||||
const std::string& name) {
|
||||
const std::string& name, size_t size) {
|
||||
std::string name2 = "/" + name;
|
||||
return MakeUnique<PlatformSharedMemoryLinux>(name2);
|
||||
return MakeUnique<PlatformSharedMemoryLinux>(name2, size);
|
||||
}
|
||||
#endif
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
// 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user