From c66e02c1f7052f3a30dcd9f02524d1571b402e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 13 Aug 2015 22:44:28 -0700 Subject: [PATCH] Added reset to HandleAlloc. --- include/bx/handlealloc.h | 44 ++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/include/bx/handlealloc.h b/include/bx/handlealloc.h index 3195f39..332fa1d 100644 --- a/include/bx/handlealloc.h +++ b/include/bx/handlealloc.h @@ -20,11 +20,7 @@ namespace bx : m_numHandles(0) , m_maxHandles(_maxHandles) { - uint16_t* dense = getDensePtr(); - for (uint16_t ii = 0; ii < _maxHandles; ++ii) - { - dense[ii] = ii; - } + reset(); } ~HandleAlloc() @@ -91,6 +87,16 @@ namespace bx dense[index] = temp; } + void reset() + { + m_numHandles = 0; + uint16_t* dense = getDensePtr(); + for (uint16_t ii = 0, num = m_maxHandles; ii < num; ++ii) + { + dense[ii] = ii; + } + } + private: HandleAlloc(); @@ -148,7 +154,7 @@ namespace bx : m_front(invalid) , m_back(invalid) { - memset(m_links, 0xff, sizeof(m_links) ); + reset(); } void pushBack(uint16_t _handle) @@ -200,22 +206,22 @@ namespace bx uint16_t getNext(uint16_t _handle) const { + BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle); const Link& curr = m_links[_handle]; - BX_CHECK(!isValid(_handle), "Invalid handle %d!", _handle); return curr.m_next; } uint16_t getPrev(uint16_t _handle) const { + BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle); const Link& curr = m_links[_handle]; - BX_CHECK(!isValid(_handle), "Invalid handle %d!", _handle); return curr.m_prev; } void remove(uint16_t _handle) { + BX_CHECK(isValid(_handle), "Invalid handle %d!", _handle); Link& curr = m_links[_handle]; - BX_CHECK(!isValid(_handle), "Invalid handle %d!", _handle); if (invalid != curr.m_prev) { @@ -241,6 +247,11 @@ namespace bx curr.m_next = invalid; } + void reset() + { + memset(m_links, 0xff, sizeof(m_links) ); + } + private: void insertBefore(int16_t _before, uint16_t _handle) { @@ -322,6 +333,15 @@ namespace bx public: static const uint16_t invalid = UINT16_MAX; + HandleAllocLruT() + { + reset(); + } + + ~HandleAllocLruT() + { + } + const uint16_t* getHandles() const { return m_alloc.getHandles(); @@ -391,6 +411,12 @@ namespace bx return m_list.getPrev(_handle); } + void reset() + { + m_list.reset(); + m_alloc.reset(); + } + private: HandleListT m_list; HandleAllocT m_alloc;