1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5
6
7#ifndef __objectlist_h__
8#define __objectlist_h__
9
10
11#include "arraylist.h"
12#include "holder.h"
13
14#define INVALID_COMPRESSEDSTACK_INDEX ((DWORD)-1)
15#ifdef _DEBUG
16#define FREE_LIST_SIZE 128
17#else
18#define FREE_LIST_SIZE 1024
19#endif
20
21
22
23class ObjectList
24{
25public:
26 class Iterator
27 {
28 friend class ObjectList;
29
30 protected:
31 ArrayList::Iterator _iter;
32
33 public:
34
35 PTR_VOID GetElement()
36 {
37 LIMITED_METHOD_CONTRACT;
38 PTR_VOID ptr = _iter.GetElement();
39 if (((DWORD)(size_t)(dac_cast<TADDR>(ptr)) & 0x1) == 0)
40 {
41 return ptr;
42 }
43 else
44 {
45 return NULL;
46 }
47 }
48
49 DWORD GetIndex()
50 {
51 LIMITED_METHOD_CONTRACT;
52 return _iter.GetIndex();
53 }
54
55 BOOL Next()
56 {
57 LIMITED_METHOD_CONTRACT;
58 return _iter.Next();
59 }
60 };
61
62 ObjectList() DAC_EMPTY();
63
64 DWORD AddToList( PVOID ptr );
65 void RemoveFromList( PVOID ptr );
66 void RemoveFromList( DWORD index, PVOID ptr );
67 PVOID Get( DWORD index );
68
69 ObjectList::Iterator Iterate()
70 {
71 LIMITED_METHOD_CONTRACT;
72 ObjectList::Iterator i;
73 i._iter = this->allEntries_.Iterate();
74 return i;
75 }
76
77private:
78 ArrayList allEntries_;
79 DWORD freeIndexHead_;
80 Crst listLock_;
81};
82
83class UnsynchronizedBlockAllocator
84{
85public:
86 UnsynchronizedBlockAllocator( size_t blockSize );
87 ~UnsynchronizedBlockAllocator( void );
88
89 PVOID Allocate( size_t size );
90
91private:
92 ArrayList blockList_;
93
94 size_t blockSize_;
95 size_t offset_;
96 DWORD index_;
97
98};
99
100#endif // __objectlist_h__
101