Revert "Use atomic<bool> primitive for thread's shared flags."

This reverts commit 39c4f2f1dc31435e12b10a051d410ec02a1ad72b.
This commit is contained in:
vng 2012-09-11 17:16:28 +03:00 committed by Alex Zolotarev
parent cd68512942
commit 3c934528be
4 changed files with 18 additions and 20 deletions

View file

@ -186,26 +186,26 @@ void Engine::SetViewportAsync(m2::RectD const & viewport, m2::RectD const & near
void Engine::SearchAsync()
{
// Avoid many threads waiting in search mutex. One is enough.
bool expected = false;
if (!m_readyThread.compare_exchange_strong(expected, true))
{
ASSERT ( expected, () );
return;
// Avoid many threads waiting in search mutex. One is enough.
threads::MutexGuard readyGuard(m_readyMutex);
if (m_readyThread)
return;
m_readyThread = true;
}
// Order of next 4 operations is very important!
// 1. Cancel previous query.
// First of all - cancel previous query.
m_pQuery->DoCancel();
// 2. Enter to run new search.
// Enter to run new search.
threads::MutexGuard searchGuard(m_searchMutex);
// 3. Free flag for the next search thread.
m_readyThread.store(false);
{
threads::MutexGuard readyGuard(m_readyMutex);
m_readyThread = false;
}
// 4. Get current search params.
// Get current search params.
SearchParams params;
m2::RectD arrRects[2];

View file

@ -11,7 +11,6 @@
#include "../std/scoped_ptr.hpp"
#include "../std/string.hpp"
#include "../std/function.hpp"
#include "../std/atomic.hpp"
class Index;
@ -62,8 +61,9 @@ private:
void SetViewportAsync(m2::RectD const & viewport, m2::RectD const & nearby);
void SearchAsync();
threads::Mutex m_searchMutex, m_updateMutex;
volatile atomic<bool> m_readyThread;
threads::Mutex m_searchMutex, m_updateMutex, m_readyMutex;
volatile bool m_readyThread;
SearchParams m_params;
m2::RectD m_viewport;

View file

@ -1336,10 +1336,9 @@ namespace
{
vector<uint32_t> const * m_offsets;
volatile atomic<bool> const & m_isCancelled;
volatile bool & m_isCancelled;
public:
FeaturesFilter(vector<uint32_t> const * offsets,
volatile atomic<bool> const & isCancelled)
FeaturesFilter(vector<uint32_t> const * offsets, volatile bool & isCancelled)
: m_offsets(offsets), m_isCancelled(isCancelled)
{
}

View file

@ -16,7 +16,6 @@
#include "../std/string.hpp"
#include "../std/unordered_set.hpp"
#include "../std/vector.hpp"
#include "../std/atomic.hpp"
class FeatureType;
@ -164,7 +163,7 @@ private:
StringsToSuggestVectorT const * m_pStringsToSuggest;
storage::CountryInfoGetter const * m_pInfoGetter;
volatile atomic<bool> m_cancel;
volatile bool m_cancel;
buffer_vector<strings::UniString, 32> m_tokens;
strings::UniString m_prefix;