diff --git a/CMakeLists.txt b/CMakeLists.txt index b3467b1a..7a6a515c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,7 @@ endif() option(ENABLE_UBSAN "Build with undefined behavior sanitizer" OFF) if(ENABLE_UBSAN) message(STATUS "Instrumenting with Undefined Behavior Sanitizer") - set(CMAKE_BUILD_TYPE "RelWithDebInfo") + set(CMAKE_BUILD_TYPE "Debug") set(UBSAN_FLAGS "${UBSAN_FLAGS} -fno-omit-frame-pointer") set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=undefined") set(UBSAN_FLAGS "${UBSAN_FLAGS} -fsanitize=implicit-conversion") @@ -464,6 +464,7 @@ message(STATUS "Using polling method in zmq_poll(er)_* API: ${API_POLLER}") string(TOUPPER ${API_POLLER} UPPER_API_POLLER) set(ZMQ_POLL_BASED_ON_${UPPER_API_POLLER} 1) +# special alignment settings execute_process( COMMAND getconf LEVEL1_DCACHE_LINESIZE OUTPUT_VARIABLE CACHELINE_SIZE @@ -476,6 +477,7 @@ else() set(ZMQ_CACHELINE_SIZE ${CACHELINE_SIZE}) endif() message(STATUS "Using ${ZMQ_CACHELINE_SIZE} bytes alignment for lock-free data structures") +check_cxx_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN) if(NOT CYGWIN) # TODO cannot we simply do 'if(WIN32) set(ZMQ_HAVE_WINDOWS ON)' or similar? @@ -1366,7 +1368,7 @@ else() add_library(libzmq SHARED $ ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc) endif() - + endif() # NOTE: the SOVERSION and VERSION MUST be the same as the one generated by libtool! It is NOT the same as the # version of the package. diff --git a/builds/cmake/platform.hpp.in b/builds/cmake/platform.hpp.in index 50bb8a96..013dca1b 100644 --- a/builds/cmake/platform.hpp.in +++ b/builds/cmake/platform.hpp.in @@ -16,6 +16,7 @@ #cmakedefine ZMQ_POLL_BASED_ON_SELECT #cmakedefine ZMQ_POLL_BASED_ON_POLL +#cmakedefine HAVE_POSIX_MEMALIGN @HAVE_POSIX_MEMALIGN@ #cmakedefine ZMQ_CACHELINE_SIZE @ZMQ_CACHELINE_SIZE@ #cmakedefine ZMQ_FORCE_MUTEXES diff --git a/src/command.hpp b/src/command.hpp index c92f7a7c..234c858a 100644 --- a/src/command.hpp +++ b/src/command.hpp @@ -33,6 +33,7 @@ #include #include "stdint.hpp" #include "endpoint.hpp" +#include "platform.hpp" namespace zmq { @@ -44,12 +45,7 @@ class socket_base_t; // This structure defines the commands that can be sent between threads. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4324) // C4324: alignment padding warnings -__declspec(align (64)) -#endif - struct command_t +struct command_t { // Object to process the command. zmq::object_t *destination; @@ -216,9 +212,12 @@ __declspec(align (64)) } args; #ifdef _MSC_VER }; -#pragma warning(pop) #else -} __attribute__ ((aligned (64))); +} +#ifdef HAVE_POSIX_MEMALIGN +__attribute__ ((aligned (ZMQ_CACHELINE_SIZE))) +#endif +; #endif } diff --git a/src/epoll.cpp b/src/epoll.cpp index fc641b74..da95bd0a 100644 --- a/src/epoll.cpp +++ b/src/epoll.cpp @@ -131,7 +131,7 @@ void zmq::epoll_t::reset_pollin (handle_t handle_) { check_thread (); poll_entry_t *pe = static_cast (handle_); - pe->ev.events &= ~(static_cast (EPOLLIN)); + pe->ev.events &= ~(static_cast (EPOLLIN)); const int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); errno_assert (rc != -1); } @@ -149,7 +149,7 @@ void zmq::epoll_t::reset_pollout (handle_t handle_) { check_thread (); poll_entry_t *pe = static_cast (handle_); - pe->ev.events &= ~(static_cast (EPOLLOUT)); + pe->ev.events &= ~(static_cast (EPOLLOUT)); const int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); errno_assert (rc != -1); } diff --git a/src/yqueue.hpp b/src/yqueue.hpp old mode 100644 new mode 100755 index 6ba634a3..0780ea7a --- a/src/yqueue.hpp +++ b/src/yqueue.hpp @@ -35,6 +35,7 @@ #include "err.hpp" #include "atomic_ptr.hpp" +#include "platform.hpp" namespace zmq { @@ -50,7 +51,7 @@ namespace zmq // T is the type of the object in the queue. // N is granularity of the queue (how many pushes have to be done till // actual memory allocation is required). -#ifdef HAVE_POSIX_MEMALIGN +#if defined HAVE_POSIX_MEMALIGN // ALIGN is the memory alignment size to use in the case where we have // posix_memalign available. Default value is 64, this alignment will // prevent two queue chunks from occupying the same CPU cache line on @@ -181,7 +182,7 @@ template class yqueue_t static inline chunk_t *allocate_chunk () { -#ifdef HAVE_POSIX_MEMALIGN +#if defined HAVE_POSIX_MEMALIGN void *pv; if (posix_memalign (&pv, ALIGN, sizeof (chunk_t)) == 0) return (chunk_t *) pv;