Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pointers.cpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fef3831d88bd8c387875f2e0f6607997f946540c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "drape/pointers.hpp"

namespace dp
{

PointerTracker::~PointerTracker()
{
  ASSERT(m_countMap.empty(), ());
}

void PointerTracker::Deref(void * p)
{
  threads::MutexGuard g(m_mutex);
  if (p == NULL)
    return;

  map_t::iterator it = m_countMap.find(p);
  ASSERT(it != m_countMap.end(), ());
  ASSERT(it->second.first > 0, ());

  if (--it->second.first == 0)
  {
    ASSERT(m_alivePointers.find(p) == m_alivePointers.end(), ("Pointer leak for type : ", it->second.second));
    m_countMap.erase(it);
  }
}

void PointerTracker::Destroy(void * p)
{
  threads::MutexGuard g(m_mutex);
  if (p == NULL)
    return;

  map_t::iterator it = m_countMap.find(p);
  if (it == m_countMap.end()) // suppress warning in release build
    ASSERT(false, ());

  ASSERT(it->second.first == 1, ("Delete memory with more than one user : ", it->second.second));
  ASSERT(m_alivePointers.erase(p) == 1, ());
}

#if defined(CHECK_POINTERS)
  PointerTracker g_tracker;
#endif

} // namespace dp