"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/include/hoard/hoardsuperblockheader.h" between
Hoard-3.12.tar.gz and Hoard-3.13.tar.gz

About: The Hoard memory allocator is a drop-in replacement for malloc() that can improve application performance, especially for multithreaded programs running on multiprocessors (hint: newer releases now part of the HeapLayers package).

hoardsuperblockheader.h  (Hoard-3.12):hoardsuperblockheader.h  (Hoard-3.13)
// -*- C++ -*- // -*- C++ -*-
/* /*
The Hoard Multiprocessor Memory Allocator The Hoard Multiprocessor Memory Allocator
www.hoard.org www.hoard.org
Author: Emery Berger, http://www.cs.umass.edu/~emery Author: Emery Berger, http://www.emeryberger.com
Copyright (c) 1998-2012 Emery Berger Copyright (c) 1998-2018 Emery Berger
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
skipping to change at line 51 skipping to change at line 51
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable" #pragma clang diagnostic ignored "-Wunused-variable"
#endif #endif
namespace Hoard { namespace Hoard {
template <class LockType, template <class LockType,
int SuperblockSize, int SuperblockSize,
typename HeapType> typename HeapType,
template <class LockType_,
int SuperblockSize_,
typename HeapType_>
class Header_>
class HoardSuperblock; class HoardSuperblock;
template <class LockType, template <class LockType,
int SuperblockSize, int SuperblockSize,
typename HeapType> typename HeapType>
class HoardSuperblockHeader;
template <class LockType,
int SuperblockSize,
typename HeapType>
class HoardSuperblockHeaderHelper { class HoardSuperblockHeaderHelper {
public: public:
enum { Alignment = 16 }; enum { Alignment = 16 };
public: public:
typedef HoardSuperblock<LockType, SuperblockSize, HeapType, HoardSuperblockH
eader> BlockType;
HoardSuperblockHeaderHelper (size_t sz, size_t bufferSize, char * start) HoardSuperblockHeaderHelper (size_t sz, size_t bufferSize, char * start)
: _magicNumber (MAGIC_NUMBER ^ (size_t) this), : _magicNumber (MAGIC_NUMBER ^ (size_t) this),
_objectSize (sz), _objectSize (sz),
_objectSizeIsPowerOfTwo (!(sz & (sz - 1)) && sz), _objectSizeIsPowerOfTwo (!(sz & (sz - 1)) && sz),
_totalObjects ((unsigned int) (bufferSize / sz)), _totalObjects ((unsigned int) (bufferSize / sz)),
_owner (NULL), _owner (nullptr),
_prev (NULL), _prev (nullptr),
_next (NULL), _next (nullptr),
_reapableObjects (_totalObjects), _reapableObjects (_totalObjects),
_objectsFree (_totalObjects), _objectsFree (_totalObjects),
_start (start), _start (start),
_position (start) _position (start)
{ {
assert ((HL::align<Alignment>((size_t) start) == (size_t) start)); assert ((HL::align<Alignment>((size_t) start) == (size_t) start));
assert (_objectSize >= Alignment); assert (_objectSize >= Alignment);
assert ((_totalObjects == 1) || (_objectSize % Alignment == 0)); assert ((_totalObjects == 1) || (_objectSize % Alignment == 0));
} }
virtual ~HoardSuperblockHeaderHelper() { virtual ~HoardSuperblockHeaderHelper() {
clear(); clear();
} }
inline void * malloc() { inline void * malloc() {
assert (isValid()); assert (isValid());
void * ptr = reapAlloc(); void * ptr = reapAlloc();
assert ((ptr == NULL) || ((size_t) ptr % Alignment == 0)); assert ((ptr == nullptr) || ((size_t) ptr % Alignment == 0));
if (!ptr) { if (!ptr) {
ptr = freeListAlloc(); ptr = freeListAlloc();
assert ((ptr == NULL) || ((size_t) ptr % Alignment == 0)); assert ((ptr == nullptr) || ((size_t) ptr % Alignment == 0));
} }
if (ptr != NULL) { if (ptr != nullptr) {
assert (getSize(ptr) >= _objectSize); assert (getSize(ptr) >= _objectSize);
assert ((size_t) ptr % Alignment == 0); assert ((size_t) ptr % Alignment == 0);
} }
return ptr; return ptr;
} }
inline void free (void * ptr) { inline void free (void * ptr) {
assert ((size_t) ptr % Alignment == 0); assert ((size_t) ptr % Alignment == 0);
assert (isValid()); assert (isValid());
_freeList.insert (reinterpret_cast<FreeSLList::Entry *>(ptr)); _freeList.insert (reinterpret_cast<FreeSLList::Entry *>(ptr));
skipping to change at line 176 skipping to change at line 187
} }
void setOwner (HeapType * o) { void setOwner (HeapType * o) {
_owner = o; _owner = o;
} }
bool isValid() const { bool isValid() const {
return (_magicNumber == (MAGIC_NUMBER ^ (size_t) this)); return (_magicNumber == (MAGIC_NUMBER ^ (size_t) this));
} }
HoardSuperblock<LockType, SuperblockSize, HeapType> * getNext() const { BlockType * getNext() const {
return _next; return _next;
} }
HoardSuperblock<LockType, SuperblockSize, HeapType> * getPrev() const { BlockType* getPrev() const {
return _prev; return _prev;
} }
void setNext (HoardSuperblock<LockType, SuperblockSize, HeapType> * n) { void setNext (BlockType* n) {
_next = n; _next = n;
} }
void setPrev (HoardSuperblock<LockType, SuperblockSize, HeapType> * p) { void setPrev (BlockType* p) {
_prev = p; _prev = p;
} }
void lock() { void lock() {
_theLock.lock(); _theLock.lock();
} }
void unlock() { void unlock() {
_theLock.unlock(); _theLock.unlock();
} }
skipping to change at line 214 skipping to change at line 225
assert (_position); assert (_position);
// Reap mode. // Reap mode.
if (_reapableObjects > 0) { if (_reapableObjects > 0) {
auto * ptr = _position; auto * ptr = _position;
_position = ptr + _objectSize; _position = ptr + _objectSize;
_reapableObjects--; _reapableObjects--;
_objectsFree--; _objectsFree--;
assert ((size_t) ptr % Alignment == 0); assert ((size_t) ptr % Alignment == 0);
return ptr; return ptr;
} else { } else {
return NULL; return nullptr;
} }
} }
MALLOC_FUNCTION INLINE void * freeListAlloc() { MALLOC_FUNCTION INLINE void * freeListAlloc() {
assert (isValid()); assert (isValid());
// Freelist mode. // Freelist mode.
auto * ptr = reinterpret_cast<char *>(_freeList.get()); auto * ptr = reinterpret_cast<char *>(_freeList.get());
if (ptr) { if (ptr) {
assert (_objectsFree >= 1); assert (_objectsFree >= 1);
_objectsFree--; _objectsFree--;
skipping to change at line 250 skipping to change at line 261
/// Total objects in the superblock. /// Total objects in the superblock.
const unsigned int _totalObjects; const unsigned int _totalObjects;
/// The lock. /// The lock.
LockType _theLock; LockType _theLock;
/// The owner of this superblock. /// The owner of this superblock.
HeapType * _owner; HeapType * _owner;
/// The preceding superblock in a linked list. /// The preceding superblock in a linked list.
HoardSuperblock<LockType, SuperblockSize, HeapType> * _prev; BlockType* _prev;
/// The succeeding superblock in a linked list. /// The succeeding superblock in a linked list.
HoardSuperblock<LockType, SuperblockSize, HeapType> * _next; BlockType* _next;
/// The number of objects available to be 'reap'ed. /// The number of objects available to be 'reap'ed.
unsigned int _reapableObjects; unsigned int _reapableObjects;
/// The number of objects available for (re)use. /// The number of objects available for (re)use.
unsigned int _objectsFree; unsigned int _objectsFree;
/// The start of reap allocation. /// The start of reap allocation.
const char * _start; const char * _start;
skipping to change at line 276 skipping to change at line 287
/// The list of freed objects. /// The list of freed objects.
FreeSLList _freeList; FreeSLList _freeList;
}; };
// A helper class that pads the header to the desired alignment. // A helper class that pads the header to the desired alignment.
template <class LockType, template <class LockType,
int SuperblockSize, int SuperblockSize,
typename HeapType> typename HeapType>
class HoardSuperblockHeader : public HoardSuperblockHeaderHelper<LockType, Sup class HoardSuperblockHeader :
erblockSize, HeapType> { public HoardSuperblockHeaderHelper<LockType, SuperblockSize, HeapType> {
public: public:
HoardSuperblockHeader (size_t sz, size_t bufferSize) HoardSuperblockHeader (size_t sz, size_t bufferSize)
: HoardSuperblockHeaderHelper<LockType,SuperblockSize,HeapType> (sz, buffe rSize, (char *) (this + 1)) : HoardSuperblockHeaderHelper<LockType,SuperblockSize,HeapType> (sz, buffe rSize, (char *) (this + 1))
{ {
sassert<((sizeof(HoardSuperblockHeader) % Parent::Alignment) == 0)> verify static_assert(sizeof(HoardSuperblockHeader) % Parent::Alignment == 0,
Size; "Superblock header size must be a multiple of the parent's al
verifySize = verifySize; ignment.");
} }
private: private:
// typedef Header_<LockType, SuperblockSize, HeapType> Header;
typedef HoardSuperblockHeaderHelper<LockType,SuperblockSize,HeapType> Parent ; typedef HoardSuperblockHeaderHelper<LockType,SuperblockSize,HeapType> Parent ;
char _dummy[Parent::Alignment - (sizeof(Parent) % Parent::Alignment)]; char _dummy[Parent::Alignment - (sizeof(Parent) % Parent::Alignment)];
}; };
} }
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif #endif
#if defined(_WIN32) #if defined(_WIN32)
 End of changes. 20 change blocks. 
22 lines changed or deleted 34 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)