Changeset: 02a5e5bb51d6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=02a5e5bb51d6
Modified Files:
gdk/gdk_imprints.c
Branch: embedded
Log Message:
merging imprints fix from Jul2015
diffs (122 lines):
diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c
--- a/gdk/gdk_imprints.c
+++ b/gdk/gdk_imprints.c
@@ -534,7 +534,7 @@ imprints_create(BAT *b, void *inbins, BU
#define FILL_HISTOGRAM(TYPE) \
do { \
BUN k; \
- TYPE *restrict s = (TYPE *) Tloc(smp, smp->batFirst); \
+ TYPE *restrict s = (TYPE *) Tloc(s4, s4->batFirst); \
TYPE *restrict h = imprints->bins; \
if (cnt < 64-1) { \
TYPE max = GDK_##TYPE##_max; \
@@ -643,7 +643,7 @@ BATcheckimprints(BAT *b)
gdk_return
BATimprints(BAT *b)
{
- BAT *o = NULL;
+ BAT *o = NULL, *s1 = NULL, *s2 = NULL, *s3 = NULL, *s4 = NULL;
Imprints *imprints;
lng t0 = 0, t1 = 0;
@@ -694,7 +694,6 @@ BATimprints(BAT *b)
MT_lock_set(&GDKimprintsLock(abs(b->batCacheid)));
t0 = GDKusec();
if (b->T->imprints == NULL) {
- BAT *smp, *s;
BUN cnt;
str nme = BBP_physical(b->batCacheid);
size_t pages;
@@ -725,37 +724,39 @@ BATimprints(BAT *b)
imprintsheap);
#define SMP_SIZE 2048
- s = BATsample(b, SMP_SIZE);
- if (s == NULL) {
+ s1 = BATsample(b, SMP_SIZE);
+ if (s1 == NULL) {
MT_lock_unset(&GDKimprintsLock(abs(b->batCacheid)));
GDKfree(imprints);
return GDK_FAIL;
}
- smp = BATunique(b, s);
- BBPunfix(s->batCacheid);
- if (smp == NULL) {
+ s2 = BATunique(b, s1);
+ if (s2 == NULL) {
MT_lock_unset(&GDKimprintsLock(abs(b->batCacheid)));
+ BBPunfix(s1->batCacheid);
GDKfree(imprints);
return GDK_FAIL;
}
- s = BATproject(smp, b);
- BBPunfix(smp->batCacheid);
- if (s == NULL) {
+ s3 = BATproject(s2, b);
+ if (s3 == NULL) {
MT_lock_unset(&GDKimprintsLock(abs(b->batCacheid)));
+ BBPunfix(s1->batCacheid);
+ BBPunfix(s2->batCacheid);
GDKfree(imprints);
return GDK_FAIL;
}
- s->tkey = 1; /* we know is unique on tail now */
- if (BATsort(&smp, NULL, NULL, s, NULL, NULL, 0, 0) !=
GDK_SUCCEED) {
+ s3->tkey = 1; /* we know is unique on tail now */
+ if (BATsort(&s4, NULL, NULL, s3, NULL, NULL, 0, 0) !=
GDK_SUCCEED) {
MT_lock_unset(&GDKimprintsLock(abs(b->batCacheid)));
- BBPunfix(s->batCacheid);
+ BBPunfix(s1->batCacheid);
+ BBPunfix(s2->batCacheid);
+ BBPunfix(s3->batCacheid);
GDKfree(imprints);
return GDK_FAIL;
}
- BBPunfix(s->batCacheid);
- /* smp now is ordered and unique on tail */
- assert(smp->tkey && smp->tsorted);
- cnt = BATcount(smp);
+ /* s4 now is ordered and unique on tail */
+ assert(s4->tkey && s4->tsorted);
+ cnt = BATcount(s4);
imprints->bits = 64;
if (cnt < 32)
imprints->bits = 32;
@@ -784,7 +785,12 @@ BATimprints(BAT *b)
1) != GDK_SUCCEED) {
GDKfree(imprints->imprints);
GDKfree(imprints);
+ GDKerror("#BATimprints: memory allocation error");
MT_lock_unset(&GDKimprintsLock(abs(b->batCacheid)));
+ BBPunfix(s1->batCacheid);
+ BBPunfix(s2->batCacheid);
+ BBPunfix(s3->batCacheid);
+ BBPunfix(s4->batCacheid);
return GDK_FAIL;
}
imprints->bins = imprints->imprints->base +
IMPRINTS_HEADER_SIZE * SIZEOF_SIZE_T;
@@ -821,8 +827,6 @@ BATimprints(BAT *b)
assert(0);
}
- BBPunfix(smp->batCacheid);
-
imprints_create(b,
imprints->bins,
imprints->stats,
@@ -868,7 +872,14 @@ BATimprints(BAT *b)
ALGODEBUG fprintf(stderr, "#BATimprints: imprints construction " LLFMT
" usec\n", t1 - t0);
MT_lock_unset(&GDKimprintsLock(abs(b->batCacheid)));
-
+ /* BBPUnfix tries to get the imprints lock which might lead to a
deadlock
+ * if those were unfixed earlier */
+ if (s1) {
+ BBPunfix(s1->batCacheid);
+ BBPunfix(s2->batCacheid);
+ BBPunfix(s3->batCacheid);
+ BBPunfix(s4->batCacheid);
+ }
if (o != NULL) {
o->T->imprints = NULL; /* views always keep null pointer and
need to obtain the latest imprint
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list