From 6d9e4242d13cf5693357b5c9a77a1151cdad9cea Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sat, 29 Jul 2017 23:51:32 -0700 Subject: [PATCH] Use shared_ptr, try to fix a crash. --- src/command_line.cc | 45 +++++++++++++++++++++++---------------------- src/performance.h | 18 ++++++++++-------- src/serializer.cc | 7 ------- src/serializer.h | 3 --- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/command_line.cc b/src/command_line.cc index 9f3e9f65..f1719ba5 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -554,12 +554,12 @@ void FilterCompletionResponse(Out_TextDocumentComplete* complete_response, struct Index_DoIdMap { - std::unique_ptr current; + std::shared_ptr current; PerformanceImportFile perf; bool is_interactive; explicit Index_DoIdMap( - std::unique_ptr current, + std::shared_ptr current, PerformanceImportFile perf, bool is_interactive) : current(std::move(current)), @@ -568,10 +568,10 @@ struct Index_DoIdMap { }; struct Index_OnIdMapped { - std::unique_ptr previous_index; - IndexFile* current_index; - std::unique_ptr previous_id_map; - IdMap* current_id_map; + std::shared_ptr previous_index; + std::shared_ptr current_index; + std::shared_ptr previous_id_map; + std::shared_ptr current_id_map; PerformanceImportFile perf; bool is_interactive; @@ -818,10 +818,10 @@ struct CacheLoader { // needed for delta index updates. struct CacheManager { struct Entry { - std::unique_ptr file; - std::unique_ptr ids; + std::shared_ptr file; + std::shared_ptr ids; - Entry(std::unique_ptr file, std::unique_ptr ids) + Entry(std::shared_ptr file, std::shared_ptr ids) : file(std::move(file)), ids(std::move(ids)) {} }; @@ -833,10 +833,10 @@ struct CacheManager { return nullptr; } - std::unique_ptr UpdateAndReturnOldFile(std::unique_ptr entry) { + std::shared_ptr UpdateAndReturnOldFile(std::shared_ptr entry) { const auto it = files_.find(entry->file->path); if (it != files_.end()) { - std::unique_ptr old = std::move(it->second); + std::shared_ptr old = std::move(it->second); files_[entry->file->path] = std::move(entry); return old; } @@ -846,7 +846,7 @@ struct CacheManager { } Config* config_; - std::unordered_map> files_; + std::unordered_map> files_; }; struct IndexManager { @@ -913,8 +913,8 @@ bool IndexMain_DoCreateIndexUpdate( return false; Timer time; - IndexUpdate update = IndexUpdate::CreateDelta(response->previous_id_map.get(), response->current_id_map, - response->previous_index.get(), response->current_index); + IndexUpdate update = IndexUpdate::CreateDelta(response->previous_id_map.get(), response->current_id_map.get(), + response->previous_index.get(), response->current_index.get()); response->perf.index_make_delta = time.ElapsedMicrosecondsAndReset(); #if false @@ -949,6 +949,7 @@ bool IndexMain_DoCreateIndexUpdate( } bool IndexMergeIndexUpdates(Index_OnIndexedQueue* queue_on_indexed) { + // TODO/FIXME: it looks like there is a crash here? optional root = queue_on_indexed->TryDequeue(); if (!root) return false; @@ -2869,14 +2870,14 @@ bool QueryDbMainLoop( Timer time; assert(request->current); - std::unique_ptr previous; - CacheManager::Entry* current = nullptr; + std::shared_ptr previous; + std::shared_ptr current; { - auto id_map = MakeUnique(db, request->current->id_cache); - std::unique_ptr current0 = - MakeUnique(std::move(request->current), + auto id_map = std::make_shared(db, request->current->id_cache); + std::shared_ptr current0 = + std::make_shared(std::move(request->current), std::move(id_map)); - current = current0.get(); + current = current0; previous = db_cache->UpdateAndReturnOldFile(std::move(current0)); } @@ -2884,8 +2885,8 @@ bool QueryDbMainLoop( response.previous_id_map = std::move(previous->ids); response.previous_index = std::move(previous->file); } - response.current_id_map = current->ids.get(); - response.current_index = current->file.get(); + response.current_id_map = current->ids; + response.current_index = current->file; response.perf.querydb_id_map = time.ElapsedMicrosecondsAndReset(); queue_on_id_mapped->Enqueue(std::move(response)); diff --git a/src/performance.h b/src/performance.h index 46fcc731..201e0ed8 100644 --- a/src/performance.h +++ b/src/performance.h @@ -2,26 +2,28 @@ #include "serializer.h" +#include + // Contains timing information for the entire pipeline for importing a file // into the querydb. struct PerformanceImportFile { // All units are in microseconds. // [indexer] clang parsing the file - long long index_parse = 0; + uint64_t index_parse = 0; // [indexer] build the IndexFile object from clang parse - long long index_build = 0; + uint64_t index_build = 0; // [querydb] create IdMap object from IndexFile - long long querydb_id_map = 0; + uint64_t querydb_id_map = 0; // [indexer] save the IndexFile to disk - long long index_save_to_disk = 0; + uint64_t index_save_to_disk = 0; // [indexer] loading previously cached index - long long index_load_cached = 0; + uint64_t index_load_cached = 0; // [indexer] create delta IndexUpdate object - long long index_make_delta = 0; + uint64_t index_make_delta = 0; // [querydb] update WorkingFile indexed file state - //long long querydb_update_working_file = 0; + //uint64_t querydb_update_working_file = 0; // [querydb] apply IndexUpdate - //long long querydb_apply_index_update = 0; + //uint64_t querydb_apply_index_update = 0; }; MAKE_REFLECT_STRUCT(PerformanceImportFile, index_parse, index_build, querydb_id_map, index_save_to_disk, index_load_cached, index_make_delta); \ No newline at end of file diff --git a/src/serializer.cc b/src/serializer.cc index 814591ea..5c361e8b 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -34,13 +34,6 @@ void Reflect(Reader& visitor, uint64_t& value) { void Reflect(Writer& visitor, uint64_t& value) { visitor.Uint64(value); } -// long long -void Reflect(Reader& visitor, long long& value) { - value = visitor.GetUint64(); -} -void Reflect(Writer& visitor, long long& value) { - visitor.Uint64(value); -} // bool void Reflect(Reader& visitor, bool& value) { value = visitor.GetBool(); diff --git a/src/serializer.h b/src/serializer.h index 1f57cf9d..79c2f68e 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -121,9 +121,6 @@ void Reflect(Writer& visitor, int64_t& value); // uint64_t void Reflect(Reader& visitor, uint64_t& value); void Reflect(Writer& visitor, uint64_t& value); -// long long -void Reflect(Reader& visitor, long long& value); -void Reflect(Writer& visitor, long long& value); // bool void Reflect(Reader& visitor, bool& value); void Reflect(Writer& visitor, bool& value);