summaryrefslogtreecommitdiff
path: root/libc/src/stdlib/atexit.cpp
diff options
context:
space:
mode:
authorJoseph Huber <huberjn@outlook.com>2024-02-23 14:10:53 -0600
committerGitHub <noreply@github.com>2024-02-23 14:10:53 -0600
commita3a316e2875258929f062fbffb81e2a9d5b4ce48 (patch)
tree241e5eacd906f68c40eadb820f74801e8a92dff8 /libc/src/stdlib/atexit.cpp
parent6dd6d487d012a9000fe975133b7935c1f8c658eb (diff)
[libc] Remove use of BlockStore for GPU atexit (#82823)
Summary: The GPU backends have restrictions on the kinds of initializers they can produce. The use of BlockStore here currently breaks the backends through the use of recursive initializers. This prevents it from actually being included in any builds. This patchs changes it to just use a fixed size of 64 slots .The chances of someone exceeding the 64 slots in practice is very, very low. However, this is primarily a bandaid solution as a real solution will need to use a lock free data structure to push work in parallel. Currently the mutexes on the GPU build do nothing, so they only work if the user guards the use themselves.
Diffstat (limited to 'libc/src/stdlib/atexit.cpp')
-rw-r--r--libc/src/stdlib/atexit.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/libc/src/stdlib/atexit.cpp b/libc/src/stdlib/atexit.cpp
index 10dff42b1be9..1513b7969f0d 100644
--- a/libc/src/stdlib/atexit.cpp
+++ b/libc/src/stdlib/atexit.cpp
@@ -28,7 +28,14 @@ struct AtExitUnit {
constexpr AtExitUnit(AtExitCallback *c, void *p) : callback(c), payload(p) {}
};
-#ifdef LIBC_COPT_PUBLIC_PACKAGING
+#if defined(LIBC_TARGET_ARCH_IS_GPU)
+// The GPU build cannot handle the potentially recursive definitions required by
+// the BlockStore class. Additionally, the liklihood that someone exceeds this
+// while executing on the GPU is extremely small.
+// FIXME: It is not generally safe to use 'atexit' on the GPU because the
+// mutexes simply passthrough. We will need a lock free stack.
+using ExitCallbackList = FixedVector<AtExitUnit, 64>;
+#elif defined(LIBC_COPT_PUBLIC_PACKAGING)
using ExitCallbackList = cpp::ReverseOrderBlockStore<AtExitUnit, 32>;
#else
// BlockStore uses dynamic memory allocation. To avoid dynamic memory