source: proiecte/swift/trunk/lib/hoard-371/src/heaplayers/padheap.h @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 607 bytes
Line 
1/* -*- C++ -*- */
2
3#ifndef _PADHEAP_H_
4#define _PADHEAP_H_
5
6#include <assert.h>
7
8// Pad object size requests.
9
10template <int CacheLineSize, class SuperHeap>
11class PadHeap : public SuperHeap {
12public:
13
14  inline void * malloc (size_t sz) {
15    return SuperHeap::malloc (roundup(sz));
16  }
17
18private:
19
20  inline size_t roundup (size_t sz) {
21    // NB: CacheLineSize MUST be a power of two.
22        // The assertion below checks this.
23        assert ((CacheLineSize & (CacheLineSize-1)) == 0);
24    size_t roundup = (sz + CacheLineSize - 1) & ~((int) CacheLineSize-1);
25        assert (roundup >= sz);
26    return roundup;
27  }
28};
29
30#endif
Note: See TracBrowser for help on using the repository browser.