8000 Disparity between Java and C++ versions of putRawTailOrdered() · Issue #589 · aeron-io/aeron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Disparity between Java and C++ versions of putRawTailOrdered() #589
Closed
@denizevrenci

Description

@denizevrenci

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0