| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef KONCLUDE_REASONER_KERNEL_CACHE_CSIGNATURESATISFIABLEEXPANDERCACHE_H |
| 22 |
#define KONCLUDE_REASONER_KERNEL_CACHE_CSIGNATURESATISFIABLEEXPANDERCACHE_H |
| 23 |
|
| 24 |
// Libraries includes |
| 25 |
#include <QHash> |
| 26 |
#include <QMutex> |
| 27 |
#include <QSemaphore> |
| 28 |
|
| 29 |
// Namespace includes |
| 30 |
#include "CacheSettings.h" |
| 31 |
#include "CSatisfiableCache.h" |
| 32 |
#include "CSignatureSatisfiableExpanderCacheHasher.h" |
| 33 |
#include "CSignatureSatisfiableExpanderCacheSlotItem.h" |
| 34 |
#include "CSignatureSatisfiableExpanderCacheEntry.h" |
| 35 |
#include "CSignatureSatisfiableExpanderCacheContext.h" |
| 36 |
#include "CSignatureSatisfiableExpanderCacheReader.h" |
| 37 |
#include "CSignatureSatisfiableExpanderCacheEntryExpandWriteData.h" |
| 38 |
#include "CSignatureSatisfiableExpanderCacheEntrySatisfiableBranchWriteData.h" |
| 39 |
#include "CCacheStatistics.h" |
| 40 |
|
| 41 |
|
| 42 |
// Other includes |
| 43 |
#include "Concurrent/CThread.h" |
| 44 |
|
| 45 |
#include "Config/CConfiguration.h" |
| 46 |
#include "Config/CConfigDataReader.h" |
| 47 |
|
| 48 |
#include "Reasoner/Kernel/Cache/Events/CWriteCachedDataEvent.h" |
| 49 |
#include "Reasoner/Kernel/Cache/Events/CWriteExpandCachedEvent.h" |
| 50 |
#include "Reasoner/Kernel/Cache/Events/CWriteSatisfiableBranchCachedEvent.h" |
| 51 |
|
| 52 |
#include "Utilities/Memory/CObjectMemoryPoolAllocator.h" |
| 53 |
#include "Utilities/Memory/CObjectParameterizingAllocator.h" |
| 54 |
#include "Utilities/Memory/CMemoryPoolContainerAllocationManager.h" |
| 55 |
|
| 56 |
#include "Context/CContextBase.h" |
| 57 |
|
| 58 |
|
| 59 |
// Logger includes |
| 60 |
#include "Logger/CLogger.h" |
| 61 |
|
| 62 |
|
| 63 |
//#define KONCLUCE_SATISFIBALE_EXPANDER_CACHE_DIRECT_WRITING |
| 64 |
|
| 65 |
|
| 66 |
namespace Konclude { |
| 67 |
|
| 68 |
using namespace Config; |
| 69 |
using namespace Concurrent; |
| 70 |
using namespace Context; |
| 71 |
using namespace Utilities::Memory; |
| 72 |
|
| 73 |
namespace Reasoner { |
| 74 |
|
| 75 |
namespace Kernel { |
| 76 |
|
| 77 |
namespace Cache { |
| 78 |
|
| 79 |
using namespace Events; |
| 80 |
|
| 81 |
/*! |
| 82 |
* |
| 83 |
* \class CSignatureSatisfiableExpanderCache |
| 84 |
* \author Andreas Steigmiller |
| 85 |
* \version 0.1 |
| 86 |
* \brief TODO |
| 87 |
* |
| 88 |
*/ |
| 89 |
class CSignatureSatisfiableExpanderCache : public CThread, public CSatisfiableCache { |
| 90 |
// public methods |
| 91 |
public: |
| 92 |
//! Constructor |
| 93 |
CSignatureSatisfiableExpanderCache(CConfiguration* config, QString threadIdentifierName = "Satisfiable-Expander-Cache", CWatchDog *watchDogThread = 0); |
| 94 |
|
| 95 |
//! Destructor |
| 96 |
virtual ~CSignatureSatisfiableExpanderCache(); |
| 97 |
|
| 98 |
CSignatureSatisfiableExpanderCacheReader* createCacheReader(); |
| 99 |
CSignatureSatisfiableExpanderCacheWriter* createCacheWriter(); |
| 100 |
|
| 101 |
|
| 102 |
CSignatureSatisfiableExpanderCache* writeCachedData(CSignatureSatisfiableExpanderCacheEntryWriteData* writeData, CMemoryPool* memoryPools); |
| 103 |
CSignatureSatisfiableExpanderCache* writeExpandCached(cint64 prevSignature, cint64 newSignature, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGHASH<cint64,cint64>* depHash, CMemoryPool* memoryPools); |
| 104 |
CSignatureSatisfiableExpanderCache* writeSatisfiableBranchCached(cint64 signature, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGLIST<CCacheValue>* branchedList, CMemoryPool* memoryPools); |
| 105 |
|
| 106 |
CCacheStatistics* getCacheStatistics(); |
| 107 |
|
| 108 |
// protected methods |
| 109 |
protected: |
| 110 |
bool isCachingDataExpandable(CSignatureSatisfiableExpanderCacheContext* context, CSignatureSatisfiableExpanderCacheEntry* entry, cint64 signature, CCACHINGLIST<CCacheValue>* cacheValueList); |
| 111 |
|
| 112 |
void writeExpanderCachingData(CSignatureSatisfiableExpanderCacheContext* context, CSignatureSatisfiableExpanderCacheEntry* entry, bool extending, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGHASH<cint64,cint64>* depHash); |
| 113 |
bool writeExpanderCachingData(CSignatureSatisfiableExpanderCacheContext* context, cint64 prevSignature, cint64 newSignature, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGHASH<cint64,cint64>* depHash); |
| 114 |
void addExpanderCachingData(CSignatureSatisfiableExpanderCacheContext* context, const CCacheValue& cacheValue, CCACHINGHASH<cint64,CExpanderCacheValueLinker*>* newTagHash, CCACHINGHASH<cint64,cint64>* depHash, CCACHINGHASH<cint64,CCacheValue>* tagCacheValueHash, CExpanderCacheValueLinker*& lastExpCacheValueLinker, CExpanderCacheValueLinker*& firstExpCacheValueLinker); |
| 115 |
|
| 116 |
bool writeSatisfiableBranchedCachingData(CSignatureSatisfiableExpanderCacheContext* context, cint64 signature, CCACHINGLIST<CCacheValue>* cacheValueList, CCACHINGLIST<CCacheValue>* branchedValueList); |
| 117 |
|
| 118 |
void createReaderSlotUpdate(CSignatureSatisfiableExpanderCacheContext* context); |
| 119 |
void cleanUnusedSlots(CSignatureSatisfiableExpanderCacheContext* context); |
| 120 |
|
| 121 |
|
| 122 |
virtual bool processCustomsEvents(QEvent::Type type, CCustomEvent *event); |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
cint64 getRequiredSignatureReferCountForNextCacheEntryCreation(CSignatureSatisfiableExpanderCacheContext* context); |
| 127 |
cint64 canCreateCacheEntryForSignature(cint64 singature, CSignatureSatisfiableExpanderCacheContext* context); |
| 128 |
|
| 129 |
// protected variables |
| 130 |
protected: |
| 131 |
CCACHINGHASH<cint64,CSignatureSatisfiableExpanderCacheRedirectionItem*>* mSigItemHash; |
| 132 |
CCACHINGSET<cint64>* mIncompatibleSigSet; |
| 133 |
CCACHINGSET<cint64>* mAlreadyExpSigSet; |
| 134 |
// currently not used |
| 135 |
CCACHINGHASH<CSignatureSatisfiableExpanderCacheHasher,CSignatureSatisfiableExpanderCacheRedirectionItem*>* mHasherItemHash; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
CCACHINGHASH<cint64,cint64>* mSignatureReferCountSet; |
| 140 |
cint64 mNextCacheEntryRequiredSignatureRefCount; |
| 141 |
cint64 mNextMemoryLevelRequiredSignatureRefCount; |
| 142 |
|
| 143 |
cint64 mNextCacheEntryRequiredSignatureReferenceCountIncrease; |
| 144 |
cint64 mNextMemoryLevelIncreaseForRequiredSignatureReferenceCount; |
| 145 |
|
| 146 |
|
| 147 |
cint64 mWriteDataCount; |
| 148 |
cint64 mStartWriteCollectCount; |
| 149 |
cint64 mNextWriteCollectCount; |
| 150 |
cint64 mCollectCount; |
| 151 |
CMemoryPool* mCollectMemoryPools; |
| 152 |
CSignatureSatisfiableExpanderCacheEntryWriteData* mCollectWriteData; |
| 153 |
|
| 154 |
|
| 155 |
CCacheStatistics mCacheStat; |
| 156 |
|
| 157 |
CSignatureSatisfiableExpanderCacheSlotItem* mSlotLinker; |
| 158 |
CSignatureSatisfiableExpanderCacheReader* mReaderLinker; |
| 159 |
|
| 160 |
QMutex mReaderSyncMutex; |
| 161 |
|
| 162 |
CSignatureSatisfiableExpanderCacheContext mContext; |
| 163 |
CConfiguration* mConfig; |
| 164 |
|
| 165 |
// private methods |
| 166 |
private: |
| 167 |
|
| 168 |
// private variables |
| 169 |
private: |
| 170 |
|
| 171 |
}; |
| 172 |
|
| 173 |
}; // end namespace Cache |
| 174 |
|
| 175 |
}; // end namespace Kernel |
| 176 |
|
| 177 |
}; // end namespace Reasoner |
| 178 |
|
| 179 |
}; // end namespace Konclude |
| 180 |
|
| 181 |
#endif // KONCLUDE_REASONER_KERNEL_CACHE_CSIGNATURESATISFIABLEEXPANDERCACHE_H |