Use std::atomic to implement OpenThreads::Atomic and AtomicPtr - #48
Use std::atomic to implement OpenThreads::Atomic and AtomicPtr#48elsid wants to merge 2 commits into
Conversation
Current implementation of atomic load is suboptimal that is visible on ARM: https://godbolt.org/z/r4E7srWcE This also triggers thread sanitizer warnings like: ``` WARNING: ThreadSanitizer: data race (pid=42478) Atomic write of size 4 at 0x7254001afb90 by main thread: #0 OpenThreads::Atomic::operator++() OpenThreads/Atomic:110 OpenMW#1 osg::Referenced::ref() osg/Referenced:164 OpenMW#2 osg::ref_ptr<osg::Drawable>::ref_ptr osg/ref_ptr:37 OpenMW#3 osgUtil::RenderLeaf::RenderLeaf osgUtil/RenderLeaf:41 OpenMW#4 osgUtil::CullVisitor::createOrReuseRenderLeaf OpenMW#5 osgUtil::CullVisitor::addDrawableAndDepth Previous read of size 4 at 0x7254001afb90 by thread T112 (mutexes: write M0): #0 OpenThreads::Atomic::operator unsigned int() const OpenThreads/Atomic:225 OpenMW#1 osg::Referenced::referenceCount() osg/Referenced:97 OpenMW#2 Resource::GenericObjectCache<Terrain::ChunkKey>::update components/resource/objectcache.hpp:82 ... OpenMW#5 Resource::GenericObjectCache<Terrain::ChunkKey>::update components/resource/objectcache.hpp:77 ``` Remove all related code along with unnecessary mutex based reference counter.
|
This has a big overlap with #44, but unlike that PR, will only work when compiled as C++11 or later, and doesn't add anything to enforce that it is. We know there are distros packaging this fork rather than upstream OSG, as we've merged build fixes, so they'd have to carry those patches anyway even if they were applying them to an upstream branch, and they're not going to be passing in the flags for C++11 in an outer build system like we do. As I think I said on the other PR, I'm happy for our fork to use |
|
C++11 is already a requirement due to rvalue references used for ref_ptr. I don't see a value of keeping old implementation. |
|
19c1df1 should not have been merged into this repository. It's not the only commit from that PR that's caused problems. It does suggest that we can get away with bumping the minimum requirement to C++11, but we don't even know that for sure as it's not out of the question that someone's carrying a tiny patch to get rid of the move constructor. I don't think that's especially likely, though, as there's literally nothing else in the repo enforcing the language standard, so it just uses whatever the compiler uses by default unless something external forces something else, and anything still updating OSG is probably updating its compiler, and defaults to something way newer. That means that I'm going to say we can YOLO it and start requiring C++11 intentionally in this repo but only as long as we add something to the CMake to actually ensure the necessary flags are set. |
|
Anyone can have a patch removing C++11 requirement, restoring old atomic implementation etc. We should not care about this. |
|
At the moment, this repo is malformed, and can be fixed either by reverting 19c1df1 or by making the CMake changes I described above. I'm not merging anything that makes it more malformed, so if you want this to be mergeable, I suggest including those CMake changes in this PR. |
* osg::ref_ptr uses rvalue reference. * OpenThreads depends on <atomic>.
|
Added C++11 as requirement. |
|
If we care about correctness of CMake to have proper builds should we bump OPENSCENEGRAPH_SOVERSION because ABI changed since last time it was bumped? |
|
If I'm going to do thread sanitization checks based on if those patches are required I should probably based it on this mr and not #44 correct? |
I'm not sure. There have been several ABI breaks upstream since it was last bumped (e.g. several new members and functions in |
Yeah |
Current implementation of atomic load is suboptimal that is visible on ARM: https://godbolt.org/z/r4E7srWcE
This also triggers thread sanitizer warnings like:
Remove all related code along with unnecessary mutex based reference counter.