Skip to content

Commit

Permalink
Changing to dlist.hh, instead of a special dlist.h
Browse files Browse the repository at this point in the history
  • Loading branch information
tongping committed Dec 17, 2019
1 parent 4340f3e commit afe29bc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 142 deletions.
12 changes: 6 additions & 6 deletions source/callstackmap.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if !defined(_HASHMAP_H)
#define _HASHMAP_H
#ifndef __HASHMAP_H__
#define __HASHMAP_H__

#define INIT_META_MAPPING 1

#include <assert.h>
#include <stddef.h>
Expand All @@ -13,6 +12,8 @@
#include "xdefines.hh"
#include "real.hh"

#define INIT_META_MAPPING 1

template <class KeyType,
class ValueType,
class LockType>
Expand Down Expand Up @@ -63,7 +64,7 @@ class HashMap {
bool _initialized;
struct HashEntry* _entries;
size_t _buckets; // How many buckets in total
size_t _bucketsUsed; // How many buckets in total
size_t _bucketsUsed; // How many buckets in use

#ifdef INIT_META_MAPPING
LockType entrylock;
Expand Down Expand Up @@ -128,7 +129,6 @@ public:
inline size_t hashIndex(const KeyType& key, size_t keylen) {
size_t hkey = _hashfunc(key, keylen);
return hkey & (_buckets-1);
//return hkey % _buckets;
}

// Look up whether an entry is existing or not.
Expand Down Expand Up @@ -215,7 +215,7 @@ public:
return isFound;
}

// Free an entry with specified
// Free an entry with specified key
bool erase(const KeyType& key, size_t keylen) {
assert(_initialized == true);
size_t hindex = hashIndex(key, keylen);
Expand Down
103 changes: 0 additions & 103 deletions source/dlist.h

This file was deleted.

15 changes: 9 additions & 6 deletions source/dlist.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ inline void listInit(list_t* node) { nodeInit(node); }
// Whether a list is empty
inline bool isListEmpty(list_t* head) { return (head->next == head); }

// Next node of current node
inline list_t* nextEntry(list_t* cur) { return cur->next; }

// Previous node of current node
inline list_t* prevEntry(list_t* cur) { return cur->prev; }

// We donot check whetehr the list is empty or not?
inline list_t* tailList(list_t* head) {
list_t* tail = NULL;
Expand Down Expand Up @@ -49,6 +43,10 @@ inline void listInsertTail(list_t* node, list_t* head) {
__insert_between(node, head->prev, head);
}

inline void listUpdateEntry(list_t * node) {
__insert_between(node, node->prev, node->next);
}

// Insert one entry to the head of specified list.
// Insert between head and head->next
inline void listInsertHead(list_t* node, list_t* head) { __insert_between(node, head, head->next); }
Expand Down Expand Up @@ -77,6 +75,11 @@ inline void listRemoveNode(list_t* node) {
nodeInit(node);
}

// Delete an entry without re-initialization.
inline void listRemoveNodeOnly(list_t* node) {
__list_link(node->prev, node->next);
}

// Check whether current node is the tail of a list
inline bool isListTail(list_t* node, list_t* head) { return (node->next == head); }

Expand Down
5 changes: 3 additions & 2 deletions source/numaheap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <new>
#include "mm.hh"
#include "xdefines.hh"
#include "dlist.h"
#include "dlist.hh"
#include "pernodeheap.hh"
#include "perthread.hh"
//#ifdef SPEC_MAINTHREAD_SUPPORT
Expand Down Expand Up @@ -110,7 +110,8 @@ public:
// is that the object is allocated in the main thread, but it is
// not freed in the same thread (before creating the threads).
bool isSharedObject() {

// TODO
return true;
}
#endif

Expand Down
42 changes: 17 additions & 25 deletions source/pernodebigobjects.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __PER_NODE_BIG_OBJECTS_HH__

#include <pthread.h>
#include "dlist.h"
#include "dlist.hh"
#include "xdefines.hh"
#include "perthread.hh"

Expand All @@ -14,7 +14,7 @@ class PerNodeBigObjects {
// the freelist that is ordered by the deallocation order.
class PerBigObject {
public:
dlist_t list;
list_t list;
void * address;
size_t size;
};
Expand All @@ -30,7 +30,7 @@ class PerNodeBigObjects {

private:
// Pointing to freed big objects
dlist_t _list;
list_t _list;

// A circular array with the maximum of 1024 objects;
// When an object is used, it will be removed from the list.
Expand Down Expand Up @@ -66,7 +66,7 @@ public:
//_nindex = ??;

// Initialize the _list and _lock
initDLList(&_list);
listInit(&_list);
pthread_spin_init(&_lock, 0);

// Initialize the _objects array
Expand Down Expand Up @@ -101,7 +101,7 @@ public:


// Now search the freelist to find an entry that satisfies the request
dlist * entry = _list.next;
list_t * entry = _list.next;

do {
PerBigObject * object = (PerBigObject *)entry;
Expand Down Expand Up @@ -140,27 +140,17 @@ public:

// Unusual case: the object size is the requested size, then we should change the freelist
if (object->size == 0) {
// Remove this entry from the list
removeDLNode(&_list, entry);

// When the current entry is not the last entry
if(entry != (dlist *)&_objects[_next - 1]) {
// Copy the last entry here, in order to free an entry for the future use
// When the current entry is not the last entry,
// then we try to copy the last entry to the current entry, in order to free one entry
if(entry != (list_t *)&_objects[_next - 1]) {
// Copy the last entry here
memcpy(entry, (void *)&_objects[_next - 1], sizeof(PerBigObject));

// Because we copy the last entry to the current node, then the last entry's prev and next node
// should be changed to the current entry
// Note that no need to change the list pointers for the current entry
entry->prev->next = entry;
if(entry->next != NULL) {
// this is the last entry
entry->next->prev = entry;
}
else {
// Update the list's pointer to this entry
_list.prev = entry;
}
// Update the last entry's prev and next node, so that they can be pointed to the current entry
// Note that there is no need to change the list pointers for the current entry
listUpdateEntry(entry);
}

// Freed an entry
_next--;
}
Expand Down Expand Up @@ -266,7 +256,8 @@ public:
lock();

PerBigObject * object = &_objects[_next];
initDLEntry(&object->list);

nodeInit(&object->list);
object->size = size;
object->address = ptr;

Expand All @@ -277,7 +268,8 @@ public:
assert(_next != _max);

// Insert this entry to the header of freelist.
insertDLBegin(&_list, &object->list);
listInsertHead(&object->list, &_list);
//insertDLBegin(&_list, &object->list);

// Change PerMBInfo in order to encourage the coalesce TODO:
clearPerMBInfo(ptr, size);
Expand Down

0 comments on commit afe29bc

Please sign in to comment.