1.1 --- a/memory.cc Sat Mar 20 01:40:39 2021 +0100
1.2 +++ b/memory.cc Sat Mar 20 01:41:43 2021 +0100
1.3 @@ -5,16 +5,9 @@
1.4
1.5 /* Initialise the memory pool with an optional 'limit' in pages. */
1.6
1.7 -Memory::Memory(unsigned int limit, offset_t region_size)
1.8 -: _limit(limit), _region_size(region_size)
1.9 +Memory::Memory(offset_t region_size)
1.10 +: _region_size(region_size)
1.11 {
1.12 - _limited = true;
1.13 -}
1.14 -
1.15 -Memory::Memory()
1.16 -: _region_size(PAGE_SIZE)
1.17 -{
1.18 - _limited = false;
1.19 }
1.20
1.21 /* Allocate a block of the given 'size'. */
1.22 @@ -35,56 +28,4 @@
1.23 return new Region((offset_t) current, (offset_t) current + size);
1.24 }
1.25
1.26 -/* Allocate a new region of the given 'size' rounded to the nearest page. */
1.27 -
1.28 -Region *Memory::region(offset_t size)
1.29 -{
1.30 - std::lock_guard<std::mutex> guard(_lock);
1.31 -
1.32 - offset_t rounded = round(size, PAGE_SIZE);
1.33 - offset_t pages = rounded / PAGE_SIZE;
1.34 -
1.35 - /* Check for sufficient pages. */
1.36 -
1.37 - if (!_limited || (_limit >= pages))
1.38 - {
1.39 - /* Attempt to allocate aligned memory. */
1.40 -
1.41 - Region *region = allocate(rounded);
1.42 -
1.43 - if (region == NULL)
1.44 - return NULL;
1.45 -
1.46 - if (_limited)
1.47 - _limit -= pages;
1.48 -
1.49 - return region;
1.50 - }
1.51 -
1.52 - /* Return no region without sufficient pages. */
1.53 -
1.54 - else
1.55 - return NULL;
1.56 -}
1.57 -
1.58 -Region *Memory::region()
1.59 -{
1.60 - return region(_region_size);
1.61 -}
1.62 -
1.63 -/* Release the allocated 'region'. */
1.64 -
1.65 -void Memory::release(Region *region)
1.66 -{
1.67 - std::lock_guard<std::mutex> guard(_lock);
1.68 -
1.69 - offset_t rounded = round(region->size(), PAGE_SIZE);
1.70 - offset_t pages = rounded / PAGE_SIZE;
1.71 -
1.72 - if (_limited)
1.73 - _limit += pages;
1.74 -
1.75 - delete region;
1.76 -}
1.77 -
1.78 // vim: tabstop=4 expandtab shiftwidth=4