C++ port of AtomicLong.lazySet

Viewed 310

I'm trying to port some Java code to Windows C++ and am confused about how to implement AtomicLong.lazySet(). The only information I can find talks about what it does but not how to implement it, and the available source code ends up in a private native library owned by Sun (sun.misc.Unsafe.class).

I currently just set a member variable to the passed parameter but I'm not sure if it's correct.

class AtomicLong
{
public:
    inline void LazySet(__int64 aValue)
    {
        // TODO: Is this correct?
        iValue = aValue;
    }

    inline void Set(__int64 aValue)
    {
        ::InterlockedExchange64(&iValue, aValue);
    }

private:
    __declspec(align(64)) volatile __int64 iValue;
};

I cannot use boost.

Edit: I'm compiling to x64 but perhaps solutions for 32-bit code would be of help to others.

I don't have access to C++11.

1 Answers
Related