@@ -39,13 +39,18 @@ StaticSingleThreadedExecutor::spin()
39
39
// except we need to keep the wait result to reproduce the StaticSingleThreadedExecutor
40
40
// behavior.
41
41
while (rclcpp::ok (this ->context_ ) && spinning.load ()) {
42
- this ->spin_once_impl (std::chrono::nanoseconds (- 1 ) );
42
+ return this ->spin_some_impl (std::chrono::nanoseconds (0 ), true );
43
43
}
44
44
}
45
45
46
46
void
47
47
StaticSingleThreadedExecutor::spin_some (std::chrono::nanoseconds max_duration)
48
48
{
49
+ if (spinning.exchange (true )) {
50
+ throw std::runtime_error (" spin_some() called while already spinning" );
51
+ }
52
+ RCPPUTILS_SCOPE_EXIT (this ->spinning .store (false ););
53
+
49
54
// In this context a 0 input max_duration means no duration limit
50
55
if (std::chrono::nanoseconds (0 ) == max_duration) {
51
56
max_duration = std::chrono::nanoseconds::max ();
@@ -56,6 +61,11 @@ StaticSingleThreadedExecutor::spin_some(std::chrono::nanoseconds max_duration)
56
61
void
57
62
StaticSingleThreadedExecutor::spin_all (std::chrono::nanoseconds max_duration)
58
63
{
64
+ if (spinning.exchange (true )) {
65
+ throw std::runtime_error (" spin_some() called while already spinning" );
66
+ }
67
+ RCPPUTILS_SCOPE_EXIT (this ->spinning .store (false ););
68
+
59
69
if (max_duration < std::chrono::nanoseconds (0 )) {
60
70
throw std::invalid_argument (" max_duration must be greater than or equal to 0" );
61
71
}
@@ -72,11 +82,6 @@ StaticSingleThreadedExecutor::spin_some_impl(std::chrono::nanoseconds max_durati
72
82
return spin_forever || (cur_duration < max_duration);
73
83
};
74
84
75
- if (spinning.exchange (true )) {
76
- throw std::runtime_error (" spin_some() called while already spinning" );
77
- }
78
- RCPPUTILS_SCOPE_EXIT (this ->spinning .store (false ););
79
-
80
85
while (rclcpp::ok (context_) && spinning.load () && max_duration_not_elapsed ()) {
81
86
// Get executables that are ready now
82
87
std::lock_guard<std::mutex> guard (mutex_);
0 commit comments