fix msvc build

This commit is contained in:
BlackMATov
2023-01-31 08:01:53 +07:00
parent 14193a1434
commit fcced26218
2 changed files with 28 additions and 20 deletions

View File

@@ -718,17 +718,21 @@ namespace meta_hpp::detail
~intrusive_ref_counter() = default;
private:
mutable std::atomic_size_t counter_{};
friend void intrusive_ptr_add_ref<Derived>(const intrusive_ref_counter* ptr) {
ptr->counter_.fetch_add(1, std::memory_order_acq_rel);
}
friend void intrusive_ptr_release<Derived>(const intrusive_ref_counter* ptr) {
if ( ptr->counter_.fetch_sub(1, std::memory_order_acq_rel) == 1 ) {
std::unique_ptr<const Derived>(static_cast<const Derived*>(ptr)).reset();
}
}
friend void intrusive_ptr_add_ref<Derived>(const intrusive_ref_counter* ptr);
friend void intrusive_ptr_release<Derived>(const intrusive_ref_counter* ptr);
};
template < typename Derived >
void intrusive_ptr_add_ref(const intrusive_ref_counter<Derived>* ptr) {
ptr->counter_.fetch_add(1, std::memory_order_acq_rel);
}
template < typename Derived >
void intrusive_ptr_release(const intrusive_ref_counter<Derived>* ptr) {
if ( ptr->counter_.fetch_sub(1, std::memory_order_acq_rel) == 1 ) {
std::unique_ptr<const Derived>(static_cast<const Derived*>(ptr)).reset();
}
}
}
namespace meta_hpp::detail

View File

@@ -37,17 +37,21 @@ namespace meta_hpp::detail
~intrusive_ref_counter() = default;
private:
mutable std::atomic_size_t counter_{};
friend void intrusive_ptr_add_ref<Derived>(const intrusive_ref_counter* ptr) {
ptr->counter_.fetch_add(1, std::memory_order_acq_rel);
}
friend void intrusive_ptr_release<Derived>(const intrusive_ref_counter* ptr) {
if ( ptr->counter_.fetch_sub(1, std::memory_order_acq_rel) == 1 ) {
std::unique_ptr<const Derived>(static_cast<const Derived*>(ptr)).reset();
}
}
friend void intrusive_ptr_add_ref<Derived>(const intrusive_ref_counter* ptr);
friend void intrusive_ptr_release<Derived>(const intrusive_ref_counter* ptr);
};
template < typename Derived >
void intrusive_ptr_add_ref(const intrusive_ref_counter<Derived>* ptr) {
ptr->counter_.fetch_add(1, std::memory_order_acq_rel);
}
template < typename Derived >
void intrusive_ptr_release(const intrusive_ref_counter<Derived>* ptr) {
if ( ptr->counter_.fetch_sub(1, std::memory_order_acq_rel) == 1 ) {
std::unique_ptr<const Derived>(static_cast<const Derived*>(ptr)).reset();
}
}
}
namespace meta_hpp::detail