diff --git a/src/core/ddsc/src/dds_init.c b/src/core/ddsc/src/dds_init.c index 0ad2486..5e9970d 100644 --- a/src/core/ddsc/src/dds_init.c +++ b/src/core/ddsc/src/dds_init.c @@ -110,6 +110,7 @@ dds_init(void) os_mutexInit (&gv.static_logbuf_lock); gv.static_logbuf_lock_inited = 1; os_mutexInit (&dds_global.m_mutex); + thread_states_init_static(); uri = os_getenv (DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI"); dds_cfgst = config_init (uri); diff --git a/src/core/ddsi/include/ddsi/q_thread.h b/src/core/ddsi/include/ddsi/q_thread.h index 4291fd7..8643ceb 100644 --- a/src/core/ddsi/include/ddsi/q_thread.h +++ b/src/core/ddsi/include/ddsi/q_thread.h @@ -86,6 +86,7 @@ struct thread_states { extern struct thread_states thread_states; extern os_threadLocal struct thread_state1 *tsd_thread_state; +void thread_states_init_static (void); void thread_states_init (_In_ unsigned maxthreads); void thread_states_fini (void); diff --git a/src/core/ddsi/src/q_log.c b/src/core/ddsi/src/q_log.c index 1ebd06f..10808cf 100644 --- a/src/core/ddsi/src/q_log.c +++ b/src/core/ddsi/src/q_log.c @@ -93,7 +93,7 @@ static void nn_vlogb (struct thread_state1 *self, const char *fmt, va_list ap) logbuf_t lb; if (*fmt == 0) return; - if (self && self->lb) + if (self->lb) lb = self->lb; else { diff --git a/src/core/ddsi/src/q_thread.c b/src/core/ddsi/src/q_thread.c index 283d724..1aa0419 100644 --- a/src/core/ddsi/src/q_thread.c +++ b/src/core/ddsi/src/q_thread.c @@ -56,6 +56,13 @@ static void os_free_aligned ( _Pre_maybenull_ _Post_invalid_ void *ptr) } } +void thread_states_init_static (void) +{ + static struct thread_state1 ts = + { .state = THREAD_STATE_ALIVE, .vtime = 1, .watchdog = 1, .lb = NULL, .name = "(anon)" }; + tsd_thread_state = &ts; +} + void thread_states_init (_In_ unsigned maxthreads) { unsigned i; @@ -324,7 +331,7 @@ void downgrade_main_thread (void) logbuf_free (ts1->lb); /* no need to sync with service lease: already stopped */ reap_thread_state (ts1, 0); - tsd_thread_state = NULL; + thread_states_init_static (); } struct thread_state1 *get_thread_state (_In_ os_threadId id)