1 /* 2 * DQt - D bindings for the Qt Toolkit 3 * 4 * GNU Lesser General Public License Usage 5 * This file may be used under the terms of the GNU Lesser 6 * General Public License version 3 as published by the Free Software 7 * Foundation and appearing in the file LICENSE.LGPL3 included in the 8 * packaging of this file. Please review the following information to 9 * ensure the GNU Lesser General Public License version 3 requirements 10 * will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 11 */ 12 module qt.core.refcount; 13 extern(C++): 14 15 import qt.config; 16 import qt.core.basicatomic; 17 import qt.helpers; 18 19 extern(C++, "QtPrivate") 20 { 21 22 23 extern(C++, class) struct RefCount 24 { 25 public: 26 extern(D) pragma(inline, true) bool ref_(string filename = __FILE__, size_t line = __LINE__)/+ noexcept+/ { 27 int count = atomic.loadRelaxed(); 28 if (count != -1) // !isStatic 29 atomic.ref_(); 30 return true; 31 } 32 33 extern(D) pragma(inline, true) bool deref(string filename = __FILE__, size_t line = __LINE__)/+ noexcept+/ { 34 int count = atomic.loadRelaxed(); 35 if (count == -1) // isStatic 36 return true; 37 return atomic.deref(); 38 } 39 40 /+ bool isStatic() const/+ noexcept+/ 41 { 42 // Persistent object, never deleted 43 return atomic.loadRelaxed() == -1; 44 }+/ 45 46 bool isShared() const/+ noexcept+/ 47 { 48 int count = atomic.loadRelaxed(); 49 return (count != 1) && (count != 0); 50 } 51 52 // void initializeOwned()/+ noexcept+/ { atomic.storeRelaxed(1); } 53 // void initializeUnsharable()/+ noexcept+/ { atomic.storeRelaxed(0); } 54 55 QBasicAtomicInt atomic; 56 } 57 58 } 59 60 /+ #define Q_REFCOUNT_INITIALIZE_STATIC { Q_BASIC_ATOMIC_INITIALIZER(-1) } +/ 61 62 63 enum Q_REFCOUNT_INITIALIZE_STATIC = RefCount(QBasicAtomicInt(-1)); 64