Closed
Description
putRawTailOrdered()
in Java is implemented with packTail()
with the implementation below:
return ((long)termId << 32) | (termOffset & 0xFFFF_FFFFL);
This has the expected behaviour of 32 termId
bits followed by 32 termOffset
bits.
While in C++ the same code is implemented with:
((termId << 32) + termOffset)
Where termId
is cast to an int64_t
implicitly at the function call.
I suppose both termId
and termOffset
can take negative values. In that case the two implementations produce different results. Also it is possible to get numeric overflow. And, furthermore, left shift of negative integers is undefined in C and C++ even though most implementations pad zeroes.
Compatible C++ implementation is:
inline void putRawTailOrdered(const std::int32_t termId, const std::int32_t termOffset)
{
aeron::concurrent::atomic::putInt64Ordered(m_tailAddr, termId * ((int64_t(1) << 32) | (int64_t(0xFFFFFFFF) & termOffset);
}
Metadata
Metadata
Assignees
Labels
No labels