fix crashes when C++ global destructors call DDS code

- properly count invocations of os_osInit/os_osExit
- handle concurrent invocations of those
- provide a single mutex for use by dds_init
- eliminate use of atexit()
- attendant dds_init/dds_fini changes
- fix related crash in thread local storage cleanup

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2018-07-18 16:21:49 +02:00
parent 20d8ef6f0d
commit bfb5874373
12 changed files with 102 additions and 199 deletions

View file

@ -110,7 +110,7 @@ cleanup_thread_state(
assert(ts->state == THREAD_STATE_ALIVE);
assert(vtime_asleep_p(ts->vtime));
reset_thread_state(ts);
os_reportExit(); /* FIXME: Should not be here! */
os_osExit();
}
_Ret_valid_ struct thread_state1 *
@ -133,6 +133,7 @@ lookup_thread_state(
os_mutexLock(&thread_states.lock);
ts1 = init_thread_state(tname);
if (ts1 != NULL) {
os_osInit();
ts1->lb = 0;
ts1->extTid = tid;
ts1->tid = tid;