[Development] atomic reference counting implementation

Kevin Kofler kevin.kofler at chello.at
Sat Aug 10 14:41:21 CEST 2019


Mutz, Marc via Development wrote:
> But that's the whole point Olivier was making two years ago: ref() is
> _documented_ to be a memory barrier:
> 
> https://doc.qt.io/qt-5/qatomicinteger.html#ref:

But QSharedDataPointer is NOT documented to call QAtomicInteger::ref/deref, 
the documentation just talks about incrementing or decrementing reference 
counts. So the exact method called is an implementation detail.

Hence, why can't we just add new QAtomicInteger::refRelaxed and 
QAtomicInteger::derefRelaxed methods and use those in QSharedDataPointer 
instead of plain ref and deref? It is a drop-in replacement, introduces no 
code duplication, and does not change any documented behavior.

> - applications programmers can continue to use QSD and "suffer" from the
> performance drag of ordered ref(). They can also use QISP + std::atomic
> as ref-count and implement their own qIntrusiveRef/Deref to match what
> Herb and Hans recommend.

That sounds to me like a lot of unnecessary boilerplate (implementing the 
qIntrusiveRef/Deref glue functions), even if you don't see the required 
mixing of Qt and STL APIs as an issue. And existing projects would also have 
to port their code to get the improvements.

        Kevin Kofler



More information about the Development mailing list