Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: platforms/stm/disco_fletch/src/page_allocator.cc

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: platforms/stm/disco_fletch/src/page_allocator.cc
diff --git a/platforms/stm/disco_fletch/src/page_allocator.cc b/platforms/stm/disco_fletch/src/page_allocator.cc
deleted file mode 100644
index 81ed4c59a583f410fa21290805e4c7d2e271df28..0000000000000000000000000000000000000000
--- a/platforms/stm/disco_fletch/src/page_allocator.cc
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright (c) 2016, the Dartino project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE.md file.
-
-#include "platforms/stm/disco_fletch/src/page_allocator.h"
-
-#include "src/shared/assert.h"
-
-uint32_t PageAllocator::AddArena(const char* name, uintptr_t start,
- size_t size, uint8_t* map, size_t map_size) {
- for (int i = 0; i < kMaxArenas; i++) {
- if (arenas_[i].IsFree()) {
- arenas_[i].Initialize(name, start, size, map, map_size);
- return 1 << i;
- }
- }
- FATAL("Too many arenas added");
- return 0;
-}
-
-void* PageAllocator::AllocatePages(size_t pages, uint32_t arenas_bitmap) {
- for (int i = 0; i < kMaxArenas; i++) {
- if ((arenas_bitmap & (1 << i)) != 0) {
- void* result = arenas_[i].AllocatePages(pages);
- if (result != NULL) return result;
- }
- }
- return NULL;
-}
-
-void PageAllocator::FreePages(void* start, size_t pages) {
- ASSERT(IS_PAGE_ALIGNED(start));
- for (int i = 0; i < kMaxArenas; i++) {
- if (arenas_[i].ContainsPageAt(start)) {
- arenas_[i].FreePages(start, pages);
- return;
- }
- }
- FATAL("Free of unallocated pages");
-}
-
-void PageAllocator::Arena::Initialize(const char* name, uintptr_t arena_start,
- size_t arena_size,
- uint8_t* map, size_t map_size) {
- uintptr_t start = ROUNDUP(arena_start, PAGE_SIZE);
- size_t size = ROUNDDOWN(arena_start + arena_size, PAGE_SIZE) - start;
- ASSERT(IS_PAGE_ALIGNED(start));
- ASSERT(IS_PAGE_ALIGNED(size));
- name_ = name;
- pages_ = size >> PAGE_SIZE_SHIFT;
-
- if (map != NULL && map_size >= pages_) {
- // There is a supplied map that can hold the state of all the pages.
- map_ = map;
- base_ = reinterpret_cast<uint8_t*>(start);
- } else {
- // Allocate a map with one byte per page from the beginning of the arena.
- map_ = reinterpret_cast<uint8_t*>(start);
- pages_ -= ROUNDUP(pages_, PAGE_SIZE) / PAGE_SIZE;
- base_ = reinterpret_cast<uint8_t*>(PAGE_ALIGN(start + pages_));
- }
- memset(map_, 0, pages_);
-}
-
-void* PageAllocator::Arena::AllocatePages(size_t pages) {
- if (pages == 0 || pages > pages_) return NULL;
- for (size_t i = 0; i < pages_ - pages + 1; i++) {
- bool found = true;
- for (size_t j = 0; j < pages; j++) {
- if (map_[i + j] != 0) {
- i += j;
- found = false;
- break;
- }
- }
- if (found) {
- memset(map_ + i, 1, pages);
- return base_ + (i << PAGE_SIZE_SHIFT); // i * PAGE_SIZE.
- }
- }
- return NULL;
-}
-
-void PageAllocator::Arena::FreePages(void* start, size_t pages) {
- size_t index = (reinterpret_cast<uint8_t*>(start) - base_) >> PAGE_SIZE_SHIFT;
- for (int i = 0; i < pages; i++) {
- ASSERT(map_[index + i] != 0);
- map_[index + i] = 0;
- }
-}
« no previous file with comments | « platforms/stm/disco_fletch/src/page_allocator.h ('k') | platforms/stm/disco_fletch/src/page_allocator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698