File indexing completed on 2023-09-24 04:04:46
0001 /* This file is part of the KDE project 0002 Copyright (C) 2007 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License version 2 as published by the Free Software Foundation. 0007 0008 This library is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 Library General Public License for more details. 0012 0013 You should have received a copy of the GNU Library General Public License 0014 along with this library; see the file COPYING.LIB. If not, write to 0015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0016 Boston, MA 02110-1301, USA. 0017 0018 */ 0019 0020 #ifndef KERNEL_KCOMPONENTDATA_P_H 0021 #define KERNEL_KCOMPONENTDATA_P_H 0022 0023 #include "kcomponentdata.h" 0024 #include <QAtomicInt> 0025 #include <QDebug> 0026 #include <QCoreApplication> 0027 #include <QString> 0028 0029 #include <kconfig.h> 0030 #include <k4aboutdata.h> 0031 0032 class KComponentDataPrivate 0033 { 0034 public: 0035 KComponentDataPrivate(const K4AboutData &aboutData_) 0036 : aboutData(aboutData_), 0037 refCount(1) 0038 { 0039 } 0040 0041 ~KComponentDataPrivate() 0042 { 0043 refCount.fetchAndStoreOrdered(-0x00FFFFFF); //prevent a reentering of the dtor 0044 0045 sharedConfig = nullptr; //delete the config object first, because it could access the standard dirs while syncing 0046 } 0047 0048 inline void ref() 0049 { 0050 refCount.ref(); 0051 //qDebug() << refCount - 1 << "->" << refCount << kBacktrace() << endl; 0052 } 0053 0054 inline void deref() 0055 { 0056 const int refc = refCount.fetchAndAddOrdered(-1) - 1; 0057 //qDebug() << refCount + 1 << "->" << refCount << kBacktrace() << endl; 0058 if (refc == 0) { 0059 delete this; 0060 } 0061 } 0062 0063 void lazyInit(); 0064 void configInit(); //call this only from lazyInit()! 0065 0066 K4AboutData aboutData; 0067 QString configName; 0068 KSharedConfig::Ptr sharedConfig; 0069 0070 private: 0071 QAtomicInt refCount; 0072 KComponentDataPrivate(const KComponentDataPrivate &); 0073 KComponentDataPrivate &operator=(const KComponentDataPrivate &); 0074 }; 0075 0076 #endif // KERNEL_KCOMPONENTDATA_P_H