Changeset: 5a5d34864737 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5a5d34864737
Modified Files:
gdk/gdk.h
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_heap.c
Branch: default
Log Message:
Call GDKupgradevarheap with the theaplock held.
This involves not calling BATextend inside the function but calling
HEAPgrow instead.
diffs (138 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1219,15 +1219,18 @@ tfastins_nocheckVAR(BAT *b, BUN p, const
assert(b->theap->parentid == b->batCacheid);
MT_lock_set(&b->theaplock);
rc = ATOMputVAR(b, &d, v);
- MT_lock_unset(&b->theaplock);
- if (rc != GDK_SUCCEED)
+ if (rc != GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
return rc;
+ }
if (b->twidth < SIZEOF_VAR_T &&
(b->twidth <= 2 ? d - GDK_VAROFFSET : d) >= ((size_t) 1 << (8 <<
b->tshift))) {
/* doesn't fit in current heap, upgrade it */
rc = GDKupgradevarheap(b, d, 0, MAX(p, b->batCount));
- if (rc != GDK_SUCCEED)
+ if (rc != GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
return rc;
+ }
}
switch (b->twidth) {
case 1:
@@ -1247,6 +1250,7 @@ tfastins_nocheckVAR(BAT *b, BUN p, const
default:
MT_UNREACHABLE();
}
+ MT_lock_unset(&b->theaplock);
return GDK_SUCCEED;
}
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -1628,15 +1628,16 @@ BUNinplacemulti(BAT *b, const oid *posit
MT_rwlock_wrunlock(&b->thashlock);
goto bailout;
}
- MT_lock_unset(&b->theaplock);
if (b->twidth < SIZEOF_VAR_T &&
(b->twidth <= 2 ? _d - GDK_VAROFFSET : _d) >=
((size_t) 1 << (8 << b->tshift))) {
/* doesn't fit in current heap, upgrade it */
if (GDKupgradevarheap(b, _d, 0, bi.count) !=
GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
MT_rwlock_wrunlock(&b->thashlock);
goto bailout;
}
}
+ MT_lock_unset(&b->theaplock);
/* reinitialize iterator after possible heap upgrade */
{
/* save and restore minpos/maxpos */
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -232,9 +232,12 @@ insert_string_bat(BAT *b, BATiter *ni, s
/* make sure there is (vertical) space in the offset heap, we
* may also widen thanks to v, set above */
+ MT_lock_set(&b->theaplock);
if (GDKupgradevarheap(b, v, oldcnt + cnt < b->batCapacity ?
b->batCapacity : oldcnt + cnt, b->batCount) != GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
return GDK_FAIL;
}
+ MT_lock_unset(&b->theaplock);
if (toff == 0 && ni->width == b->twidth && ci->tpe == cand_dense) {
/* we don't need to do any translation of offset
@@ -1511,14 +1514,15 @@ BATappend_or_update(BAT *b, BAT *p, cons
prevnew = new;
prevoff = d;
}
- MT_lock_unset(&b->theaplock);
if (rc != GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
goto bailout;
}
if (b->twidth < SIZEOF_VAR_T &&
(b->twidth <= 2 ? d - GDK_VAROFFSET : d) >=
((size_t) 1 << (8 << b->tshift))) {
/* doesn't fit in current heap, upgrade it */
if (GDKupgradevarheap(b, d, 0, MAX(updid,
b->batCount)) != GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
goto bailout;
}
}
@@ -1533,6 +1537,7 @@ BATappend_or_update(BAT *b, BAT *p, cons
bi.minpos = minpos;
bi.maxpos = maxpos;
}
+ MT_lock_unset(&b->theaplock);
switch (b->twidth) {
case 1:
((uint8_t *) b->theap->base)[updid] = (uint8_t)
(d - GDK_VAROFFSET);
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -437,7 +437,9 @@ HEAPextend(Heap *h, size_t size, bool ma
/* grow the string offset heap so that the value v fits (i.e. wide
* enough to fit the value), and it has space for at least cap elements;
- * copy ncopy BUNs, or up to the heap size, whichever is smaller */
+ * copy ncopy BUNs, or up to the heap size, whichever is smaller
+ *
+ * this function should be called with theaplock held */
gdk_return
GDKupgradevarheap(BAT *b, var_t v, BUN cap, BUN ncopy)
{
@@ -478,7 +480,11 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
BATsetcapacity(b, cap);
return GDK_SUCCEED;
}
- return BATextend(b, newsize >> shift);
+ if (HEAPgrow(&b->theap, newsize,
+ b->batRestricted == BAT_READ) != GDK_SUCCEED)
+ return GDK_FAIL;
+ b->batCapacity = newsize >> shift;
+ return GDK_SUCCEED;
}
n = MIN(ncopy, old->size >> b->tshift);
@@ -573,7 +579,6 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
default:
MT_UNREACHABLE();
}
- MT_lock_set(&b->theaplock);
b->tshift = shift;
b->twidth = width;
if (cap > BATcapacity(b))
@@ -590,7 +595,6 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
ValPtr p = BATgetprop_nolock(b, (enum prop_t) 20);
HEAPdecref(old, p == NULL || strcmp(((Heap*)
p->val.pval)->filename, old->filename) != 0);
}
- MT_lock_unset(&b->theaplock);
return GDK_SUCCEED;
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]