diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index f1860afe1..68b69cb20 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -885,24 +885,16 @@ static void test_iothread() { say(L"Testing iothreads"); std::unique_ptr> int_ptr = make_unique>(0); int iterations = 64; - int max_achieved_thread_count = 0; - double start = timef(); for (int i = 0; i < iterations; i++) { - int thread_count = iothread_perform([&]() { test_iothread_thread_call(int_ptr.get()); }); - max_achieved_thread_count = std::max(max_achieved_thread_count, thread_count); + iothread_perform([&]() { test_iothread_thread_call(int_ptr.get()); }); } - - // Now wait until we're done. iothread_drain_all(); - double end = timef(); // Should have incremented it once per thread. + do_test(*int_ptr == iterations); if (*int_ptr != iterations) { say(L"Expected int to be %d, but instead it was %d", iterations, int_ptr->load()); } - - say(L" (%.02f msec, with max of %d threads)", (end - start) * 1000.0, - max_achieved_thread_count); } static void test_pthread() { diff --git a/src/iothread.cpp b/src/iothread.cpp index ab6504971..cabf23b53 100644 --- a/src/iothread.cpp +++ b/src/iothread.cpp @@ -278,10 +278,10 @@ int thread_pool_t::perform(void_function_t &&func, void_function_t &&completion, return local_thread_count; } -int iothread_perform_impl(void_function_t &&func, void_function_t &&completion, bool cant_wait) { +void iothread_perform_impl(void_function_t &&func, void_function_t &&completion, bool cant_wait) { ASSERT_IS_MAIN_THREAD(); ASSERT_IS_NOT_FORKED_CHILD(); - return s_io_thread_pool.perform(std::move(func), std::move(completion), cant_wait); + s_io_thread_pool.perform(std::move(func), std::move(completion), cant_wait); } int iothread_port() { return get_notify_pipes().read; } diff --git a/src/iothread.h b/src/iothread.h index a669bd379..92430dfa1 100644 --- a/src/iothread.h +++ b/src/iothread.h @@ -11,32 +11,19 @@ #include "maybe.h" -/// Runs a command on a thread. -/// -/// \param handler The function to execute on a background thread. Accepts an arbitrary context -/// pointer, and returns an int, which is passed to the completionCallback. -/// \param completionCallback The function to execute on the main thread once the background thread -/// is complete. Accepts an int (the return value of handler) and the context. -/// \param context An arbitrary context pointer to pass to the handler and completion callback. -/// \return A sequence number, currently not very useful. -int iothread_perform_base(int (*handler)(void *), void (*completionCallback)(void *, int), - void *context); - -/// Gets the fd on which to listen for completion callbacks. -/// -/// \return A file descriptor on which to listen for completion callbacks. -int iothread_port(void); +/// \return the fd on which to listen for completion callbacks. +int iothread_port(); /// Services one iothread completion callback. -void iothread_service_completion(void); +void iothread_service_completion(); /// Waits for all iothreads to terminate. /// \return the number of threads that were running. -int iothread_drain_all(void); +int iothread_drain_all(); // Internal implementation -int iothread_perform_impl(std::function &&func, std::function &&completion, - bool cant_wait = false); +void iothread_perform_impl(std::function &&func, std::function &&completion, + bool cant_wait = false); // This is the glue part of the handler-completion handoff. // Given a Handler and Completion, where the return value of Handler should be passed to Completion, @@ -62,7 +49,7 @@ struct iothread_trampoline_t { iothread_trampoline_t(std::function hand, std::function comp) : handler(std::move(hand)), completion(std::move(comp)) {} - // The generated handler and completion functions. + // The handler and completion functions. std::function handler; std::function completion; }; @@ -72,32 +59,32 @@ struct iothread_trampoline_t { // In other words, this is like Completion(Handler()) except the handler part is invoked // on a background thread. template -int iothread_perform(const Handler &handler, const Completion &completion) { +void iothread_perform(const Handler &handler, const Completion &completion) { iothread_trampoline_t tramp(handler, completion); - return iothread_perform_impl(std::move(tramp.handler), std::move(tramp.completion)); + iothread_perform_impl(std::move(tramp.handler), std::move(tramp.completion)); } // variant of iothread_perform without a completion handler -inline int iothread_perform(std::function &&func) { - return iothread_perform_impl(std::move(func), {}); +inline void iothread_perform(std::function &&func) { + iothread_perform_impl(std::move(func), {}); } /// Variant of iothread_perform that disrespects the thread limit. /// It does its best to spawn a new thread if all other threads are occupied. /// This is for cases where deferring a new thread might lead to deadlock. -inline int iothread_perform_cantwait(std::function &&func) { - return iothread_perform_impl(std::move(func), {}, true); +inline void iothread_perform_cantwait(std::function &&func) { + iothread_perform_impl(std::move(func), {}, true); } /// Performs a function on the main thread, blocking until it completes. -void iothread_perform_on_main(std::function &&func); +void iothread_perform_on_main(std::function &&func); /// Creates a pthread, manipulating the signal mask so that the thread receives no signals. /// The thread is detached. /// The pthread runs \p func. /// \returns true on success, false on failure. bool make_detached_pthread(void *(*func)(void *), void *param); -bool make_detached_pthread(std::function &&func); +bool make_detached_pthread(std::function &&func); /// \returns a thread ID for this thread. /// Thread IDs are never repeated. @@ -114,9 +101,9 @@ class debounce_t { /// function will not execute. /// This returns the active thread token, which is only of interest to tests. template - uint64_t perform(Handler handler, Completion completion) { + void perform(Handler handler, Completion completion) { iothread_trampoline_t tramp(handler, completion); - return perform_impl(std::move(tramp.handler), std::move(tramp.completion)); + perform_impl(std::move(tramp.handler), std::move(tramp.completion)); } /// One-argument form with no completion.