Changeset: ae39d693faee for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ae39d693faee
Branch: Jul2021
Log Message:

merged


diffs (truncated from 500 to 300 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1696,6 +1696,12 @@ tfastins_nocheckVAR(BAT *b, BUN p, const
 }
 
 static inline gdk_return __attribute__((__warn_unused_result__))
+tfastins_nocheckFIX(BAT *b, BUN p, const void *v)
+{
+       return ATOMputFIX(b->ttype, Tloc(b, p), v);
+}
+
+static inline gdk_return __attribute__((__warn_unused_result__))
 tfastins_nocheck(BAT *b, BUN p, const void *v)
 {
        assert(b->theap->parentid == b->batCacheid);
@@ -1707,7 +1713,7 @@ tfastins_nocheck(BAT *b, BUN p, const vo
        } else if (b->tvarsized) {
                return tfastins_nocheckVAR(b, p, v);
        } else {
-               return ATOMputFIX(b->ttype, Tloc(b, p), v);
+               return tfastins_nocheckFIX(b, p, v);
        }
        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
@@ -632,11 +632,12 @@ BATclear(BAT *b, bool force)
                        b->tvheap->dirty = true;
                }
        }
-       MT_lock_unset(&b->theaplock);
 
        if (force)
                b->batInserted = 0;
-       BATsetcount(b,0);
+       b->batCount = 0;
+       if (b->ttype == TYPE_void)
+               b->batCapacity = 0;
        BAThseqbase(b, 0);
        BATtseqbase(b, ATOMtype(b->ttype) == TYPE_oid ? 0 : oid_nil);
        b->batDirtydesc = true;
@@ -644,6 +645,7 @@ BATclear(BAT *b, bool force)
        BATsettrivprop(b);
        b->tnosorted = b->tnorevsorted = 0;
        b->tnokey[0] = b->tnokey[1] = 0;
+       MT_lock_unset(&b->theaplock);
        return GDK_SUCCEED;
 }
 
