Changeset: 19dc30bfd08d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=19dc30bfd08d
Modified Files:
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_heap.c
gdk/gdk_private.h
Branch: unlock
Log Message:
New function HEAPgrow to grow a heap using reference counting.
diffs (95 lines):
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -467,10 +467,15 @@ BATextend(BAT *b, BUN newcap)
theap_size *= Tsize(b);
if (b->theap->base) {
- TRC_DEBUG(HEAP, "HEAPextend in BATextend %s %zu %zu\n",
+ TRC_DEBUG(HEAP, "HEAPgrow in BATextend %s %zu %zu\n",
b->theap->filename, b->theap->size, theap_size);
- if (HEAPextend(b->theap, theap_size, b->batRestricted ==
BAT_READ) != GDK_SUCCEED)
+ Heap *h = HEAPgrow(b->theap, theap_size);
+ if (h == NULL)
return GDK_FAIL;
+ MT_lock_set(&b->theaplock);
+ HEAPdecref(b->theap, false);
+ b->theap = h;
+ MT_lock_unset(&b->theaplock);
}
return GDK_SUCCEED;
}
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -176,10 +176,13 @@ insert_string_bat(BAT *b, BAT *n, struct
toff = (toff + GDK_VARALIGN - 1) &
~(GDK_VARALIGN - 1);
/* if in "force" mode, the heap may be
* shared when memory mapped */
- if (HEAPextend(b->tvheap, toff +
n->tvheap->size, force) != GDK_SUCCEED) {
- toff = ~(size_t) 0;
+ Heap *h = HEAPgrow(b->tvheap, toff +
n->tvheap->size);
+ if (h == NULL)
return GDK_FAIL;
- }
+ MT_lock_set(&b->theaplock);
+ HEAPdecref(b->tvheap, false);
+ b->tvheap = h;
+ MT_lock_unset(&b->theaplock);
memcpy(b->tvheap->base + toff, n->tvheap->base,
n->tvheap->free);
b->tvheap->free = toff + n->tvheap->free;
if (toff > 0) {
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -85,6 +85,38 @@ decompose_filename(str nme)
return ext;
}
+Heap *
+HEAPgrow(const Heap *old, size_t size)
+{
+ assert(size >= old->free);
+ assert(old->storage == STORE_MEM || old->storage == STORE_MMAP);
+
+ Heap *new = GDKmalloc(sizeof(Heap));
+ if (new == NULL)
+ return NULL;
+ *new = (Heap) {
+ .farmid = old->farmid,
+ .hashash = old->hashash,
+ .cleanhash = old->cleanhash,
+ .dirty = true,
+ .remove = old->remove,
+ .parentid = old->parentid,
+ };
+ memcpy(new->filename, old->filename, sizeof(new->filename));
+ if (HEAPalloc(new, size, 1) != GDK_SUCCEED) {
+ GDKfree(new);
+ return NULL;
+ }
+ ATOMIC_INIT(&new->refs, 1);
+ assert(new->storage == STORE_MEM || new->storage == STORE_MMAP);
+ new->free = old->free;
+ if (old->free > 0 &&
+ (new->storage == STORE_MEM || old->storage == STORE_MEM))
+ memcpy(new->base, old->base, old->free);
+ /* else both are STORE_MMAP and refer to the same file */
+ return new;
+}
+
/*
* @- HEAPalloc
*
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -186,6 +186,8 @@ gdk_return HEAPdelete(Heap *h, const cha
__attribute__((__visibility__("hidden")));
void HEAPfree(Heap *h, bool remove)
__attribute__((__visibility__("hidden")));
+Heap *HEAPgrow(const Heap *old, size_t size)
+ __attribute__((__visibility__("hidden")));
gdk_return HEAPload(Heap *h, const char *nme, const char *ext, bool trunc)
__attribute__((__warn_unused_result__))
__attribute__((__visibility__("hidden")));
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list