| 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_COCCURRENCEUNSATISFIABLECACHE_H |
| 22 |
#define KONCLUDE_REASONER_KERNEL_CACHE_COCCURRENCEUNSATISFIABLECACHE_H |
| 23 |
|
| 24 |
// Libraries includes |
| 25 |
#include <QHash> |
| 26 |
#include <QMutex> |
| 27 |
#include <QSemaphore> |
| 28 |
#include <QVector> |
| 29 |
#include <QList> |
| 30 |
#include <QStringList> |
| 31 |
#include <QReadWriteLock> |
| 32 |
|
| 33 |
// Namespace includes |
| 34 |
#include "CacheSettings.h" |
| 35 |
#include "COccurrenceUnsatisfiableCacheReader.h" |
| 36 |
#include "COccurrenceUnsatisfiableCacheEntry.h" |
| 37 |
#include "CUnsatisfiableCache.h" |
| 38 |
#include "CCacheValue.h" |
| 39 |
#include "COccurrenceUnsatisfiableCacheUpdateSlotItem.h" |
| 40 |
#include "COccurrenceUnsatisfiableCacheEntriesHash.h" |
| 41 |
#include "COccurrenceUnsatisfiableCacheWriter.h" |
| 42 |
#include "CCacheTaggingPool.h" |
| 43 |
#include "CCacheStatistics.h" |
| 44 |
|
| 45 |
|
| 46 |
// Other includes |
| 47 |
#include "Reasoner/Ontology/CConcept.h" |
| 48 |
#include "Reasoner/Ontology/CConceptTextFormater.h" |
| 49 |
#include "Reasoner/Ontology/CConceptProcessData.h" |
| 50 |
|
| 51 |
#include "Concurrent/CThread.h" |
| 52 |
|
| 53 |
#include "Events/CWriteUnsatisfiableCacheEntryEvent.h" |
| 54 |
|
| 55 |
// Logger includes |
| 56 |
#include "Logger/CLogger.h" |
| 57 |
|
| 58 |
#include <iostream> |
| 59 |
|
| 60 |
namespace Konclude { |
| 61 |
|
| 62 |
using namespace Concurrent; |
| 63 |
|
| 64 |
namespace Reasoner { |
| 65 |
|
| 66 |
using namespace Ontology; |
| 67 |
|
| 68 |
namespace Kernel { |
| 69 |
|
| 70 |
namespace Cache { |
| 71 |
|
| 72 |
using namespace Events; |
| 73 |
|
| 74 |
#ifdef KONCLUDE_FORCE_ALL_DEBUG_DEACTIVATED |
| 75 |
#define KONCLUCE_OCCURUNSATCACHE_CACHING_STRING_INSTRUCTION(a) |
| 76 |
#else |
| 77 |
|
| 78 |
//#define KONCLUCE_OCCURUNSATCACHE_CACHING_STRING_INSTRUCTION(a) a |
| 79 |
#define KONCLUCE_OCCURUNSATCACHE_CACHING_STRING_INSTRUCTION(a) |
| 80 |
|
| 81 |
#endif |
| 82 |
|
| 83 |
/*! |
| 84 |
* |
| 85 |
* \class COccurrenceUnsatisfiableCache |
| 86 |
* \author Andreas Steigmiller |
| 87 |
* \version 0.1 |
| 88 |
* \brief TODO |
| 89 |
* |
| 90 |
*/ |
| 91 |
class COccurrenceUnsatisfiableCache : public CThread, public CUnsatisfiableCache { |
| 92 |
// public methods |
| 93 |
public: |
| 94 |
//! Constructor |
| 95 |
COccurrenceUnsatisfiableCache(qint64 writeUpdateSlotCount, const QString &threadIdentifierName = QString("Unsatisfiable-Cache"), CWatchDog *watchDogThread = 0); |
| 96 |
|
| 97 |
//! Destructor |
| 98 |
virtual ~COccurrenceUnsatisfiableCache(); |
| 99 |
|
| 100 |
COccurrenceUnsatisfiableCacheReader *getCacheReader(); |
| 101 |
COccurrenceUnsatisfiableCacheWriter *getCacheWriter(); |
| 102 |
|
| 103 |
|
| 104 |
COccurrenceUnsatisfiableCacheEntry *getPrimarCacheEntry(); |
| 105 |
void addUnsatisfiableCacheEntry(QList<CCacheValue> &itemList); |
| 106 |
|
| 107 |
|
| 108 |
bool isCacheWritePending(); |
| 109 |
|
| 110 |
|
| 111 |
cint64 getCurrentCachingTag(); |
| 112 |
CCacheStatistics* getCacheStatistics(); |
| 113 |
|
| 114 |
// protected methods |
| 115 |
protected: |
| 116 |
|
| 117 |
virtual void threadStarted(); |
| 118 |
virtual void threadStopped(); |
| 119 |
|
| 120 |
virtual bool processCustomsEvents(QEvent::Type type, CCustomEvent *event); |
| 121 |
|
| 122 |
|
| 123 |
bool writeCacheTags(CCacheValue* cacheValue, cint64 cachingTag, cint64 cachedTag, cint64 cachingSize); |
| 124 |
bool writeCacheValues(COccurrenceUnsatisfiableCacheUpdateSlotItem *updateSlot, QList<CCacheValue> *cacheValueList); |
| 125 |
|
| 126 |
bool waitCacheWritePrepared(); |
| 127 |
bool activateCacheUpdate(COccurrenceUnsatisfiableCacheUpdateSlotItem *updateSlot); |
| 128 |
|
| 129 |
|
| 130 |
QString getCachingConceptsDebugString(QList<CCacheValue> &itemList); |
| 131 |
|
| 132 |
bool testAlreadyCached(COccurrenceUnsatisfiableCacheUpdateSlotItem *updateSlot, QList<CCacheValue> *cacheValueList); |
| 133 |
|
| 134 |
// private methods |
| 135 |
private: |
| 136 |
|
| 137 |
// private variables |
| 138 |
private: |
| 139 |
QMutex cacheReaderSyncMutex; |
| 140 |
QMutex cacheWriterSyncMutex; |
| 141 |
QList<COccurrenceUnsatisfiableCacheReader *> cacheReaderList; |
| 142 |
QList<COccurrenceUnsatisfiableCacheWriter *> cacheWriterList; |
| 143 |
|
| 144 |
COccurrenceUnsatisfiableCacheEntry *primarCacheEntry; |
| 145 |
QList<COccurrenceUnsatisfiableCacheEntry *> container; |
| 146 |
|
| 147 |
qint64 updateSlotCount; |
| 148 |
QVector<COccurrenceUnsatisfiableCacheUpdateSlotItem *> updatesSlotItemVector; |
| 149 |
QList<COccurrenceUnsatisfiableCacheUpdateSlotItem *> usedUpdatesSlotsList; |
| 150 |
QList<COccurrenceUnsatisfiableCacheUpdateSlotItem *> notusedUpdatesSlotsList; |
| 151 |
COccurrenceUnsatisfiableCacheUpdateSlotItem* lastUpdateSlot; |
| 152 |
|
| 153 |
QMutex lockFreeMutexSync; |
| 154 |
bool canGetLockFreeAccess; |
| 155 |
qint64 lockFreeAccessCount; |
| 156 |
QSemaphore lockFreeAccessLockSemaphore; |
| 157 |
|
| 158 |
|
| 159 |
bool cacheWritingRequested; |
| 160 |
|
| 161 |
qint64 writeOperationsCount; |
| 162 |
|
| 163 |
CCacheTaggingPool mCacheTaggingPool; |
| 164 |
cint64 mCachingTag; |
| 165 |
|
| 166 |
CCacheStatistics mCachStat; |
| 167 |
|
| 168 |
QString mCachingString; |
| 169 |
QStringList mCachedStringList; |
| 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_COCCURRENCEUNSATISFIABLECACHE_H |