Skip to content

Commit 4aa6d44

Browse files
committed
Refs #23069. Cancel requests before terminating thread pool.
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 352dbbd commit 4aa6d44

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/main/java/com/eprosima/fastdds/idl/templates/ServerSource.stg

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,21 @@ public:
171171

172172
void stop() override
173173
{
174+
// Notify all threads to finish
174175
finish_condition_.set_trigger_value(true);
175-
thread_pool_.stop();
176176

177-
std::lock_guard<std::mutex> _(mtx_);
178-
// TODO: Cancel all pending requests
179-
processing_requests_.clear();
177+
// Cancel all pending requests
178+
{
179+
std::lock_guard<std::mutex> _(mtx_);
180+
for (auto& it : processing_requests_)
181+
{
182+
it.second->cancel();
183+
}
184+
processing_requests_.clear();
185+
}
186+
187+
// Wait for all threads to finish
188+
thread_pool_.stop();
180189
}
181190

182191
private:
@@ -198,6 +207,7 @@ private:
198207
virtual ~IInputFeedProcessor() = default;
199208
virtual bool process_additional_request(
200209
const RequestType& request) = 0;
210+
virtual void cancel_input_feed() = 0;
201211
};
202212

203213
//} Input feed helpers
@@ -308,6 +318,21 @@ $endif$
308318
replier->send_reply(&reply, info);
309319
}
310320

321+
void cancel()
322+
{
323+
// Cancel output feed
324+
if (output_feed_cancellator_)
325+
{
326+
output_feed_cancellator_->cancel();
327+
}
328+
329+
// Cancel input feeds
330+
for (const auto& input_feed : input_feed_processors_)
331+
{
332+
input_feed->cancel_input_feed();
333+
}
334+
}
335+
311336
private:
312337

313338
std::shared_ptr<IOutputFeedCancellator> output_feed_cancellator_;
@@ -562,6 +587,13 @@ struct $op.name$_$param.name$_reader :
562587
return false;
563588
}
564589

590+
void cancel_input_feed() override
591+
{
592+
std::lock_guard<std::mutex> _(mtx_);
593+
finished_ = true;
594+
cv_.notify_all();
595+
}
596+
565597
bool read(
566598
$param.typecode.cppTypename$& value) override
567599
{

0 commit comments

Comments
 (0)