Changeset: 4be888a2becd for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/4be888a2becd Modified Files: gdk/gdk_batop.c gdk/gdk_bbp.c gdk/gdk_hash.c Branch: default Log Message:
Fixed a bunch of data races. diffs (161 lines): diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c --- a/gdk/gdk_batop.c +++ b/gdk/gdk_batop.c @@ -92,9 +92,9 @@ insert_string_bat(BAT *b, BAT *n, struct HEAPdecref(b->tvheap, b->tvheap->parentid == b->batCacheid); HEAPincref(ni.vh); b->tvheap = ni.vh; - BBPshare(ni.vh->parentid); b->batDirtydesc = true; MT_lock_unset(&b->theaplock); + BBPshare(ni.vh->parentid); toff = 0; MT_thread_setalgorithm("share vheap"); } else { @@ -1858,10 +1858,15 @@ BATordered(BAT *b) { lng t0 = GDKusec(); - if (b->ttype == TYPE_void || b->tsorted || BATcount(b) == 0) + MT_lock_set(&b->theaplock); + if (b->ttype == TYPE_void || b->tsorted || BATcount(b) == 0) { + MT_lock_unset(&b->theaplock); return true; - if (b->tnosorted > 0 || !ATOMlinear(b->ttype)) + } + if (b->tnosorted > 0 || !ATOMlinear(b->ttype)) { + MT_lock_unset(&b->theaplock); return false; + } /* There are a few reasons why we need a lock here. It may be * that multiple threads call this functions at the same time @@ -1871,7 +1876,6 @@ BATordered(BAT *b) * remain accessible (could have used bat_iterator for that), * and, and this is the killer argument, we may need to make * changes to the bat descriptor. */ - MT_lock_set(&b->theaplock); BATiter bi = bat_iterator_nolock(b); if (!b->tsorted && b->tnosorted == 0) { b->batDirtydesc = true; @@ -2012,13 +2016,19 @@ BATordered_rev(BAT *b) if (b == NULL || !ATOMlinear(b->ttype)) return false; - if (BATcount(b) <= 1 || b->trevsorted) + MT_lock_set(&b->theaplock); + if (BATcount(b) <= 1 || b->trevsorted) { + MT_lock_unset(&b->theaplock); return true; - if (b->ttype == TYPE_void) + } + if (b->ttype == TYPE_void) { + MT_lock_unset(&b->theaplock); return is_oid_nil(b->tseqbase); - if (BATtdense(b) || b->tnorevsorted > 0) + } + if (BATtdense(b) || b->tnorevsorted > 0) { + MT_lock_unset(&b->theaplock); return false; - MT_lock_set(&b->theaplock); + } BATiter bi = bat_iterator_nolock(b); if (!b->trevsorted && b->tnorevsorted == 0) { b->batDirtydesc = true; diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -125,12 +125,6 @@ static void BBPcallbacks(void); static lng BBPlogno; /* two lngs of extra info in BBP.dir */ static lng BBPtransid; -#ifdef HAVE_HGE -/* start out by saying we have no hge, but as soon as we've seen one, - * we'll always say we do have it */ -static bool havehge = false; -#endif - #define BBPtmpcheck(s) (strncmp(s, "tmp_", 4) == 0) #define BBPnamecheck(s) (BBPtmpcheck(s) ? strtol((s) + 4, NULL, 8) : 0) @@ -468,10 +462,6 @@ heapinit(BAT *b, const char *buf, *hashash = var & 2; #endif var &= ~2; -#ifdef HAVE_HGE - if (strcmp(type, "hge") == 0) - havehge = true; -#endif if ((t = ATOMindex(type)) < 0) { if ((t = ATOMunknown_find(type)) == 0) { TRC_CRITICAL(GDK, "no space for atom %s", type); @@ -1935,9 +1925,11 @@ BBPdir_header(FILE *f, int n, lng logno, if (fprintf(f, "BBP.dir, GDKversion %u\n%d %d %d\nBBPsize=%d\nBBPinfo=" LLFMT " " LLFMT "\n", GDKLIBRARY, SIZEOF_SIZE_T, SIZEOF_OID, #ifdef HAVE_HGE - havehge ? SIZEOF_HGE : + SIZEOF_HGE +#else + SIZEOF_LNG #endif - SIZEOF_LNG, n, logno, transid) < 0 || + , n, logno, transid) < 0 || ferror(f)) { GDKsyserror("Writing BBP.dir header failed\n"); return GDK_FAIL; @@ -2482,11 +2474,6 @@ BBPinsert(BAT *bn) BBP_pid(i) = MT_getpid(); MT_lock_unset(&GDKswapLock(i)); -#ifdef HAVE_HGE - if (bn->ttype == TYPE_hge) - havehge = true; -#endif - if (*BBP_bak(i) == 0) len = snprintf(BBP_bak(i), sizeof(BBP_bak(i)), "tmp_%o", (unsigned) i); if (len == -1 || len >= FILENAME_MAX) { diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c --- a/gdk/gdk_hash.c +++ b/gdk/gdk_hash.c @@ -448,18 +448,19 @@ HASHgrowbucket(BAT *b) bool BATcheckhash(BAT *b) { - bool ret; lng t = 0; + Hash *h; - /* we don't need the lock just to read the value b->thash */ - if (b->thash == (Hash *) 1) { + MT_rwlock_rdlock(&b->thashlock); + h = b->thash; + MT_rwlock_rdunlock(&b->thashlock); + if (h == (Hash *) 1) { /* but when we want to change it, we need the lock */ TRC_DEBUG_IF(ACCELERATOR) t = GDKusec(); MT_rwlock_wrlock(&b->thashlock); TRC_DEBUG_IF(ACCELERATOR) t = GDKusec() - t; /* if still 1 now that we have the lock, we can update */ if (b->thash == (Hash *) 1) { - Hash *h; int fd; assert(!GDKinmemory(b->theap->farmid)); @@ -578,13 +579,13 @@ BATcheckhash(BAT *b) GDKfree(h); GDKclrerr(); /* we're not currently interested in errors */ } + h = b->thash; MT_rwlock_wrunlock(&b->thashlock); } - ret = b->thash != NULL; - if (ret) { + if (h != NULL) { TRC_DEBUG(ACCELERATOR, ALGOBATFMT ": already has hash, waited " LLFMT " usec\n", ALGOBATPAR(b), t); } - return ret; + return h != NULL; } static void _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org