mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 19:07:08 +00:00
24 lines
703 B
C++
24 lines
703 B
C++
|
#include "file_consumer.h"
|
||
|
|
||
|
FileConsumer::FileConsumer(SharedState* shared_state) : shared_(shared_state) {}
|
||
|
|
||
|
void FileConsumer::ClearOwnership() {
|
||
|
for (auto& entry : local_)
|
||
|
entry.second = Ownership::DoesNotOwn;
|
||
|
}
|
||
|
|
||
|
bool FileConsumer::DoesOwnFile(const std::string& file) {
|
||
|
// Try to find cached local result.
|
||
|
auto it = local_.find(file);
|
||
|
if (it != local_.end())
|
||
|
return it->second == Ownership::Owns;
|
||
|
|
||
|
// No result in local; we need to query global.
|
||
|
bool did_insert = false;
|
||
|
{
|
||
|
std::lock_guard<std::mutex> lock(shared_->muetx);
|
||
|
did_insert = shared_->files.insert(file).second;
|
||
|
}
|
||
|
local_[file] = did_insert ? Ownership::Owns : Ownership::DoesNotOwn;
|
||
|
return did_insert;
|
||
|
}
|