@@ -1163,22 +1165,42 @@ BUNappendmulti(BAT *b, const void *value
        }
        MT_rwlock_wrlock(&b->thashlock);
        if (values && b->ttype) {
-               for (BUN i = 0; i < count; i++) {
-                       t = b->tvarsized ? ((void **) values)[i] :
-                               (void *) ((char *) values + (i << b->tshift));
-                       gdk_return rc = bunfastapp_nocheck(b, t);
-                       if (rc != GDK_SUCCEED) {
-                               MT_rwlock_wrunlock(&b->thashlock);
-                               return rc;
+               if (b->tvarsized) {
+                       for (BUN i = 0; i < count; i++) {
+                               t = ((void **) values)[i];
+                               gdk_return rc = tfastins_nocheckVAR(b, p, t);
+                               if (rc != GDK_SUCCEED) {
+                                       MT_rwlock_wrunlock(&b->thashlock);
+                                       return rc;
+                               }
+                               if (b->thash) {
+                                       HASHappend_locked(b, p, t);
+                               }
+                               p++;
                        }
-                       if (b->thash) {
-                               HASHappend_locked(b, p, t);
+               } else if (ATOMstorage(b->ttype) == TYPE_msk) {
+                       for (BUN i = 0; i < count; i++) {
+                               t = (void *) ((char *) values + (i << 
b->tshift));
+                               mskSetVal(b, p, *(msk *) t);
+                               p++;
                        }
-                       p++;
+               } else {
+                       for (BUN i = 0; i < count; i++) {
+                               t = (void *) ((char *) values + (i << 
b->tshift));
+                               gdk_return rc = tfastins_nocheckFIX(b, p, t);
+                               if (rc != GDK_SUCCEED) {
+                                       MT_rwlock_wrunlock(&b->thashlock);
+                                       return rc;
+                               }
+                               if (b->thash) {
+                                       HASHappend_locked(b, p, t);
+                               }
+                               p++;
+                       }
                }
        } else {
                for (BUN i = 0; i < count; i++) {
-                       gdk_return rc = bunfastapp_nocheck(b, t);
+                       gdk_return rc = tfastins_nocheck(b, p, t);
                        if (rc != GDK_SUCCEED) {
                                MT_rwlock_wrunlock(&b->thashlock);
                                return rc;
@@ -1190,6 +1212,7 @@ BUNappendmulti(BAT *b, const void *value
                }
        }
        MT_rwlock_wrunlock(&b->thashlock);
+       BATsetcount(b, p);
 
        IMPSdestroy(b); /* no support for inserts in imprints yet */
        OIDXdestroy(b);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -229,7 +229,6 @@ insert_string_bat(BAT *b, BAT *n, struct
                /* we don't need to do any translation of offset
                 * values, so we can use fast memcpy */
                memcpy(Tloc(b, BUNlast(b)), (const char *) ni.base + ((ci->seq 
- n->hseqbase) << ni.shift), cnt << ni.shift);
-               BATsetcount(b, oldcnt + cnt);
        } else if (toff != ~(size_t) 0) {
                /* we don't need to insert any actual strings since we
                 * have already made sure that they are all in b's
@@ -314,7 +313,6 @@ insert_string_bat(BAT *b, BAT *n, struct
                                break;
                        }
                }
-               BATsetcount(b, r); /* set batCount and theap->free */
        } else if (b->tvheap->free < ni.vh->free / 2 ||
                   GDK_ELIMDOUBLES(b->tvheap)) {
                /* if b's string heap is much smaller than n's string
@@ -335,7 +333,6 @@ insert_string_bat(BAT *b, BAT *n, struct
                        }
                        r++;
                }
-               BATsetcount(b, r);
        } else {
                /* Insert values from n individually into b; however,
                 * we check whether there is a string in b's string
@@ -387,8 +384,8 @@ insert_string_bat(BAT *b, BAT *n, struct
                        }
                        r++;
                }
-               BATsetcount(b, r);
        }
+       BATsetcount(b, oldcnt + ci->ncand);
        bat_iterator_end(&ni);
        assert(b->batCapacity >= b->batCount);
        b->theap->dirty = true;
@@ -465,11 +462,13 @@ append_varsized_bat(BAT *b, BAT *n, stru
                b->theap->dirty = true;
                BATsetcount(b, BATcount(b) + ci->ncand);
                /* maintain hash table */
+               MT_rwlock_wrlock(&b->thashlock);
                for (BUN i = BATcount(b) - ci->ncand;
                     b->thash && i < BATcount(b);
                     i++) {
-                       HASHappend(b, i, b->tvheap->base + *(var_t *) Tloc(b, 
i));
+                       HASHappend_locked(b, i, b->tvheap->base + *(var_t *) 
Tloc(b, i));
                }
+               MT_rwlock_wrunlock(&b->thashlock);
                bat_iterator_end(&ni);
                return GDK_SUCCEED;
        }
@@ -504,7 +503,7 @@ append_varsized_bat(BAT *b, BAT *n, stru
                cnt--;
                BUN p = canditer_next(ci) - hseq;
                const void *t = BUNtvar(ni, p);
-               if (bunfastapp_nocheckVAR(b, t) != GDK_SUCCEED) {
+               if (tfastins_nocheckVAR(b, r, t) != GDK_SUCCEED) {
                        bat_iterator_end(&ni);
                        return GDK_FAIL;
                }
@@ -512,6 +511,7 @@ append_varsized_bat(BAT *b, BAT *n, stru
                        HASHappend(b, r, t);
                r++;
        }
+       BATsetcount(b, r);
        bat_iterator_end(&ni);
        b->theap->dirty = true;
        return GDK_SUCCEED;
@@ -525,6 +525,8 @@ append_msk_bat(BAT *b, BAT *n, struct ca
        if (BATextend(b, BATcount(b) + ci->ncand) != GDK_SUCCEED)
                return GDK_FAIL;
 
+       MT_lock_set(&b->theaplock);
+
        uint32_t boff = b->batCount % 32;
        uint32_t *bp = (uint32_t *) b->theap->base + b->batCount / 32;
        b->batCount += ci->ncand;
@@ -550,30 +552,29 @@ append_msk_bat(BAT *b, BAT *n, struct ca
                                        *bp &= ~mask;
                                        *bp |= *np & mask;
                                }
-                               bat_iterator_end(&ni);
-                               return GDK_SUCCEED;
-                       }
-                       /* multiple words of b are affected */
-                       if (boff != 0) {
-                               /* first fill up the rest of the first
-                                * word */
-                               mask = ~0U << boff;
-                               *bp &= ~mask;
-                               *bp++ |= *np++ & mask;
-                               cnt -= 32 - boff;
-                       }
-                       if (cnt >= 32) {
-                               /* copy an integral number of words fast */
-                               BUN nw = cnt / 32;
-                               memcpy(bp, np, nw*sizeof(int));
-                               bp += nw;
-                               np += nw;
-                               cnt %= 32;
-                       }
-                       if (cnt > 0) {
-                               /* do the left over bits */
-                               mask = (1U << cnt) - 1;
-                               *bp = *np & mask;
+                       } else {
+                               /* multiple words of b are affected */
+                               if (boff != 0) {
+                                       /* first fill up the rest of the first
+                                        * word */
+                                       mask = ~0U << boff;
+                                       *bp &= ~mask;
+                                       *bp++ |= *np++ & mask;
+                                       cnt -= 32 - boff;
+                               }
+                               if (cnt >= 32) {
+                                       /* copy an integral number of words 
fast */
+                                       BUN nw = cnt / 32;
+                                       memcpy(bp, np, nw*sizeof(int));
+                                       bp += nw;
+                                       np += nw;
+                                       cnt %= 32;
+                               }
+                               if (cnt > 0) {
+                                       /* do the left over bits */
+                                       mask = (1U << cnt) - 1;
+                                       *bp = *np & mask;
+                               }
                        }
                } else if (boff > noff) {
                        if (boff + cnt <= 32) {
@@ -585,42 +586,41 @@ append_msk_bat(BAT *b, BAT *n, struct ca
                                mask = (1U << cnt) - 1;
                                *bp &= ~(mask << boff);
                                *bp |= (*np & (mask << noff)) << (boff - noff);
-                               bat_iterator_end(&ni);
-                               return GDK_SUCCEED;
-                       }
-                       /* first fill the rest of the last partial
-                        * word of b, so that's 32-boff bits */
-                       mask = (1U << (32 - boff)) - 1;
-                       *bp &= ~(mask << boff);
-                       *bp++ |= (*np & (mask << noff)) << (boff - noff);
-                       cnt -= 32 - boff;
+                       } else {
+                               /* first fill the rest of the last partial
+                                * word of b, so that's 32-boff bits */
+                               mask = (1U << (32 - boff)) - 1;
+                               *bp &= ~(mask << boff);
+                               *bp++ |= (*np & (mask << noff)) << (boff - 
noff);
+                               cnt -= 32 - boff;
 
-                       /* set boff and noff to the amount we need to
-                        * shift bits in consecutive words of n around
-                        * to fit into the next word of b; set mask to
-                        * the mask of the bottom bits of n that fit
-                        * in a word of b (and the complement are the
-                        * top bits that go to another word of b) */
-                       boff -= noff;
-                       noff = 32 - boff;
-                       mask = (1U << noff) - 1;
-                       while (cnt >= 32) {
-                               *bp = (*np++ & ~mask) >> noff;
-                               *bp++ |= (*np & mask) << boff;
-                               cnt -= 32;
-                       }
-                       if (cnt > boff) {
-                               /* the last bits come from two words
-                                * in n */
-                               *bp = (*np++ & ~mask) >> noff;
-                               cnt -= noff;
-                               mask = (1U << cnt) - 1;
-                               *bp++ |= (*np & mask) << boff;
-                       } else if (cnt > 0) {
-                               /* the last bits come from a single
-                                * word in n */
-                               mask = ((1U << cnt) - 1) << noff;
-                               *bp = (*np & mask) >> noff;
+                               /* set boff and noff to the amount we need to
+                                * shift bits in consecutive words of n around
+                                * to fit into the next word of b; set mask to
+                                * the mask of the bottom bits of n that fit
+                                * in a word of b (and the complement are the
+                                * top bits that go to another word of b) */
+                               boff -= noff;
+                               noff = 32 - boff;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to