1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#ifndef NDB_OBJECT_ID_MAP_HPP
17
#define NDB_OBJECT_ID_MAP_HPP
19
#include <ndb_global.h>
20
//#include <NdbMutex.h>
23
#include <EventLogger.hpp>
24
extern EventLogger g_eventLogger;
26
//#define DEBUG_OBJECTMAP
31
class NdbObjectIdMap //: NdbLockable
34
STATIC_CONST( InvalidId = ~(Uint32)0 );
35
NdbObjectIdMap(NdbMutex*, Uint32 initalSize = 128, Uint32 expandSize = 10);
38
Uint32 map(void * object);
39
void * unmap(Uint32 id, void *object);
41
void * getObject(Uint32 id);
52
int expand(Uint32 newSize);
57
NdbObjectIdMap::map(void * object){
61
if(m_firstFree == InvalidId && expand(m_expandSize))
64
Uint32 ff = m_firstFree;
65
m_firstFree = m_map[ff].m_next;
66
m_map[ff].m_obj = object;
70
DBUG_PRINT("info",("NdbObjectIdMap::map(0x%lx) %u", (long) object, ff<<2));
77
NdbObjectIdMap::unmap(Uint32 id, void *object){
83
void * obj = m_map[i].m_obj;
85
m_map[i].m_next = m_firstFree;
88
g_eventLogger.error("NdbObjectIdMap::unmap(%u, 0x%x) obj=0x%x",
89
id, (long) object, (long) obj);
90
DBUG_PRINT("error",("NdbObjectIdMap::unmap(%u, 0x%lx) obj=0x%lx",
91
id, (long) object, (long) obj));
97
DBUG_PRINT("info",("NdbObjectIdMap::unmap(%u) obj=0x%lx", id, (long) obj));
105
NdbObjectIdMap::getObject(Uint32 id){
106
// DBUG_PRINT("info",("NdbObjectIdMap::getObject(%u) obj=0x%x", id, m_map[id>>2].m_obj));
109
return m_map[id].m_obj;