Remove memtables from HandleSys (bug 5899 part 5, r=fyren).
This commit is contained in:
		
							parent
							
								
									b917c540aa
								
							
						
					
					
						commit
						2dae228f10
					
				@ -59,8 +59,6 @@ HandleSystem::HandleSystem()
 | 
				
			|||||||
	m_Types = new QHandleType[HANDLESYS_TYPEARRAY_SIZE];
 | 
						m_Types = new QHandleType[HANDLESYS_TYPEARRAY_SIZE];
 | 
				
			||||||
	memset(m_Types, 0, sizeof(QHandleType) * HANDLESYS_TYPEARRAY_SIZE);
 | 
						memset(m_Types, 0, sizeof(QHandleType) * HANDLESYS_TYPEARRAY_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m_strtab = new BaseStringTable(512);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	m_TypeTail = 0;
 | 
						m_TypeTail = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -68,7 +66,6 @@ HandleSystem::~HandleSystem()
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	delete [] m_Handles;
 | 
						delete [] m_Handles;
 | 
				
			||||||
	delete [] m_Types;
 | 
						delete [] m_Types;
 | 
				
			||||||
	delete m_strtab;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -142,12 +139,10 @@ HandleType_t HandleSystem::CreateType(const char *name,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (name && name[0] != '\0')
 | 
						if (name && name[0] != '\0')
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (m_TypeLookup.retrieve(name))
 | 
							if (m_TypeLookup.contains(name))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (err)
 | 
								if (err)
 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				*err = HandleError_Parameter;
 | 
									*err = HandleError_Parameter;
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -209,10 +204,10 @@ HandleType_t HandleSystem::CreateType(const char *name,
 | 
				
			|||||||
	pType->dispatch = dispatch;
 | 
						pType->dispatch = dispatch;
 | 
				
			||||||
	if (name && name[0] != '\0')
 | 
						if (name && name[0] != '\0')
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		pType->nameIdx = m_strtab->AddString(name);
 | 
							pType->name = name;
 | 
				
			||||||
		m_TypeLookup.insert(name, pType);
 | 
							m_TypeLookup.insert(name, pType);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		pType->nameIdx = -1;
 | 
							pType->name.setVoid();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pType->opened = 0;
 | 
						pType->opened = 0;
 | 
				
			||||||
@ -930,13 +925,8 @@ bool HandleSystem::RemoveType(HandleType_t type, IdentityToken_t *ident)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Remove it from the type cache. */
 | 
						/* Remove it from the type cache. */
 | 
				
			||||||
	if (pType->nameIdx != -1)
 | 
						if (!pType->name.isVoid())
 | 
				
			||||||
	{
 | 
							m_TypeLookup.remove(pType->name.chars());
 | 
				
			||||||
		const char *typeName;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		typeName = m_strtab->GetString(pType->nameIdx);
 | 
					 | 
				
			||||||
		m_TypeLookup.remove(typeName);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1061,14 +1051,10 @@ bool HandleSystem::TryAndFreeSomeHandles()
 | 
				
			|||||||
			continue; /* We may have gaps, it's fine. */
 | 
								continue; /* We may have gaps, it's fine. */
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (m_Types[i].nameIdx != -1)
 | 
							if (!m_Types[i].name.isVoid())
 | 
				
			||||||
		{
 | 
								pTypeName = m_Types[i].name.chars();
 | 
				
			||||||
			pTypeName = m_strtab->GetString(m_Types[i].nameIdx);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			pTypeName = "ANON";
 | 
								pTypeName = "ANON";
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		HANDLE_LOG_VERY_BAD("Type\t%-20.20s|\tCount\t%u", pTypeName, pCount[i]);
 | 
							HANDLE_LOG_VERY_BAD("Type\t%-20.20s|\tCount\t%u", pTypeName, pCount[i]);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -1133,10 +1119,8 @@ void HandleSystem::Dump(HANDLE_REPORTER rep)
 | 
				
			|||||||
		unsigned int size = 0;
 | 
							unsigned int size = 0;
 | 
				
			||||||
		unsigned int parentIdx;
 | 
							unsigned int parentIdx;
 | 
				
			||||||
		bool bresult;
 | 
							bool bresult;
 | 
				
			||||||
		if (pType->nameIdx != -1)
 | 
							if (!pType->name.isVoid())
 | 
				
			||||||
		{
 | 
								type = pType->name.chars();
 | 
				
			||||||
			type = m_strtab->GetString(pType->nameIdx);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ((parentIdx = m_Handles[i].clone) != 0)
 | 
							if ((parentIdx = m_Handles[i].clone) != 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
				
			|||||||
@ -34,8 +34,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <IHandleSys.h>
 | 
					#include <IHandleSys.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <sm_stringhashmap.h>
 | 
					#include <sm_namehashset.h>
 | 
				
			||||||
#include "sm_memtable.h"
 | 
					#include <am-string.h>
 | 
				
			||||||
#include "common_logic.h"
 | 
					#include "common_logic.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define HANDLESYS_MAX_HANDLES		(1<<14)
 | 
					#define HANDLESYS_MAX_HANDLES		(1<<14)
 | 
				
			||||||
@ -103,7 +103,12 @@ struct QHandleType
 | 
				
			|||||||
	TypeAccess typeSec;
 | 
						TypeAccess typeSec;
 | 
				
			||||||
	HandleAccess hndlSec;
 | 
						HandleAccess hndlSec;
 | 
				
			||||||
	unsigned int opened;
 | 
						unsigned int opened;
 | 
				
			||||||
	int nameIdx;
 | 
						ke::AString name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static inline bool matches(const char *key, const QHandleType *type)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							return type->name.compare(key) == 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef void (HANDLE_REPORTER)(const char *str, ...);
 | 
					typedef void (HANDLE_REPORTER)(const char *str, ...);
 | 
				
			||||||
@ -216,13 +221,12 @@ protected:
 | 
				
			|||||||
private:
 | 
					private:
 | 
				
			||||||
	QHandle *m_Handles;
 | 
						QHandle *m_Handles;
 | 
				
			||||||
	QHandleType *m_Types;
 | 
						QHandleType *m_Types;
 | 
				
			||||||
	StringHashMap<QHandleType *> m_TypeLookup;
 | 
						NameHashSet<QHandleType *> m_TypeLookup;
 | 
				
			||||||
	unsigned int m_TypeTail;
 | 
						unsigned int m_TypeTail;
 | 
				
			||||||
	unsigned int m_FreeTypes;
 | 
						unsigned int m_FreeTypes;
 | 
				
			||||||
	unsigned int m_HandleTail;
 | 
						unsigned int m_HandleTail;
 | 
				
			||||||
	unsigned int m_FreeHandles;
 | 
						unsigned int m_FreeHandles;
 | 
				
			||||||
	unsigned int m_HSerial;
 | 
						unsigned int m_HSerial;
 | 
				
			||||||
	BaseStringTable *m_strtab;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern HandleSystem g_HandleSys;
 | 
					extern HandleSystem g_HandleSys;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user