0
0
mirror of https://github.com/yse/easy_profiler.git synced 2025-01-14 00:27:55 +08:00

More correct version of reader interruption

This commit is contained in:
Victor Zarubkin 2016-09-24 00:26:56 +03:00
parent e600c2f5cd
commit 485cec2b4f

View File

@ -296,12 +296,11 @@ extern "C" PROFILER_API::profiler::block_index_t fillTreesFromFile(::std::atomic
descriptors.push_back(descriptor);
i += sz;
progress.store(static_cast<int>(15 * i / descriptors_memory_size), ::std::memory_order_release);
auto oldprogress = progress.exchange(static_cast<int>(15 * i / descriptors_memory_size), ::std::memory_order_release);
if (oldprogress < 0)
return 0; // Loading interrupted
}
if (progress.load(::std::memory_order_acquire) < 0)
return 0; // Loading interrupted
typedef ::std::unordered_map<::profiler::thread_id_t, StatsMap, ::profiler::passthrough_hash> PerThreadStats;
PerThreadStats thread_statistics, parent_statistics, frame_statistics;
IdMap identification_table;
@ -375,14 +374,13 @@ extern "C" PROFILER_API::profiler::block_index_t fillTreesFromFile(::std::atomic
root.sync.emplace_back(block_index);
}
if (progress.load(::std::memory_order_acquire) < 0)
break; // Loading interrupted
progress.store(20 + static_cast<int>(70 * i / memory_size), ::std::memory_order_release);
auto oldprogress = progress.exchange(20 + static_cast<int>(70 * i / memory_size), ::std::memory_order_release);
if (oldprogress < 0)
return 0; // Loading interrupted
}
if (progress.load(::std::memory_order_acquire) < 0 || inFile.eof())
break; // Loading interrupted
if (inFile.eof())
break;
blocks_number_in_thread = 0;
inFile.read((char*)&blocks_number_in_thread, sizeof(decltype(blocks_number_in_thread)));
@ -519,10 +517,9 @@ extern "C" PROFILER_API::profiler::block_index_t fillTreesFromFile(::std::atomic
}
}
if (progress.load(::std::memory_order_acquire) < 0)
break; // Loading interrupted
progress.store(20 + static_cast<int>(70 * i / memory_size), ::std::memory_order_release);
auto oldprogress = progress.exchange(20 + static_cast<int>(70 * i / memory_size), ::std::memory_order_release);
if (oldprogress < 0)
return 0; // Loading interrupted
}
}