Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaKernel] Remove usage of helper::system::atomic<int> (replaced by STL's) #1035

Merged
merged 2 commits into from
May 21, 2019

Conversation

fredroy
Copy link
Contributor

@fredroy fredroy commented May 10, 2019

helper::system::atomic was introduced long time ago (before std::atomic I guess).
This code is compiling only for i386 and x86_64 code with gcc/clang (and msvc)
Now that std::atomic is here (and we are using c+>11), I guess it is time to use std::atomic where we can.

Those modifications mostly appeared in multithreading-related code, so it would be good that @fspadoni could take a look :octocat:


This PR:

  • builds with SUCCESS for all platforms on the CI.
  • does not generate new warnings.
  • does not generate new unit test failures.
  • does not generate new scene test failures.
  • does not break API compatibility.
  • is more than 1 week old (or has fast-merge label).

Reviewers will merge only if all these checks are true.

@fredroy fredroy added the pr: status wip Development in the pull-request is still in progress label May 10, 2019
@fredroy fredroy force-pushed the remove_system_atomicint branch from 88419b4 to 4c77c72 Compare May 10, 2019 23:01
@fredroy fredroy changed the title [SofaKernel] Remove usage of std::helper::atomic<int> (replaced by STL's) [SofaKernel] Remove usage of helper::system::atomic<int> (replaced by STL's) May 11, 2019
@fredroy
Copy link
Contributor Author

fredroy commented May 11, 2019

[ci-build][with-all-scenes]

@fredroy
Copy link
Contributor Author

fredroy commented May 12, 2019

[ci-build][with-all-tests]

@fredroy fredroy added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels May 13, 2019
}
while(!array[writeIdx].compare_exchange_strong(refInt, item) );
//while(array[writeIdx].compare_and_swap(-1, item) != -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Keeping the old line on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I am not so sure that what I have done what the correct thing to do; so I kept the old line to check the previous behavior....

}
while(item == -1);
//while((item = array[readIdx]) == -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Keeping the old line on purpose?

Copy link
Contributor

@fspadoni fspadoni May 14, 2019

Choose a reason for hiding this comment

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

Just a quick remark:
In general I always prefer to explicitly call the load/store functions for read/write atomic operations like this:

do
{
    item.exchange(array[readIdx].load() );
} 
while(item.load() == -1);

It helps to quickly understand or remind the developers that it's an atomic operation and it allows to set the memory order model to do some optimization.
But in this case the memory order is not specified (default value) so explicitly call the load/store function call is only to make clear that there is an atomic read/write operation.
I see that explicitly call the load/store functions was not previously used so I don't know if it worths to check all the atomic operations.

@guparan guparan added the pr: clean Cleaning the code label May 13, 2019
@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels May 21, 2019
@damienmarchal
Copy link
Contributor

Thanks mr roy

@damienmarchal damienmarchal merged commit 6b25d21 into sofa-framework:master May 21, 2019
@guparan guparan removed pr: status to review To notify reviewers to review this pull-request labels Jun 20, 2019
@guparan guparan added this to the v19.06 milestone Jun 20, 2019
@fredroy fredroy deleted the remove_system_atomicint branch October 11, 2019 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: clean Cleaning the code pr: status ready Approved a pull-request, ready to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants