Skip to content

Conversation

@jonesmz
Copy link

@jonesmz jonesmz commented Sep 30, 2018

Please note: I did not do extensive testing on this pull request. I'm not actually able to run the game on my development machine. Something's causing the Linux graphics driver to die. Who knows why.

I also did not test that this compiles successfully with any version of Visual Studio. Your mileage may vary.

That being said, I believe this PR should be bug free and very easy for reviewers to go through.

newVal = flagOn ? (prevVal | flag) : (prevVal & ~flag);

} while(flags.compare_exchange_strong(newVal, prevVal) != prevVal);
} while( ! flags.compare_exchange_strong(prevVal, newVal));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the std::atomic version of compare_exchange_strong has the arguments switched, and returns bool instead of the value currently being stored.

void stop() {
runThread.compare_exchange_strong(1, 2);
std::int32_t comparand = 2;
runThread.compare_exchange_strong(comparand, 1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the std::atomic version of compare_exchange_strong has the arguments switched, and returns bool instead of the value currently being stored.

The first argument is also a reference, and has it's value replaced with the value stored in the atomic object at the time the operation is initiated. Previously this would have been the return value.

if(localFunc) {
if(runThread.compare_exchange_strong(2, 0) == 0) {
std::int32_t comparand = 0;
if(runThread.compare_exchange_strong(comparand, 2)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the std::atomic version of compare_exchange_strong has the arguments switched, and returns bool instead of the value currently being stored.

The first argument is also a reference, and has it's value replaced with the value stored in the atomic object at the time the operation is initiated. Previously this would have been the return value.

int operator--(int);

int operator+=(int value);
int operator-=(int value);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these operators are provided by std::atomic<int32_t>

// Offered for backwards compatibility
int32_t get_basic()
{
return load();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously these provided non-atomic get and set.

I didn't see how that would be valid, since it goes against the basic concept of std::atomic. So now they conduct the operations atomically.

Eventually these functions should go away, but they were used in a lot of places and I didn't see any harm in keeping them for now.


int get() const { return value; }
operator int() const { return value; }
void wait_compare_exchange(const int32_t xchg, const int32_t compareToOriginal, const int32_t spinCount) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reimplemented using the std::atomic<>::compare_exchange_strong.

the std::atomic version of compare_exchange_strong has the arguments switched, and returns bool instead of the value currently being stored.

The first argument is also a reference, and has it's value replaced with the value stored in the atomic object at the time the operation is initiated. Previously this would have been the return value.

int id = getThreadID();
if(owningThread != id) {
for(unsigned i = 0; i < spinCount; ++i) {
if(owningThread.compare_exchange_strong(id, invalidThreadID) == invalidThreadID) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the std::atomic version of compare_exchange_strong has the arguments switched, and returns bool instead of the value currently being stored.

The first argument is also a reference, and has it's value replaced with the value stored in the atomic object at the time the operation is initiated. Previously this would have been the return value.

return owningThread == getThreadID();
}

void atomic_int::wait_compare_exchange(int xchg, int compareTo, const int spinCount) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the .h file.


bool Signal::checkAndSignal(int waitFor, int newSignal) {
return flag.compare_exchange_strong(newSignal, waitFor) == waitFor;
return flag.compare_exchange_strong(waitFor, newSignal);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the std::atomic version of compare_exchange_strong has the arguments switched, and returns bool instead of the value currently being stored.

The first argument is also a reference, and has it's value replaced with the value stored in the atomic object at the time the operation is initiated. Previously this would have been the return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant