1/*
2 * Copyright 2011, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef TEAM_MEMORY_BLOCK_MANAGER_H
6#define TEAM_MEMORY_BLOCK_MANAGER_H
7
8
9#include <Locker.h>
10#include <Referenceable.h>
11#include <util/DoublyLinkedList.h>
12#include <util/OpenHashTable.h>
13
14#include "Types.h"
15
16
17struct MemoryBlockHashDefinition;
18class TeamMemoryBlock;
19
20
21class TeamMemoryBlockManager
22{
23public:
24								TeamMemoryBlockManager();
25								~TeamMemoryBlockManager();
26
27		status_t				Init();
28
29		TeamMemoryBlock*		GetMemoryBlock(target_addr_t address);
30
31private:
32		struct Key;
33		struct MemoryBlockEntry;
34		struct MemoryBlockHashDefinition;
35		typedef BOpenHashTable<MemoryBlockHashDefinition> MemoryBlockTable;
36		typedef DoublyLinkedList<TeamMemoryBlock> DeadBlockTable;
37
38private:
39		void					_Cleanup();
40		void					_MarkDeadBlock(target_addr_t address);
41		void					_RemoveBlock(target_addr_t address);
42
43private:
44		friend class TeamMemoryBlockOwner;
45
46private:
47		BLocker					fLock;
48		MemoryBlockTable*		fActiveBlocks;
49		DeadBlockTable*			fDeadBlocks;
50};
51
52
53class TeamMemoryBlockOwner
54{
55public:
56								TeamMemoryBlockOwner(
57									TeamMemoryBlockManager* manager);
58								~TeamMemoryBlockOwner();
59
60		void					RemoveBlock(TeamMemoryBlock* block);
61
62private:
63	TeamMemoryBlockManager* 	fBlockManager;
64};
65
66
67#endif // TEAM_MEMORY_BLOCK_MANAGER_H
68