[
https://issues.apache.org/jira/browse/THRIFT-4327?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16166034#comment-16166034
]
ASF GitHub Bot commented on THRIFT-4327:
----------------------------------------
Github user Typz commented on a diff in the pull request:
https://github.com/apache/thrift/pull/1353#discussion_r138849560
--- Diff: lib/cpp/test/concurrency/TimerManagerTests.h ---
@@ -192,6 +192,38 @@ class TimerManagerTests {
return true;
}
+ /**
+ * This test creates two tasks, removes the first one then waits for the
second one. It then
+ * verifies that the timer manager properly clean up itself and the
remaining orphaned timeout
+ * task when the manager goes out of scope and its destructor is called.
+ */
+ bool test03(int64_t timeout = 1000LL) {
+ TimerManager timerManager;
+ timerManager.threadFactory(shared_ptr<PlatformThreadFactory>(new
PlatformThreadFactory()));
+ timerManager.start();
+ assert(timerManager.state() == TimerManager::STARTED);
+
+ Synchronized s(_monitor);
+
+ // Setup the two tasks
+ shared_ptr<TimerManagerTests::Task> taskToRemove
+ = shared_ptr<TimerManagerTests::Task>(new
TimerManagerTests::Task(_monitor, timeout / 2));
+ TimerManager::Timer timer = timerManager.add(taskToRemove,
taskToRemove->_timeout);
+
+ shared_ptr<TimerManagerTests::Task> task
+ = shared_ptr<TimerManagerTests::Task>(new
TimerManagerTests::Task(_monitor, timeout));
+ timerManager.add(task, task->_timeout);
+
+ // Remove one task and wait until the other has completed
+ timerManager.remove(timer);
--- End diff --
Done
> Improve TimerManager API to allow removing specific task
> --------------------------------------------------------
>
> Key: THRIFT-4327
> URL: https://issues.apache.org/jira/browse/THRIFT-4327
> Project: Thrift
> Issue Type: Improvement
> Components: C++ - Library
> Reporter: Francois Ferrand
>
> The TimerManager::remove() method removes all timers with the specified
> callback, and does so by traversing the list of timers.
> This should be improved by returning a "handle" in `TimerManager::add`, and
> supporting efficiently removing a single timer from its handle:
> {code:java}
> class TimerManager {
> Timer add(shared_ptr<Runnable> task, const struct timeval& value);
> void remove(Timer t);
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)