Commit | Line | Data |
---|---|---|
243a9253 PA |
1 | /* Thread command's finish-state machine, for GDB, the GNU debugger. |
2 | Copyright (C) 2015 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include "defs.h" | |
20 | #include "thread-fsm.h" | |
21 | ||
22 | /* See thread-fsm.h. */ | |
23 | ||
24 | void | |
25 | thread_fsm_ctor (struct thread_fsm *self, struct thread_fsm_ops *ops) | |
26 | { | |
27 | self->finished = 0; | |
28 | self->ops = ops; | |
29 | } | |
30 | ||
31 | /* See thread-fsm.h. */ | |
32 | ||
33 | void | |
34 | thread_fsm_delete (struct thread_fsm *self) | |
35 | { | |
36 | if (self != NULL) | |
37 | { | |
38 | if (self->ops->dtor != NULL) | |
39 | self->ops->dtor (self); | |
40 | xfree (self); | |
41 | } | |
42 | } | |
43 | ||
44 | /* See thread-fsm.h. */ | |
45 | ||
46 | void | |
47 | thread_fsm_clean_up (struct thread_fsm *self) | |
48 | { | |
49 | if (self->ops->clean_up != NULL) | |
50 | self->ops->clean_up (self); | |
51 | } | |
52 | ||
53 | /* See thread-fsm.h. */ | |
54 | ||
55 | int | |
56 | thread_fsm_should_stop (struct thread_fsm *self) | |
57 | { | |
58 | return self->ops->should_stop (self); | |
59 | } | |
60 | ||
61 | /* See thread-fsm.h. */ | |
62 | ||
63 | struct return_value_info * | |
64 | thread_fsm_return_value (struct thread_fsm *self) | |
65 | { | |
66 | if (self->ops->return_value != NULL) | |
67 | return self->ops->return_value (self); | |
68 | return NULL; | |
69 | } | |
70 | ||
71 | /* See thread-fsm.h. */ | |
72 | ||
73 | void | |
74 | thread_fsm_set_finished (struct thread_fsm *self) | |
75 | { | |
76 | self->finished = 1; | |
77 | } | |
78 | ||
79 | /* See thread-fsm.h. */ | |
80 | ||
81 | int | |
82 | thread_fsm_finished_p (struct thread_fsm *self) | |
83 | { | |
84 | return self->finished; | |
85 | } | |
86 | ||
87 | /* See thread-fsm.h. */ | |
88 | ||
89 | enum async_reply_reason | |
90 | thread_fsm_async_reply_reason (struct thread_fsm *self) | |
91 | { | |
92 | /* If we didn't finish, then the stop reason must come from | |
93 | elsewhere. E.g., a breakpoint hit or a signal intercepted. */ | |
94 | gdb_assert (thread_fsm_finished_p (self)); | |
95 | ||
96 | return self->ops->async_reply_reason (self); | |
97 | } | |
388a7084 PA |
98 | |
99 | /* See thread-fsm.h. */ | |
100 | ||
101 | int | |
102 | thread_fsm_should_notify_stop (struct thread_fsm *self) | |
103 | { | |
104 | if (self->ops->should_notify_stop != NULL) | |
105 | return self->ops->should_notify_stop (self); | |
106 | return 1; | |
107 | } |