tid = get_signaled_thread (pid);
if (tid != 0)
- thread = iterate_over_threads ([&] (struct thread_info *thread)
+ thread = find_thread ([&] (thread_info *thread)
{
return thread->ptid.lwp () == tid;
});
event-top.c won't do anything, and temporary breakpoints with
commands won't work. */
- iterate_over_threads ([&] (struct thread_info *th)
+ for_each_thread ([&] (struct thread_info *th)
{
bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
- return false;
});
/* Now that breakpoint is removed from breakpoint list, update the
signalled_thr = curr_thr;
else
{
- signalled_thr = iterate_over_threads (find_signalled_thread);
+ signalled_thr = find_thread (find_signalled_thread);
if (signalled_thr == NULL)
signalled_thr = curr_thr;
}
void thread_change_ptid (process_stratum_target *targ,
ptid_t old_ptid, ptid_t new_ptid);
-/* Iterator function to call a user-provided callback function
- once for each known thread. */
-typedef gdb::function_view<bool (struct thread_info *)> thread_callback_func;
-extern struct thread_info *iterate_over_threads (thread_callback_func);
+/* Callback function type for function for_each_thread. */
+
+using for_each_thread_callback_ftype
+ = gdb::function_view<void (thread_info *)>;
+
+/* Call CALLBACK once for each known thread. */
+
+extern void for_each_thread (for_each_thread_callback_ftype callback);
+
+/* Callback function type for function find_thread. */
+
+using find_thread_callback_ftype = gdb::function_view<bool (thread_info *)>;
+
+/* Return the first thread for which CALLBACK returns true, or nullptr if
+ there is no such thread. */
+
+extern struct thread_info *find_thread (find_thread_callback_ftype callback);
/* Pull in the internals of the inferiors/threads ranges and
iterators. Must be done after struct thread_info is defined. */
run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN);
}
-static bool
+static void
proceed_thread_callback (struct thread_info *thread)
{
/* We go through all threads individually instead of compressing
way to tell the target `hold this thread stopped until I say
otherwise', then we can optimize this. */
if (thread->state () != THREAD_STOPPED)
- return false;
+ return;
if (!thread->inf->has_execution ())
- return false;
+ return;
switch_to_thread (thread);
clear_proceed_status (0);
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
- return false;
}
static void
scoped_disable_commit_resumed disable_commit_resumed
("continue all threads in non-stop");
- iterate_over_threads (proceed_thread_callback);
+ for_each_thread (proceed_thread_callback);
if (current_ui->prompt_state == PROMPT_BLOCKED)
{
}
}
-/* Callback for iterate_over_threads. Find a resumed thread that has
+/* Callback for find_thread. Find a resumed thread that has
a pending waitstatus. */
static bool
if (ecs->ws.kind () == TARGET_WAITKIND_THREAD_EXITED)
return 0;
- pending = iterate_over_threads (resumed_thread_with_pending_status);
+ pending = find_thread (resumed_thread_with_pending_status);
if (pending != nullptr)
{
struct thread_info *tp = ecs->event_thread;
pid = inf->pid;
}
- iterate_over_threads ([&] (struct thread_info *thread)
+ for_each_thread ([&] (struct thread_info *thread)
{
proceed_thread (thread, pid);
- return false;
});
disable_commit_resumed.reset_and_commit ();
}
scoped_disable_commit_resumed disable_commit_resumed
("interrupting all threads of thread group");
- iterate_over_threads ([&] (struct thread_info *thread)
+ for_each_thread ([&] (struct thread_info *thread)
{
if (thread->state () != THREAD_RUNNING)
- return false;
+ return;
if (thread->ptid.pid () != inf->pid)
- return false;
+ return;
target_stop (thread->ptid);
- return false;
});
}
else
/* Pick any thread in the desired process. Current
target_detach detaches from the parent of inferior_ptid. */
- tp = iterate_over_threads ([&] (struct thread_info *ti)
+ tp = find_thread ([&] (struct thread_info *ti)
{
return ti->ptid.pid () == pid && ti->state () != THREAD_EXITED;
});
if (inferior->pid != 0)
{
- iterate_over_threads ([&] (struct thread_info *ti)
+ for_each_thread ([&] (struct thread_info *ti)
{
if (ti->ptid.pid () == inferior->pid)
{
if (core != -1)
cores.insert (core);
}
- return false;
});
}
descriptors for the parent process, but discard any file
descriptors we may have accumulated for the threads.
- As this function is called by iterate_over_threads, it always
- returns zero (so that iterate_over_threads will keep
+ As this function is called by proc_iterate_over_threads, it always
+ returns zero (so that proc_iterate_over_threads will keep
iterating). */
static int
static enum gdb_signal
find_stop_signal (void)
{
- struct thread_info *info = iterate_over_threads (find_signalled_thread);
+ struct thread_info *info = find_thread (find_signalled_thread);
if (info)
return info->stop_signal ();
};
struct thread_info *thread_info
- = iterate_over_threads (thread_db_find_thread_from_tid);
+ = find_thread (thread_db_find_thread_from_tid);
if (thread_info == NULL)
{
/* The list of threads is probably not up to date. Find any
thread that is missing from the list, and try again. */
update_thread_list ();
- thread_info = iterate_over_threads (thread_db_find_thread_from_tid);
+ thread_info = find_thread (thread_db_find_thread_from_tid);
}
gdb_assert (thread_info != NULL);
inf);
}
-/*
- * Thread iterator function.
- *
- * Calls a callback function once for each thread, so long as
- * the callback function returns false. If the callback function
- * returns true, the iteration will end and the current thread
- * will be returned. This can be useful for implementing a
- * search for a thread with arbitrary attributes, or for applying
- * some operation to every thread.
- *
- * FIXME: some of the existing functionality, such as
- * "Thread apply all", might be rewritten using this functionality.
- */
+/* See gdbthread.h. */
+
+void
+for_each_thread (for_each_thread_callback_ftype callback)
+{
+ for (thread_info &tp : all_threads_safe ())
+ callback (&tp);
+}
+
+/* See gdbthread.h. */
struct thread_info *
-iterate_over_threads (gdb::function_view<bool (struct thread_info *)> callback)
+find_thread (find_thread_callback_ftype callback)
{
for (thread_info &tp : all_threads_safe ())
if (callback (&tp))
return &tp;
- return NULL;
+ return nullptr;
}
/* See gdbthread.h. */