19 #ifndef NDB_OBJECT_ID_MAP_HPP
20 #define NDB_OBJECT_ID_MAP_HPP
22 #include <ndb_global.h>
25 #include <EventLogger.hpp>
36 STATIC_CONST( InvalidId = 0x7fffffff );
40 Uint32 map(
void *
object);
41 void * unmap(Uint32
id,
void *
object);
43 void * getObject(Uint32
id);
45 const Uint32 m_expandSize;
61 return (m_val & 1) == 1;
64 Uint32 getNext()
const
67 return static_cast<Uint32
>(m_val >> 1);
70 void setNext(Uint32 next)
72 m_val = (next << 1) | 1;
77 assert((m_val & 3) == 0);
78 return reinterpret_cast<void*
>(m_val);
81 void setObj(
void* obj)
83 m_val =
reinterpret_cast<UintPtr
>(obj);
84 assert((m_val & 3) == 0);
99 int expand(Uint32 newSize);
101 bool checkConsistency();
106 NdbObjectIdMap::map(
void *
object)
108 if(m_firstFree == InvalidId && expand(m_expandSize))
111 const Uint32 ff = m_firstFree;
112 m_firstFree = m_map[ff].getNext();
113 m_map[ff].setObj(
object);
115 DBUG_PRINT(
"info",(
"NdbObjectIdMap::map(0x%lx) %u", (
long)
object, ff<<2));
122 NdbObjectIdMap::unmap(Uint32
id,
void *
object)
124 const Uint32
i =
id>>2;
129 void *
const obj = m_map[
i].getObj();
132 m_map[
i].setNext(InvalidId);
133 if (m_firstFree == InvalidId)
139 m_map[m_lastFree].setNext(i);
145 g_eventLogger->
error(
"NdbObjectIdMap::unmap(%u, 0x%lx) obj=0x%lx",
146 id, (
long)
object, (
long) obj);
147 DBUG_PRINT(
"error",(
"NdbObjectIdMap::unmap(%u, 0x%lx) obj=0x%lx",
148 id, (
long)
object, (
long) obj));
153 DBUG_PRINT(
"info",(
"NdbObjectIdMap::unmap(%u) obj=0x%lx",
id, (
long) obj));
161 NdbObjectIdMap::getObject(Uint32
id)
168 if(m_map[
id].isFree())
174 return m_map[
id].getObj();