Changeset: 2bd5d2dc2135 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/2bd5d2dc2135 Modified Files: gdk/gdk_system.c gdk/gdk_utils.c Branch: default Log Message:
Some small fixes to updated thread code. diffs (149 lines): diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c --- a/gdk/gdk_system.c +++ b/gdk/gdk_system.c @@ -410,7 +410,6 @@ MT_thread_register(void) GDKerror("too many threads\n"); return false; } - thread_lock(); *self = (struct mtthread) { .detached = false, #ifdef HAVE_PTHREAD_H @@ -424,6 +423,7 @@ MT_thread_register(void) snprintf(self->threadname, sizeof(self->threadname), "foreign %zu", self->tid); ATOMIC_INIT(&self->exited, 0); thread_setself(self); + thread_lock(); self->next = mtthreads; mtthreads = self; thread_unlock(); @@ -477,6 +477,8 @@ GDKsetbuf(char *errbuf) self = &mainthread; assert(errbuf == NULL || self->errbuf == NULL); self->errbuf = errbuf; + if (errbuf) + *errbuf = 0; /* start clean */ } char * @@ -765,17 +767,6 @@ join_detached_threads(void) thread_unlock(); } -#ifdef HAVE_PTHREAD_SIGMASK -static void -MT_thread_sigmask(sigset_t *new_mask, sigset_t *orig_mask) -{ - /* do not check for errors! */ - sigdelset(new_mask, SIGQUIT); - sigdelset(new_mask, SIGPROF); - pthread_sigmask(SIG_SETMASK, new_mask, orig_mask); -} -#endif - int MT_create_thread(MT_Id *t, void (*f) (void *), void *arg, enum MT_thr_detach d, const char *threadname) { @@ -803,11 +794,13 @@ MT_create_thread(MT_Id *t, void (*f) (vo int ret; if ((ret = pthread_attr_init(&attr)) != 0) { GDKsyserr(ret, "Cannot init pthread attr"); + dealloc_thread(mtid); return -1; } if ((ret = pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE)) != 0) { GDKsyserr(ret, "Cannot set stack size"); pthread_attr_destroy(&attr); + dealloc_thread(mtid); return -1; } #endif @@ -817,6 +810,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo #ifdef HAVE_PTHREAD_H pthread_attr_destroy(&attr); #endif + dealloc_thread(mtid); return -1; } @@ -830,38 +824,39 @@ MT_create_thread(MT_Id *t, void (*f) (vo }; ATOMIC_INIT(&self->exited, 0); strcpy_len(self->threadname, threadname, sizeof(self->threadname)); + TRC_DEBUG(THRD, "Create thread \"%s\"\n", self->threadname); +#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_SIGMASK sigset_t new_mask, orig_mask; (void) sigfillset(&new_mask); - MT_thread_sigmask(&new_mask, &orig_mask); + sigdelset(&new_mask, SIGQUIT); + sigdelset(&new_mask, SIGPROF); + pthread_sigmask(SIG_SETMASK, &new_mask, &orig_mask); #endif - TRC_DEBUG(THRD, "Create thread \"%s\"\n", threadname); - thread_lock(); -#ifdef HAVE_PTHREAD_H ret = pthread_create(&self->hdl, &attr, thread_starter, self); + pthread_attr_destroy(&attr); +#ifdef HAVE_PTHREAD_SIGMASK + pthread_sigmask(SIG_SETMASK, &orig_mask, NULL); +#endif if (ret != 0) { - thread_unlock(); GDKsyserr(ret, "Cannot start thread"); free(self); + dealloc_thread(mtid); + return -1; } - pthread_attr_destroy(&attr); -#ifdef HAVE_PTHREAD_SIGMASK - MT_thread_sigmask(&orig_mask, NULL); -#endif - if (ret != 0) - return -1; #else self->hdl = CreateThread(NULL, THREAD_STACK_SIZE, thread_starter, self, 0, &self->wtid); if (self->hdl == NULL) { GDKwinerror("Failed to create thread"); - thread_unlock(); free(self); + dealloc_thread(mtid); return -1; } #endif /* must not fail after this: the thread has been started */ *t = mtid; + thread_lock(); self->next = mtthreads; mtthreads = self; thread_unlock(); diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c --- a/gdk/gdk_utils.c +++ b/gdk/gdk_utils.c @@ -1153,6 +1153,8 @@ GDKinit(opt *set, int setlen, bool embed return GDK_FAIL; } } + if (GDKnr_threads > THREADS) + GDKnr_threads = THREADS; if (!GDKinmemory(0)) { if ((p = GDKgetenv("gdk_dbpath")) != NULL && @@ -1251,7 +1253,6 @@ static ATOMIC_TYPE GDKnrofthreads = ATOM struct threadStruct { ATOMIC_TYPE pid; /* thread id, 0 = unallocated */ }; -static struct threadStruct GDKthreads[THREADS]; bool GDKexiting(void) @@ -1302,8 +1303,6 @@ GDKreset(int status) if (status == 0) { /* they had their chance, now kill them */ bool killed = MT_kill_threads(); - for (int i = 0; i < THREADS; i++) - ATOMIC_SET(&GDKthreads[i].pid, 0); /* all threads ceased running, now we can clean up */ if (!killed) { /* we can't clean up after killing threads */ _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org