Page MenuHomeFreeBSD

D41936.id127632.diff
No OneTemporary

D41936.id127632.diff

diff --git a/lib/libc/stdlib/quick_exit.c b/lib/libc/stdlib/quick_exit.c
--- a/lib/libc/stdlib/quick_exit.c
+++ b/lib/libc/stdlib/quick_exit.c
@@ -29,7 +29,6 @@
#include <sys/types.h>
#include <machine/atomic.h>
#include <stdlib.h>
-#include <pthread.h>
/**
* Linked list of quick exit handlers. This is simpler than the atexit()
@@ -42,11 +41,7 @@
};
/**
- * Lock protecting the handlers list.
- */
-static pthread_mutex_t atexit_mutex = PTHREAD_MUTEX_INITIALIZER;
-/**
- * Stack of cleanup handlers. These will be invoked in reverse order when
+ * Stack of cleanup handlers. These will be invoked in reverse order when
*/
static struct quick_exit_handler *handlers;
@@ -54,17 +49,17 @@
at_quick_exit(void (*func)(void))
{
struct quick_exit_handler *h;
-
- h = malloc(sizeof(*h));
+ int done;
+ h = malloc(sizeof(*h));
if (NULL == h)
return (1);
h->cleanup = func;
- pthread_mutex_lock(&atexit_mutex);
h->next = handlers;
- __compiler_membar();
- handlers = h;
- pthread_mutex_unlock(&atexit_mutex);
+ do {
+ done = atomic_fcmpset_rel_ptr((uintptr_t *)&handlers,
+ (uintptr_t *)&h->next, (uintptr_t)h);
+ } while (__predict_false(!done));
return (0);
}
@@ -77,8 +72,8 @@
* XXX: The C++ spec requires us to call std::terminate if there is an
* exception here.
*/
- for (h = handlers; NULL != h; h = h->next) {
- __compiler_membar();
+ h = (void *)atomic_load_acq_ptr((uintptr_t *)&handlers);
+ for (; NULL != h; h = h->next) {
h->cleanup();
}
_Exit(status);

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 2, 1:28 AM (9 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29132993
Default Alt Text
D41936.id127632.diff (1 KB)

Event Timeline