xref: /haiku/src/kits/debugger/debug_managers/TeamMemoryBlockManager.h (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
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 
17 struct MemoryBlockHashDefinition;
18 class TeamMemoryBlock;
19 
20 
21 class TeamMemoryBlockManager
22 {
23 public:
24 								TeamMemoryBlockManager();
25 								~TeamMemoryBlockManager();
26 
27 		status_t				Init();
28 
29 		TeamMemoryBlock*		GetMemoryBlock(target_addr_t address);
30 
31 private:
32 		struct Key;
33 		struct MemoryBlockEntry;
34 		struct MemoryBlockHashDefinition;
35 		typedef BOpenHashTable<MemoryBlockHashDefinition> MemoryBlockTable;
36 		typedef DoublyLinkedList<TeamMemoryBlock> DeadBlockTable;
37 
38 private:
39 		void					_Cleanup();
40 		void					_MarkDeadBlock(target_addr_t address);
41 		void					_RemoveBlock(target_addr_t address);
42 
43 private:
44 		friend class TeamMemoryBlockOwner;
45 
46 private:
47 		BLocker					fLock;
48 		MemoryBlockTable*		fActiveBlocks;
49 		DeadBlockTable*			fDeadBlocks;
50 };
51 
52 
53 class TeamMemoryBlockOwner
54 {
55 public:
56 								TeamMemoryBlockOwner(
57 									TeamMemoryBlockManager* manager);
58 								~TeamMemoryBlockOwner();
59 
60 		void					RemoveBlock(TeamMemoryBlock* block);
61 
62 private:
63 	TeamMemoryBlockManager* 	fBlockManager;
64 };
65 
66 
67 #endif // TEAM_MEMORY_BLOCK_MANAGER_H
68