qemu-e2k/util
Peter Maydell a458774ad7 util/qemu-thread-posix: Fix qemu_thread_atexit* for OSX
Our current implementation of qemu_thread_atexit* is broken on OSX.
This is because it works by cerating a piece of thread-specific
data with pthread_key_create() and using the destructor function
for that data to run the notifier function passed to it by
the caller of qemu_thread_atexit_add(). The expected use case
is that the caller uses a __thread variable as the notifier,
and uses the callback to clean up information that it is
keeping per-thread in __thread variables.

Unfortunately, on OSX this does not work, because on OSX
a __thread variable may be destroyed (freed) before the
pthread_key_create() destructor runs. (POSIX imposes no
ordering constraint here; the OSX implementation happens
to implement __thread variables in terms of pthread_key_create((),
whereas Linux uses different mechanisms that mean the __thread
variables will still be present when the pthread_key_create()
destructor is run.)

Fix this by switching to a scheme similar to the one qemu-thread-win32
uses for qemu_thread_atexit: keep the thread's notifiers on a
__thread variable, and run the notifiers on calls to
qemu_thread_exit() and on return from the start routine passed
to qemu_thread_start(). We do this with the pthread_cleanup_push()
API.

We take advantage of the qemu_thread_atexit_add() API
permission not to run thread notifiers on process exit to
avoid having to special case the main thread.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20181105135538.28025-3-peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-11-06 21:35:06 +01:00
..
Makefile.objs util: add atomic64 2018-10-02 18:47:55 +02:00
acl.c
aio-posix.c util: aio-posix: fix a typo 2018-10-29 13:35:22 +00:00
aio-wait.c block: Use a single global AioWait 2018-09-25 15:50:15 +02:00
aio-win32.c
aiocb.c
async.c util/async: use qemu_aio_coroutine_enter in co_schedule_bh_cb 2018-09-25 15:50:15 +02:00
atomic64.c util: add atomic64 2018-10-02 18:47:55 +02:00
base64.c
bitmap.c
bitops.c
buffer.c
bufferiszero.c
cacheinfo.c util: add atomic64 2018-10-02 18:47:55 +02:00
compatfd.c
coroutine-sigaltstack.c
coroutine-ucontext.c
coroutine-win32.c
crc32c.c
cutils.c cutils: add qemu_pstrcmp0() 2018-10-05 16:14:22 +04:00
drm.c util: promote qemu_egl_rendernode_open() to libqemuutil 2018-08-27 10:51:44 +02:00
envlist.c
error.c error: Fix use of error_prepend() with &error_fatal, &error_abort 2018-10-19 14:51:34 +02:00
event_notifier-posix.c
event_notifier-win32.c
fifo8.c
getauxval.c
hbitmap.c bitmap: Update count after a merge 2018-10-29 16:23:17 -04:00
hexdump.c
host-utils.c
id.c
iohandler.c
iov.c
iova-tree.c
keyval.c
lockcnt.c
log.c
main-loop.c
memfd.c hostmem-memfd: add checks before adding hostmem-memfd & properties 2018-10-02 18:47:55 +02:00
mmap-alloc.c
module.c module: Use QEMU_MODULE_DIR as a search path 2018-08-23 18:46:25 +02:00
notify.c
osdep.c
oslib-posix.c oslib-posix: Use MAP_STACK in qemu_alloc_stack() on OpenBSD 2018-11-06 10:52:23 +00:00
oslib-win32.c util: add qemu_write_pidfile() 2018-10-02 18:47:55 +02:00
pagesize.c
path.c
qdist.c
qemu-config.c
qemu-coroutine-io.c
qemu-coroutine-lock.c
qemu-coroutine-sleep.c
qemu-coroutine.c block: Add missing locking in bdrv_co_drain_bh_cb() 2018-09-25 15:50:15 +02:00
qemu-error.c error: Drop bogus "use error_setg() instead" admonitions 2018-10-19 15:47:09 +02:00
qemu-openpty.c
qemu-option.c option: Make option help nicer to read 2018-11-05 15:17:48 +01:00
qemu-progress.c
qemu-sockets.c
qemu-thread-common.h
qemu-thread-posix.c util/qemu-thread-posix: Fix qemu_thread_atexit* for OSX 2018-11-06 21:35:06 +01:00
qemu-thread-win32.c qsp: QEMU's Synchronization Profiler 2018-08-23 18:46:25 +02:00
qemu-timer-common.c
qemu-timer.c qemu-timer: avoid checkpoints for virtual clock timers in external subsystems 2018-10-19 13:44:03 +02:00
qht.c qht: constify arguments to some internal functions 2018-09-26 08:55:54 -07:00
qsp.c qsp: use atomic64 accessors 2018-10-02 18:47:55 +02:00
range.c
rcu.c
readline.c
stats64.c
sys_membarrier.c
systemd.c
thread-pool.c
throttle.c
timed-average.c
trace-events aio-posix: compute timeout before polling 2018-09-26 10:46:21 +08:00
unicode.c json: Reject invalid UTF-8 sequences 2018-08-24 20:26:37 +02:00
uri.c
uuid.c
vfio-helpers.c