bindings c++: make it where spawning threads can't fail
extern "C" {
#include <errno.h>
+#include <base/assert.h>
#include <runtime/thread.h>
}
@@ -13,25 +14,23 @@ extern void ThreadTrampoline(void *arg);
} // namespace thread_internal
// Spawns a new thread by copying.
-static inline int ThreadSpawn(const std::function<void()>& func) {
+static inline void ThreadSpawn(const std::function<void()>& func) {
void *buf;
thread_t *th = thread_create_with_buf(thread_internal::ThreadTrampoline, &buf,
sizeof(std::function<void()>));
- if (!th) return -ENOMEM;
+ if (unlikely(!th)) BUG();
new(buf) std::function<void()>(func);
thread_ready(th);
- return 0;
}
// Spawns a new thread by moving.
-static inline int ThreadSpawn(std::function<void()>&& func) {
+static inline void ThreadSpawn(std::function<void()>&& func) {
void *buf;
thread_t *th = thread_create_with_buf(thread_internal::ThreadTrampoline, &buf,
sizeof(std::function<void()>));
- if (!th) return -ENOMEM;
+ if (unlikely(!th)) BUG();
new(buf) std::function<void()>(std::move(func));
thread_ready(th);
- return 0;
}
// Called from a running thread to exit.
