debug invariant checks for DHT observer allocator
This commit is contained in:
parent
360c6a6e16
commit
b6eb5d7476
|
@ -82,10 +82,12 @@ struct observer : boost::noncopyable
|
||||||
m_in_constructor = true;
|
m_in_constructor = true;
|
||||||
m_was_sent = false;
|
m_was_sent = false;
|
||||||
m_was_abandoned = false;
|
m_was_abandoned = false;
|
||||||
|
m_in_use = true;
|
||||||
#endif
|
#endif
|
||||||
set_target(ep);
|
set_target(ep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// defined in rpc_manager.cpp
|
||||||
virtual ~observer();
|
virtual ~observer();
|
||||||
|
|
||||||
// this is called when a reply is received
|
// this is called when a reply is received
|
||||||
|
@ -167,6 +169,7 @@ public:
|
||||||
bool m_in_constructor:1;
|
bool m_in_constructor:1;
|
||||||
bool m_was_sent:1;
|
bool m_was_sent:1;
|
||||||
bool m_was_abandoned:1;
|
bool m_was_abandoned:1;
|
||||||
|
bool m_in_use:1;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,11 @@ void* rpc_manager::allocate_observer()
|
||||||
{
|
{
|
||||||
m_pool_allocator.set_next_size(10);
|
m_pool_allocator.set_next_size(10);
|
||||||
void* ret = m_pool_allocator.malloc();
|
void* ret = m_pool_allocator.malloc();
|
||||||
if (ret) ++m_allocated_observers;
|
if (ret)
|
||||||
|
{
|
||||||
|
++m_allocated_observers;
|
||||||
|
TORRENT_ASSERT(reinterpret_cast<observer*>(ret)->m_in_use == false);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,6 +228,7 @@ void rpc_manager::free_observer(void* ptr)
|
||||||
{
|
{
|
||||||
if (!ptr) return;
|
if (!ptr) return;
|
||||||
--m_allocated_observers;
|
--m_allocated_observers;
|
||||||
|
TORRENT_ASSERT(reinterpret_cast<observer*>(ptr)->m_in_use == true);
|
||||||
m_pool_allocator.free(ptr);
|
m_pool_allocator.free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,6 +507,10 @@ observer::~observer()
|
||||||
// reported back
|
// reported back
|
||||||
TORRENT_ASSERT(m_was_sent == bool(flags & flag_done) || m_was_abandoned);
|
TORRENT_ASSERT(m_was_sent == bool(flags & flag_done) || m_was_abandoned);
|
||||||
TORRENT_ASSERT(!m_in_constructor);
|
TORRENT_ASSERT(!m_in_constructor);
|
||||||
|
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
||||||
|
TORRENT_ASSERT(m_in_use);
|
||||||
|
m_in_use = false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} } // namespace libtorrent::dht
|
} } // namespace libtorrent::dht
|
||||||
|
|
Loading…
Reference in New Issue