Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
nuke TLS
  • Loading branch information
rtri committed Aug 28, 2019
1 parent 8cb7408 commit 0cbc60a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
3 changes: 2 additions & 1 deletion rts/System/FileSystem/ArchiveScanner.cpp
Expand Up @@ -928,6 +928,7 @@ bool CArchiveScanner::GetArchiveChecksum(const std::string& archiveName, Archive
std::unique_ptr<IFileFilter> ignore(CreateIgnoreFilter(ar.get()));
std::vector<std::string> fileNames;
std::vector<sha512::raw_digest> fileHashes;
std::array<std::vector<std::uint8_t>, ThreadPool::MAX_THREADS> fileBuffers;

fileNames.reserve(ar->NumFiles());
fileHashes.reserve(ar->NumFiles());
Expand All @@ -948,7 +949,7 @@ bool CArchiveScanner::GetArchiveChecksum(const std::string& archiveName, Archive

// compute hashes of the files
for_mt(0, fileNames.size(), [&](const int i) {
ar->CalcHash(ar->FindFile(fileNames[i]), fileHashes[i].data());
ar->CalcHash(ar->FindFile(fileNames[i]), fileHashes[i].data(), fileBuffers[ ThreadPool::GetThreadNum() ]);

#if !defined(DEDICATED) && !defined(UNITSYNC)
Watchdog::ClearTimer(WDT_MAIN);
Expand Down
10 changes: 4 additions & 6 deletions rts/System/FileSystem/Archives/IArchive.cpp
Expand Up @@ -15,18 +15,16 @@ unsigned int IArchive::FindFile(const std::string& filePath) const
return NumFiles();
}

bool IArchive::CalcHash(uint32_t fid, uint8_t hash[sha512::SHA_LEN])
bool IArchive::CalcHash(uint32_t fid, uint8_t hash[sha512::SHA_LEN], std::vector<std::uint8_t>& fb)
{
// NOTE: should be possible to avoid a re-read for buffered archives
std::vector<std::uint8_t> buffer;

if (!GetFile(fid, buffer))
if (!GetFile(fid, fb))
return false;

if (buffer.empty())
if (fb.empty())
return false;

sha512::calc_digest(buffer.data(), buffer.size(), hash);
sha512::calc_digest(fb.data(), fb.size(), hash);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion rts/System/FileSystem/Archives/IArchive.h
Expand Up @@ -124,7 +124,7 @@ class IArchive
/**
* Fetches the (SHA512) hash of a file by its ID.
*/
virtual bool CalcHash(uint32_t fid, uint8_t hash[sha512::SHA_LEN]);
virtual bool CalcHash(uint32_t fid, uint8_t hash[sha512::SHA_LEN], std::vector<std::uint8_t>& fb);


protected:
Expand Down
5 changes: 1 addition & 4 deletions rts/System/FileSystem/Archives/PoolArchive.h
Expand Up @@ -8,7 +8,6 @@

#include "IArchiveFactory.h"
#include "BufferedArchive.h"
#include "System/MainDefines.h"


/**
Expand Down Expand Up @@ -89,12 +88,10 @@ class CPoolArchive : public CBufferedArchive
name = files[fid].name;
size = files[fid].size;
}
bool CalcHash(uint32_t fid, uint8_t hash[sha512::SHA_LEN]) override {
bool CalcHash(uint32_t fid, uint8_t hash[sha512::SHA_LEN], std::vector<std::uint8_t>& fb) override {
assert(IsFileId(fid));

const FileData& fd = files[fid];
// TLS to handle ArchiveScanner threading
static _threadlocal std::vector<std::uint8_t> fb;

// pool-entry hashes are not calculated until GetFileImpl, must check JIT
if (memcmp(fd.shasum.data(), dummyFileHash.data(), sizeof(fd.shasum)) == 0)
Expand Down

0 comments on commit 0cbc60a

Please sign in to comment.