Liste des Groupes | Revenir à cl c++ |
On 17.09.2024 09:04, Chris M. Thomasson wrote:[... snip code ...]On 9/16/2024 10:59 PM, Chris M. Thomasson wrote:Yes. Otherwise I could not generate new smartpointers from bare T*.On 9/16/2024 10:54 PM, Paavo Helde wrote:[...]>template<typename T>
class CachedAtomicPtr {
public:
CachedAtomicPtr(): ptr_(nullptr) {}
>
/// Store p in *this if *this is not yet assigned.
/// Return pointer stored in *this, which can be \a p or not.
Ptr<T> AssignIfNull(Ptr<T> p) {
const T* other = nullptr;
if (ptr_.compare_exchange_weak(other, p.get(), std::memory_order_release, std::memory_order_acquire)) {
p->IncrementRefcount();
return p;
} else {
// wrap in an extra smartptr (increments refcount)
return Ptr<T>(other);
}
^^^^^^^^^^^^^^^^^^
>
Is Ptr<T> an intrusive reference count? I assume it is.
FYI, here is my current full compilable code together with a test harness (no relacy, could not get it working, so this just creates a number of threads which make use of the CachedAtomicPtr objects in parallel.
Les messages affichés proviennent d'usenet.