mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-29 16:45:51 +08:00
Problem: SIGBUS on SPARC64
Solution: force the compiler to make the atomic_counter_t alignment friendly. This will ensure that the pointers inside the buffers allocated by shared_message_memory are aligned, at the cost of growing the memory size of atomic_counter_t from 4 to 8 bytes on 64 bit (when not using mutexes). Note that although content_t contains an atomic_counter_t, the compiler already padded the struct so there is no change in the buffer sizes used by the engines, save for the extra 4 bytes for the buffer's own single atomic counter. Fixes #2588
This commit is contained in:
parent
f0ae5e585c
commit
e376c81c2d
@ -69,8 +69,22 @@ namespace zmq
|
||||
|
||||
// This class represents an integer that can be incremented/decremented
|
||||
// in atomic fashion.
|
||||
//
|
||||
// In zmq::shared_message_memory_allocator a buffer with an atomic_counter_t
|
||||
// at the start is allocated. If the class does not align to pointer size,
|
||||
// access to pointers in structures in the buffer will cause SIGBUS on
|
||||
// architectures that do not allow mis-aligned pointers (eg: SPARC).
|
||||
// Force the compiler to align to pointer size, which will cause the object
|
||||
// to grow from 4 bytes to 8 bytes on 64 bit architectures (when not using
|
||||
// mutexes).
|
||||
|
||||
#if defined (_MSC_VER) && (defined (_M_X64) || defined (_M_ARM64))
|
||||
class __declspec (align (8)) atomic_counter_t
|
||||
#elif defined (_MSC_VER) && (defined (_M_IX86) || defined (_M_ARM_ARMV7VE))
|
||||
class __declspec (align (4)) atomic_counter_t
|
||||
#else
|
||||
class atomic_counter_t
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
|
||||
@ -212,7 +226,13 @@ namespace zmq
|
||||
atomic_counter_t (const atomic_counter_t&);
|
||||
const atomic_counter_t& operator = (const atomic_counter_t&);
|
||||
#endif
|
||||
#if defined (__GNUC__) || defined ( __INTEL_COMPILER) || \
|
||||
(defined (__SUNPRO_C) && __SUNPRO_C >= 0x590) || \
|
||||
(defined (__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
|
||||
} __attribute__ ((aligned (sizeof (void *))));
|
||||
#else
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user