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: 5b8c28c205b9d0a3d23a12f26876d4a4c4030006 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "drape/pointers.hpp"
#include "base/logging.hpp"

DpPointerTracker & DpPointerTracker::Instance()
{
  static DpPointerTracker pointersTracker;
  return pointersTracker;
}

DpPointerTracker::~DpPointerTracker()
{
  ASSERT(m_alivePointers.empty(), ());
}

void DpPointerTracker::RefPtrNamed(void * refPtr, string const & name)
{
  lock_guard<mutex> lock(m_mutex);
  if (refPtr != nullptr)
  {
    auto it = m_alivePointers.find(refPtr);
    if (it != m_alivePointers.end())
      it->second.first++;
    else
      m_alivePointers.insert(make_pair(refPtr, make_pair(1, name)));
  }
}

void DpPointerTracker::DestroyPtr(void * p)
{
  lock_guard<mutex> lock(m_mutex);
  ASSERT(p != nullptr, ());
  auto it = m_alivePointers.find(p);
  if (it != m_alivePointers.end())
  {
    ASSERT(it->second.first == 0, ("Drape pointer [", it->second.second, p,
                                   "] was destroyed, but had references, ref count = ",
                                   it->second.first));
    m_alivePointers.erase(it);
  }
}

void DpPointerTracker::DerefPtr(void * p)
{
  lock_guard<mutex> lock(m_mutex);
  if (p != nullptr)
  {
    auto it = m_alivePointers.find(p);
    if (it != m_alivePointers.end())
    {
      ASSERT(it->second.first > 0, ());
      it->second.first--;
    }
  }
}

DpPointerTracker::TAlivePointers const & DpPointerTracker::GetAlivePointers() const
{
  return m_alivePointers;
}