#include <Packet.h>
Classes | |
struct | CacheEntry |
Public Member Functions | |
std::unique_ptr< PacketLock > | lock (uint64_t packetLogicalOffset, char *&pkt) |
PacketReadCache (CheckedFile *cFile, unsigned packetCount) | |
Protected Member Functions | |
void | readPacket (unsigned oldestEntry, uint64_t packetLogicalOffset) |
void | unlock (unsigned cacheIndex) |
Protected Attributes | |
CheckedFile * | cFile_ = nullptr |
std::vector< CacheEntry > | entries_ |
unsigned | lockCount_ = 0 |
unsigned | useCount_ = 0 |
Friends | |
class | PacketLock |
Only PacketLock can unlock the cache. More... | |
PacketReadCache::PacketReadCache | ( | CheckedFile * | cFile, |
unsigned | packetCount | ||
) |
References e57::E57_ERROR_INTERNAL, and e57::toString().
std::unique_ptr< PacketLock > PacketReadCache::lock | ( | uint64_t | packetLogicalOffset, |
char *& | pkt | ||
) |
Only allow one locked packet at a time.
Offset can't be 0
Linear scan for matching packet offset in cache
Found a match, so don't have to read anything
Mark entry with current useCount (keeps track of age of entry).
Publish buffer address to caller
Create lock so we are sure that we will be unlocked when use is finished.
Increment cache lock just before return
Get here if didn't find a match already in cache.
Find least recently used (LRU) packet buffer
Publish buffer address to caller
Create lock so we are sure we will be unlocked when use is finished.
Increment cache lock just before return
References e57::E57_ERROR_INTERNAL, entries_, lockCount_, PacketLock, readPacket(), e57::toString(), and useCount_.
Referenced by e57::CompressedVectorReaderImpl::CompressedVectorReaderImpl(), AddonManager.CommandAddonManager::on_package_updated(), drafttaskpanels.task_scale.ScaleTaskPanel::retranslateUi(), drafttaskpanels.task_scale.ScaleTaskPanel::setValue(), addonmanager_workers.CacheMacroCode::terminate(), and addonmanager_workers.CacheMacroCode::update_and_advance().
|
protected |
Read header of packet first to get length. Use EmptyPacketHeader since it has the fields common to all packets.
Can't verify packet header here, because it is not really an EmptyPacketHeader.
Be paranoid about packetLength before read
Now read in whole packet into preallocated buffer_. Note buffer is
Verify that packet is good.
Mark entry with current useCount (keeps track of age of entry). This is a cache, so a small hiccup when useCount_ overflows won't hurt.
References cFile_, e57::DATA_PACKET, e57::DATA_PACKET_MAX, e57::E57_ERROR_BAD_CV_PACKET, e57::E57_ERROR_INTERNAL, e57::EMPTY_PACKET, entries_, e57::INDEX_PACKET, e57::CheckedFile::Logical, EmptyPacketHeader::packetLogicalLengthMinus1, EmptyPacketHeader::packetType, e57::CheckedFile::read(), e57::CheckedFile::seek(), e57::toString(), useCount_, EmptyPacketHeader::verify(), e57::DataPacket::verify(), and IndexPacket::verify().
Referenced by lock().
|
protected |
References e57::E57_ERROR_INTERNAL, lockCount_, and e57::toString().
Referenced by e57::PacketLock::~PacketLock().
|
friend |
Only PacketLock can unlock the cache.
Referenced by lock().
|
protected |
Referenced by readPacket().
|
protected |
Referenced by lock(), and readPacket().
|
protected |
Referenced by lock(), and readPacket().