mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-03 06:41:14 -03:00
Remove return value from iothread_perform
It was not actually used by any test.
This commit is contained in:
@@ -885,24 +885,16 @@ static void test_iothread() {
|
||||
say(L"Testing iothreads");
|
||||
std::unique_ptr<std::atomic<int>> int_ptr = make_unique<std::atomic<int>>(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() {
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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<void(void)> &&func, std::function<void(void)> &&completion,
|
||||
bool cant_wait = false);
|
||||
void iothread_perform_impl(std::function<void()> &&func, std::function<void()> &&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<Handler, Completion, void> {
|
||||
iothread_trampoline_t(std::function<void()> hand, std::function<void()> comp)
|
||||
: handler(std::move(hand)), completion(std::move(comp)) {}
|
||||
|
||||
// The generated handler and completion functions.
|
||||
// The handler and completion functions.
|
||||
std::function<void()> handler;
|
||||
std::function<void()> completion;
|
||||
};
|
||||
@@ -72,32 +59,32 @@ struct iothread_trampoline_t<Handler, Completion, void> {
|
||||
// In other words, this is like Completion(Handler()) except the handler part is invoked
|
||||
// on a background thread.
|
||||
template <typename Handler, typename Completion>
|
||||
int iothread_perform(const Handler &handler, const Completion &completion) {
|
||||
void iothread_perform(const Handler &handler, const Completion &completion) {
|
||||
iothread_trampoline_t<Handler, Completion> 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<void(void)> &&func) {
|
||||
return iothread_perform_impl(std::move(func), {});
|
||||
inline void iothread_perform(std::function<void()> &&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<void(void)> &&func) {
|
||||
return iothread_perform_impl(std::move(func), {}, true);
|
||||
inline void iothread_perform_cantwait(std::function<void()> &&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<void(void)> &&func);
|
||||
void iothread_perform_on_main(std::function<void()> &&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<void(void)> &&func);
|
||||
bool make_detached_pthread(std::function<void()> &&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 <typename Handler, typename Completion>
|
||||
uint64_t perform(Handler handler, Completion completion) {
|
||||
void perform(Handler handler, Completion completion) {
|
||||
iothread_trampoline_t<Handler, Completion> 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.
|
||||
|
||||
Reference in New Issue
Block a user