use flag to prevent multiple calls to abort_jobs even when asserts are disabled

This commit is contained in:
Steven Siloti 2019-03-25 19:49:35 -07:00 committed by Arvid Norberg
parent 8d9c746149
commit 4dc2e6015d
2 changed files with 3 additions and 2 deletions

View File

@ -578,9 +578,10 @@ namespace aux {
// indices into m_torrents to empty slots
std::vector<storage_index_t> m_free_slots;
std::atomic_flag m_jobs_aborted = ATOMIC_FLAG_INIT;
#if TORRENT_USE_ASSERTS
int m_magic = 0x1337;
std::atomic<bool> m_jobs_aborted{false};
#endif
};
}

View File

@ -3211,7 +3211,7 @@ constexpr disk_job_flags_t disk_interface::cache_hit;
void disk_io_thread::abort_jobs()
{
TORRENT_ASSERT(m_magic == 0x1337);
TORRENT_ASSERT(!m_jobs_aborted.exchange(true));
if (m_jobs_aborted.test_and_set()) return;
jobqueue_t jobs;
m_disk_cache.clear(jobs);