Fix building Loongarch BFD with a 32-bit compiler
[binutils-gdb.git] / gdbsupport / task-group.h
blobb1d287ad78dc0fbdb0fdac425668d408e74fe02c
1 /* Task group
3 Copyright (C) 2023-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef GDBSUPPORT_TASK_GROUP_H
21 #define GDBSUPPORT_TASK_GROUP_H
23 #include <memory>
25 namespace gdb
28 /* A task group is a collection of tasks. Each task in the group is
29 submitted to the thread pool. When all the tasks in the group have
30 finished, a final action is run. */
32 class task_group
34 public:
36 explicit task_group (std::function<void ()> &&done);
37 DISABLE_COPY_AND_ASSIGN (task_group);
39 /* Add a task to the task group. All tasks must be added before the
40 group is started. Note that a task may not throw an
41 exception. */
42 void add_task (std::function<void ()> &&task);
44 /* Start this task group. A task group may only be started once.
45 This will submit all the tasks to the global thread pool. */
46 void start ();
48 private:
50 class impl;
52 /* A task group is just a facade around an impl. This is done
53 because the impl object must live as long as its longest-lived
54 task, so it is heap-allocated and destroyed when the last task
55 completes. */
56 std::shared_ptr<impl> m_task;
59 } /* namespace gdb */
61 #endif /* GDBSUPPORT_TASK_GROUP_H */