-
Notifications
You must be signed in to change notification settings - Fork 317
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
[SofaKernel] Remove usage of helper::system::atomic<int> (replaced by STL's) #1035
Conversation
88419b4
to
4c77c72
Compare
[ci-build][with-all-scenes] |
[ci-build][with-all-tests] |
} | ||
while(!array[writeIdx].compare_exchange_strong(refInt, item) ); | ||
//while(array[writeIdx].compare_and_swap(-1, item) != -1) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Thanks mr roy |
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
This PR:
Reviewers will merge only if all these checks are true.