trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: For atscppapi::AsyncTimer, pass the thread pool for execution to the constructor, rather than always using the default thread pool.
Date Mon, 18 Jun 2018 19:47:06 GMT
This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 305fb1e  For atscppapi::AsyncTimer, pass the thread pool for execution to the constructor,
rather than always using the default thread pool.
305fb1e is described below

commit 305fb1e93f8245f27f037cd52a7f9d4262e27488
Author: Walter Karas <wkaras@oath.com>
AuthorDate: Mon Jun 18 11:32:56 2018 -0500

    For atscppapi::AsyncTimer, pass the thread pool for execution to the constructor, rather
than always using the default thread pool.
---
 lib/cppapi/AsyncTimer.cc                  | 19 ++++++++++++-------
 lib/cppapi/include/atscppapi/AsyncTimer.h | 13 ++++++++++++-
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/lib/cppapi/AsyncTimer.cc b/lib/cppapi/AsyncTimer.cc
index cc44699..a0cc755 100644
--- a/lib/cppapi/AsyncTimer.cc
+++ b/lib/cppapi/AsyncTimer.cc
@@ -30,12 +30,17 @@ struct atscppapi::AsyncTimerState {
   AsyncTimer::Type type_;
   int period_in_ms_;
   int initial_period_in_ms_;
+  TSThreadPool thread_pool_;
   TSAction initial_timer_action_  = nullptr;
   TSAction periodic_timer_action_ = nullptr;
   AsyncTimer *timer_              = nullptr;
   std::shared_ptr<AsyncDispatchControllerBase> dispatch_controller_{};
-  AsyncTimerState(AsyncTimer::Type type, int period_in_ms, int initial_period_in_ms, AsyncTimer
*timer)
-    : type_(type), period_in_ms_(period_in_ms), initial_period_in_ms_(initial_period_in_ms),
timer_(timer)
+  AsyncTimerState(AsyncTimer::Type type, int period_in_ms, int initial_period_in_ms, TSThreadPool
thread_pool, AsyncTimer *timer)
+    : type_(type),
+      period_in_ms_(period_in_ms),
+      initial_period_in_ms_(initial_period_in_ms),
+      thread_pool_(thread_pool),
+      timer_(timer)
   {
   }
 };
@@ -51,7 +56,7 @@ handleTimerEvent(TSCont cont, TSEvent event, void *edata)
     state->initial_timer_action_ = nullptr; // mark it so that it won't be canceled later
on
     if (state->type_ == AsyncTimer::TYPE_PERIODIC) {
       LOG_DEBUG("Scheduling periodic event now");
-      state->periodic_timer_action_ = TSContScheduleEvery(state->cont_, state->period_in_ms_,
TS_THREAD_POOL_DEFAULT);
+      state->periodic_timer_action_ = TSContScheduleEvery(state->cont_, state->period_in_ms_,
state->thread_pool_);
     }
   }
   if (!state->dispatch_controller_->dispatch()) {
@@ -62,9 +67,9 @@ handleTimerEvent(TSCont cont, TSEvent event, void *edata)
 }
 } // namespace
 
-AsyncTimer::AsyncTimer(Type type, int period_in_ms, int initial_period_in_ms)
+AsyncTimer::AsyncTimer(Type type, int period_in_ms, int initial_period_in_ms, TSThreadPool
thread_pool)
 {
-  state_        = new AsyncTimerState(type, period_in_ms, initial_period_in_ms, this);
+  state_        = new AsyncTimerState(type, period_in_ms, initial_period_in_ms, thread_pool,
this);
   state_->cont_ = TSContCreate(handleTimerEvent, TSMutexCreate());
   TSContDataSet(state_->cont_, static_cast<void *>(state_));
 }
@@ -83,10 +88,10 @@ AsyncTimer::run()
   }
   if (one_off_timeout_in_ms) {
     LOG_DEBUG("Scheduling initial/one-off event");
-    state_->initial_timer_action_ = TSContSchedule(state_->cont_, one_off_timeout_in_ms,
TS_THREAD_POOL_DEFAULT);
+    state_->initial_timer_action_ = TSContSchedule(state_->cont_, one_off_timeout_in_ms,
state_->thread_pool_);
   } else if (regular_timeout_in_ms) {
     LOG_DEBUG("Scheduling regular timer events");
-    state_->periodic_timer_action_ = TSContScheduleEvery(state_->cont_, regular_timeout_in_ms,
TS_THREAD_POOL_DEFAULT);
+    state_->periodic_timer_action_ = TSContScheduleEvery(state_->cont_, regular_timeout_in_ms,
state_->thread_pool_);
   }
 }
 
diff --git a/lib/cppapi/include/atscppapi/AsyncTimer.h b/lib/cppapi/include/atscppapi/AsyncTimer.h
index c8308de..3a02458 100644
--- a/lib/cppapi/include/atscppapi/AsyncTimer.h
+++ b/lib/cppapi/include/atscppapi/AsyncTimer.h
@@ -24,6 +24,7 @@
 
 #include <string>
 #include <memory>
+#include <ts/ts.h>
 #include <atscppapi/Async.h>
 #include <atscppapi/Request.h>
 #include <atscppapi/Response.h>
@@ -60,8 +61,18 @@ public:
    *                             events will have "regular" cadence. This is useful if the
timer is
    *                             set for a long period of time (1hr etc.), but an initial
event is
    *                             required. Value of 0 (default) indicates no initial event
is desired.
+   * @param thread_pool Thread pool to execute timer action in.
    */
-  AsyncTimer(Type type, int period_in_ms, int initial_period_in_ms = 0);
+  AsyncTimer(Type type, int period_in_ms, int initial_period_in_ms, TSThreadPool thread_pool);
+
+  // For convenience, additional constructor prototypes.
+
+  AsyncTimer(Type type, int period_in_ms, int initial_period_in_ms = 0)
+    : AsyncTimer(type, period_in_ms, initial_period_in_ms, TS_THREAD_POOL_DEFAULT)
+  {
+  }
+
+  AsyncTimer(Type type, int period_in_ms, TSThreadPool thread_pool) : AsyncTimer(type, period_in_ms,
0, thread_pool) {}
 
   ~AsyncTimer() override;
 

-- 
To stop receiving notification emails like this one, please contact
amc@apache.org.

Mime
View raw message