Rev | Line | |
---|
[176] | 1 | /* -*- C++ -*- */ |
---|
| 2 | |
---|
| 3 | #ifndef _PADHEAP_H_ |
---|
| 4 | #define _PADHEAP_H_ |
---|
| 5 | |
---|
| 6 | #include <assert.h> |
---|
| 7 | |
---|
| 8 | // Pad object size requests. |
---|
| 9 | |
---|
| 10 | template <int CacheLineSize, class SuperHeap> |
---|
| 11 | class PadHeap : public SuperHeap { |
---|
| 12 | public: |
---|
| 13 | |
---|
| 14 | inline void * malloc (size_t sz) { |
---|
| 15 | return SuperHeap::malloc (roundup(sz)); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | private: |
---|
| 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.