build: portability groundwork toward a Windows/MSVC viewer
- CMakeLists.txt: fetch libzmq at the top level (zeromq/libzmq v4.3.5) before slsDetectorPackage, so this project controls the ZeroMQ version instead of sls's bundled archive. sls reuses it via its if(NOT libzmq_POPULATED) guard, so a single libzmq-static target is built (no duplicate-target/double-symbol clash). Verified the full Linux build still links (JFJochZMQ -> JFJochReceiver -> jfjoch_process). - common/NetworkAddressConvert.cpp: guard the network includes for _WIN32 (winsock2/ws2tcpip vs arpa/inet). - common/ImageBuffer.cpp: use std::malloc/std::free for the non-NUMA path instead of an anonymous mmap (the mapping had no huge-page/mbind flags, so it was equivalent) - portable and removes the POSIX-only dependency. The NUMA-interleave path is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+9
-10
@@ -6,28 +6,27 @@
|
||||
#include "JFJochException.h"
|
||||
#include "ZeroCopyReturnValue.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#ifdef JFJOCH_USE_NUMA
|
||||
#include <numa.h>
|
||||
#endif
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
ImageBuffer::ImageBuffer(size_t buffer_size_bytes)
|
||||
: buffer_size(buffer_size_bytes) {
|
||||
|
||||
#ifdef JFJOCH_USE_NUMA
|
||||
// Interleave the buffer across NUMA nodes - throughput-critical path (receiver), Linux-only.
|
||||
buffer = static_cast<uint8_t *>(numa_alloc_interleaved(buffer_size));
|
||||
#else
|
||||
// The non-NUMA mapping carried no huge-page / mbind flags, so a plain heap allocation is
|
||||
// equivalent (and portable). The buffer is zeroed below.
|
||||
buffer = static_cast<uint8_t *>(std::malloc(buffer_size));
|
||||
#endif
|
||||
if (buffer == nullptr)
|
||||
throw JFJochException(JFJochExceptionCategory::MemAllocFailed,
|
||||
"Failed to allocate image buffer");
|
||||
|
||||
#else
|
||||
buffer = (uint8_t *) mmap (nullptr, buffer_size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) ;
|
||||
if (buffer == MAP_FAILED)
|
||||
throw JFJochException(JFJochExceptionCategory::MemAllocFailed,
|
||||
"Failed to allocate image buffer");
|
||||
#endif
|
||||
memset(buffer, 0, buffer_size);
|
||||
}
|
||||
|
||||
@@ -39,7 +38,7 @@ ImageBuffer::~ImageBuffer() {
|
||||
#ifdef JFJOCH_USE_NUMA
|
||||
numa_free(buffer, buffer_size);
|
||||
#else
|
||||
munmap(buffer, buffer_size);
|
||||
std::free(buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user