Changeset: 466a0f7900ce for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=466a0f7900ce Modified Files: gdk/gdk_bbp.c gdk/gdk_utils.c Branch: subquery Log Message:
merged diffs (109 lines): diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -549,9 +549,11 @@ fixfloatbats(void) "%s/%.*s_nil-nan-convert", BBPfarms[0].dirname, (int) (len - 12), BBP_logical(bid)); - if (written == -1 || written >= FILENAME_MAX) - GDKfatal("fixfloatbats: cannot create file %s has a very large pathname\n", + if (written == -1 || written >= FILENAME_MAX) { + GDKerror("fixfloatbats: cannot create file %s has a very large pathname\n", filename); + return GDK_FAIL; + } fp = fopen(filename, "w"); if (fp == NULL) { GDKsyserror("fixfloatbats: cannot create file %s\n", diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c --- a/gdk/gdk_utils.c +++ b/gdk/gdk_utils.c @@ -699,28 +699,29 @@ GDKexiting(void) return (bool) (ATOMIC_GET(&GDKstopped) > 0); } -static struct serverthread { +struct serverthread { struct serverthread *next; MT_Id pid; -} *serverthread; +}; +static ATOMIC_PTR_TYPE serverthread = ATOMIC_PTR_VAR_INIT(NULL); void GDKprepareExit(void) { + struct serverthread *st; + if (ATOMIC_ADD(&GDKstopped, 1) > 0) return; THRDDEBUG dump_threads(); - MT_lock_set(&GDKthreadLock); - while (serverthread != NULL) { - struct serverthread *st = serverthread; - serverthread = st->next; - MT_lock_unset(&GDKthreadLock); + /* we're saved from the ABA problem in this code because it is + * only executed by one thread */ + while ((st = ATOMIC_PTR_GET(&serverthread)) != NULL) { + while (!ATOMIC_PTR_CAS(&serverthread, &st, st->next)) + ; MT_join_thread(st->pid); GDKfree(st); - MT_lock_set(&GDKthreadLock); } - MT_lock_unset(&GDKthreadLock); join_detached_threads(); } @@ -734,15 +735,15 @@ GDKregister(MT_Id pid) if ((st = GDKmalloc(sizeof(struct serverthread))) == NULL) return; st->pid = pid; - MT_lock_set(&GDKthreadLock); - st->next = serverthread; - serverthread = st; - MT_lock_unset(&GDKthreadLock); + st->next = ATOMIC_PTR_GET(&serverthread); + while (!ATOMIC_PTR_CAS(&serverthread, &st->next, st)) + ; } void GDKreset(int status) { + struct serverthread *st; MT_Id pid = MT_getpid(); assert(GDKexiting()); @@ -756,23 +757,21 @@ GDKreset(int status) GDKval = NULL; } - MT_lock_set(&GDKthreadLock); - while (serverthread != NULL) { - struct serverthread *st = serverthread; - serverthread = st->next; - MT_lock_unset(&GDKthreadLock); + /* we're saved from the ABA problem in this code because it is + * only executed by one thread */ + while ((st = ATOMIC_PTR_GET(&serverthread)) != NULL) { + while (!ATOMIC_PTR_CAS(&serverthread, &st, st->next)) + ; MT_join_thread(st->pid); GDKfree(st); - MT_lock_set(&GDKthreadLock); } - MT_lock_unset(&GDKthreadLock); join_detached_threads(); if (status == 0) { /* they had their chance, now kill them */ bool killed = false; MT_lock_set(&GDKthreadLock); - assert(serverthread == NULL); + assert(ATOMIC_PTR_GET(&serverthread) == NULL); for (Thread t = GDKthreads; t < GDKthreads + THREADS; t++) { MT_Id victim; if ((victim = (MT_Id) ATOMIC_GET(&t->pid)) != 0) { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list