| 140 | |
| 141 | |
| 142 | void* FrameAllocator::Allocate(uint16_t size) |
| 143 | { |
| 144 | auto realSize = (uint16_t)(size + 63) & 0xFFC0u; |
| 145 | |
| 146 | auto curPage = CurrentPage; |
| 147 | auto offset = (uint64_t)InterlockedExchangeAdd64(&curPage->Offset, realSize); |
| 148 | while (offset + realSize > PageSize) { |
| 149 | |
| 150 | EnterCriticalSection(&CS); |
| 151 | if (curPage == CurrentPage) { |
| 152 | auto page = AllocPage(); |
| 153 | page->Offset = 0x40; |
| 154 | CurrentPage = page; |
| 155 | } |
| 156 | LeaveCriticalSection(&CS); |
| 157 | |
| 158 | curPage = CurrentPage; |
| 159 | offset = (uint64_t)InterlockedExchangeAdd64(&curPage->Offset, realSize); |
| 160 | } |
| 161 | |
| 162 | return (uint8_t*)curPage + offset; |
| 163 | } |
| 164 | |
| 165 | FrameAllocator::FrameBuffer* FrameAllocator::AllocPage() |
| 166 | { |
no test coverage detected