Skip to content

Commit

Permalink
fix: atomic shared_ptr checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed May 29, 2024
1 parent be9a55a commit 4805772
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/mrdocs/Dom/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,11 @@ class MRDOCS_DECL
class MRDOCS_DECL
LazyObjectImpl : public ObjectImpl
{
#ifdef __cpp_lib_atomic_shared_ptr
std::atomic<std::shared_ptr<ObjectImpl>> mutable sp_;
#else
std::shared_ptr<ObjectImpl> mutable sp_;
#endif

using impl_type = Object::impl_type;

Expand Down
4 changes: 4 additions & 0 deletions src/lib/Dom/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ ObjectImpl&
LazyObjectImpl::
obj() const
{
#ifdef __cpp_lib_atomic_shared_ptr
auto impl = sp_.load();
if(impl)
return *impl;
Expand All @@ -225,6 +226,9 @@ obj() const
expected, construct().impl()))
return *sp_.load();
return *expected;
#else
return *sp_;
#endif
}

std::size_t
Expand Down

0 comments on commit 4805772

Please sign in to comment.