"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/include/hoard/heapmanager.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).

heapmanager.h  (Hoard-3.12):heapmanager.h  (Hoard-3.13)
skipping to change at line 32 skipping to change at line 32
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef HOARD_HEAPMANAGER_H #ifndef HOARD_HEAPMANAGER_H
#define HOARD_HEAPMANAGER_H #define HOARD_HEAPMANAGER_H
#include <cstdlib> #include <cstdlib>
#include <mutex>
#include "hoardconstants.h" #include "hoardconstants.h"
#include "heaplayers.h" #include "heaplayers.h"
namespace Hoard { namespace Hoard {
template <typename LockType, template <typename LockType,
typename HeapType> typename HeapType>
class HeapManager : public HeapType { class HeapManager : public HeapType {
public: public:
enum { Alignment = HeapType::Alignment }; enum { Alignment = HeapType::Alignment };
HeapManager() HeapManager()
{ {
HL::Guard<LockType> g (heapLock); std::lock_guard<LockType> g (heapLock);
/// Initialize all heap maps (nothing yet assigned). /// Initialize all heap maps (nothing yet assigned).
for (auto i = 0; i < HeapType::MaxThreads; i++) { for (auto i = 0; i < HeapType::MaxThreads; i++) {
HeapType::setTidMap (i, 0); HeapType::setTidMap (i, 0);
} }
for (auto i = 0; i < HeapType::MaxHeaps; i++) { for (auto i = 0; i < HeapType::MaxHeaps; i++) {
HeapType::setInusemap (i, 0); HeapType::setInusemap (i, 0);
} }
} }
/// Set this thread's heap id to 0. /// Set this thread's heap id to 0.
void chooseZero() { void chooseZero() {
HL::Guard<LockType> g (heapLock); std::lock_guard<LockType> g (heapLock);
HeapType::setTidMap (HL::CPUInfo::getThreadId() % Hoard::MaxThreads, 0); HeapType::setTidMap (HL::CPUInfo::getThreadId() % Hoard::MaxThreads, 0);
} }
int findUnusedHeap() { int findUnusedHeap() {
HL::Guard<LockType> g (heapLock); std::lock_guard<LockType> g (heapLock);
auto tid_original = HL::CPUInfo::getThreadId(); auto tid_original = HL::CPUInfo::getThreadId();
auto tid = tid_original % HeapType::MaxThreads; auto tid = tid_original % HeapType::MaxThreads;
int i = 0; int i = 0;
while ((i < HeapType::MaxHeaps) && (HeapType::getInusemap(i))) while ((i < HeapType::MaxHeaps) && (HeapType::getInusemap(i)))
i++; i++;
if (i >= HeapType::MaxHeaps) { if (i >= HeapType::MaxHeaps) {
// Every heap is in use: pick a random heap. // Every heap is in use: pick a random heap.
#if defined(_WIN32) #if defined(_WIN32)
skipping to change at line 93 skipping to change at line 94
HeapType::setInusemap (i, 1); HeapType::setInusemap (i, 1);
HeapType::setTidMap ((int) tid, i); HeapType::setTidMap ((int) tid, i);
return i; return i;
} }
void releaseHeap() { void releaseHeap() {
// Decrement the ref-count on the current heap. // Decrement the ref-count on the current heap.
HL::Guard<LockType> g (heapLock); std::lock_guard<LockType> g (heapLock);
// Statically ensure that the number of threads is a power of two. // Statically ensure that the number of threads is a power of two.
enum { VerifyPowerOfTwo = 1 / ((HeapType::MaxThreads & ~(HeapType::MaxThre ads-1))) }; enum { VerifyPowerOfTwo = 1 / ((HeapType::MaxThreads & ~(HeapType::MaxThre ads-1))) };
auto tid = (int) (HL::CPUInfo::getThreadId() & (HeapType::MaxThreads - 1)) ; auto tid = (int) (HL::CPUInfo::getThreadId() & (HeapType::MaxThreads - 1)) ;
auto heapIndex = HeapType::getTidMap (tid); auto heapIndex = HeapType::getTidMap (tid);
HeapType::setInusemap (heapIndex, 0); HeapType::setInusemap (heapIndex, 0);
// Prevent underruns (defensive programming). // Prevent underruns (defensive programming).
 End of changes. 5 change blocks. 
4 lines changed or deleted 5 lines changed or added

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