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:
@@ -144,6 +144,26 @@ FetchContent_Declare(
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
||||
# ZeroMQ (libzmq): fetch it here, at the top level, so that THIS project - not
|
||||
# slsDetectorPackage - controls the version. slsDetectorPackage bundles its own libzmq
|
||||
# archive, but only populates it behind `if(NOT libzmq_POPULATED)`; by making libzmq
|
||||
# available before sls below, sls reuses this copy and a single libzmq-static target is
|
||||
# built (no duplicate target / double-symbol clash). A future viewer-only / Windows build
|
||||
# (which does not build sls) fetches the same libzmq standalone.
|
||||
SET(BUILD_SHARED OFF CACHE BOOL "" FORCE) # libzmq: static only (matches sls)
|
||||
SET(BUILD_TESTS OFF CACHE BOOL "" FORCE) # libzmq: no test build
|
||||
SET(WITH_PERF_TOOL OFF CACHE BOOL "" FORCE) # libzmq: no perf tools
|
||||
SET(WITH_DOCS OFF CACHE BOOL "" FORCE) # libzmq: no docs
|
||||
SET(ENABLE_CPACK OFF CACHE BOOL "" FORCE) # libzmq: no CPack injection
|
||||
FetchContent_Declare(
|
||||
libzmq
|
||||
GIT_REPOSITORY https://github.com/zeromq/libzmq.git
|
||||
GIT_TAG v4.3.5
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
||||
# libzmq must be made available BEFORE sls_detector_package for the override above to take effect.
|
||||
FetchContent_MakeAvailable(libzmq)
|
||||
FetchContent_MakeAvailable(zstd sls_detector_package catch2 hdf5 spdlog httplib)
|
||||
|
||||
ADD_SUBDIRECTORY(jungfrau)
|
||||
|
||||
+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
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user