This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.1.x by this push:
new 0bc58d2 Revert "remove TSContSchedule, then rename
TSContScheduleOnPool to TSContSchedule"
0bc58d2 is described below
commit 0bc58d28412bdc58859431c9eaf3cefffd2acabb
Author: Leif Hedstrom <[email protected]>
AuthorDate: Wed Jan 27 19:58:42 2021 -0700
Revert "remove TSContSchedule, then rename TSContScheduleOnPool to
TSContSchedule"
This reverts commit cefe4826c919847385aa9d8459b9d5cfc20377f9.
This is an incompatible change, that can not go into 9.1.0. Reverting here,
on the 9.1.x branch, but it is still on master, and marked for 10.0.0.
---
doc/.tx/config | 6 +-
...uleEveryOnPool.en.rst => TSContSchedule.en.rst} | 28 +++----
...eOnThread.en.rst => TSContScheduleEvery.en.rst} | 23 +++---
.../api/functions/TSContScheduleOnPool.en.rst | 25 ++-----
.../api/functions/TSContScheduleOnThread.en.rst | 17 +----
.../api/functions/TSContThreadAffinitySet.en.rst | 4 +-
.../continuations/activating-continuations.en.rst | 2 +-
.../plugins/continuations/index.en.rst | 2 +-
.../continuations/writing-handler-functions.en.rst | 5 +-
...ntScheduleOnPool.en.po => TSContSchedule.en.po} | 10 +--
.../continuations/activating-continuations.en.po | 4 +-
.../plugins/continuations/index.en.po | 4 +-
.../continuations/writing-handler-functions.en.po | 8 +-
include/ts/ts.h | 2 +
src/traffic_server/InkAPI.cc | 63 ++++++++++++++++
tests/gold_tests/cont_schedule/gold/schedule.gold | 4 +
tests/gold_tests/cont_schedule/schedule.test.py | 49 ++++++++++++
tests/tools/plugins/cont_schedule.cc | 87 ++++++++++++++++++++--
18 files changed, 257 insertions(+), 86 deletions(-)
diff --git a/doc/.tx/config b/doc/.tx/config
index 65eedbc..3ea91b1 100644
--- a/doc/.tx/config
+++ b/doc/.tx/config
@@ -697,9 +697,9 @@ file_filter =
locale/<lang>/LC_MESSAGES/developer-guide/api/functions/TSContMute
source_file =
_build/locale/pot/developer-guide/api/functions/TSContMutexGet.en.pot
source_lang = en
-[apache-traffic-server-6x.developer-guide--api--functions--TSContScheduleOnPool_en]
-file_filter =
locale/<lang>/LC_MESSAGES/developer-guide/api/functions/TSContScheduleOnPool.en.po
-source_file =
_build/locale/pot/developer-guide/api/functions/TSContScheduleOnPool.en.pot
+[apache-traffic-server-6x.developer-guide--api--functions--TSContSchedule_en]
+file_filter =
locale/<lang>/LC_MESSAGES/developer-guide/api/functions/TSContSchedule.en.po
+source_file =
_build/locale/pot/developer-guide/api/functions/TSContSchedule.en.pot
source_lang = en
[apache-traffic-server-6x.developer-guide--api--functions--TSDebug_en]
diff --git a/doc/developer-guide/api/functions/TSContScheduleEveryOnPool.en.rst
b/doc/developer-guide/api/functions/TSContSchedule.en.rst
similarity index 56%
rename from doc/developer-guide/api/functions/TSContScheduleEveryOnPool.en.rst
rename to doc/developer-guide/api/functions/TSContSchedule.en.rst
index 0116395..4dbb9f6 100644
--- a/doc/developer-guide/api/functions/TSContScheduleEveryOnPool.en.rst
+++ b/doc/developer-guide/api/functions/TSContSchedule.en.rst
@@ -18,8 +18,8 @@
.. default-domain:: c
-TSContScheduleEveryOnPool
-*************************
+TSContSchedule
+**************
Synopsis
========
@@ -28,25 +28,24 @@ Synopsis
#include <ts/ts.h>
-.. function:: TSAction TSContScheduleEveryOnPool(TSCont contp, TSHRTime every)
+.. function:: TSAction TSContSchedule(TSCont contp, TSHRTime timeout)
Description
===========
-Schedules :arg:`contp` to run :arg:`every` milliseconds, on a random thread
that belongs to
-:arg:`tp`. The :arg:`every` is an approximation, meaning it will be at least
:arg:`every`
-milliseconds but possibly more. Resolutions finer than roughly 5 milliseconds
will not be
-effective. Note that :arg:`contp` is required to have a mutex, which is
provided to
+Schedules :arg:`contp` to run :arg:`delay` milliseconds in the future. This is
approximate. The delay
+will be at least :arg:`delay` but possibly more. Resolutions finer than
roughly 5 milliseconds will
+not be effective. :arg:`contp` is required to have a mutex, which is provided
to
:func:`TSContCreate`.
-The return value can be used to cancel the scheduled event via
:func:`TSActionCancel`. This
-is effective until the continuation :arg:`contp` is being dispatched. However,
if it is
-scheduled on another thread this can be problematic to be correctly timed. The
return value
-can be checked with :func:`TSActionDone` to see if the continuation ran before
the return,
-which is possible if :arg:`timeout` is `0`.
+The return value can be used to cancel the scheduled event via
:func:`TSActionCancel`. This is
+effective until the continuation :arg:`contp` is being dispatched. However, if
it is scheduled on
+another thread this can be problematic to be correctly timed. The return value
can be checked with
+:func:`TSActionDone` to see if the continuation ran before the return, which
is possible if
+:arg:`timeout` is `0`. Returns ``nullptr`` if thread affinity was cleared.
-If :arg:`contp` has no thread affinity set, the thread it is now scheduled on
will be set
-as its thread affinity thread.
+TSContSchedule() or TSContScheduleEvery() will default to set the thread
affinity to the calling thread
+when no affinity is already set for example, using
:func:`TSContThreadAffinitySet`
Note that the TSContSchedule() family of API shall only be called from an ATS
EThread.
Calling it from raw non-EThreads can result in unpredictable behavior.
@@ -54,5 +53,6 @@ Calling it from raw non-EThreads can result in unpredictable
behavior.
See Also
========
+:doc:`TSContScheduleEvery.en`
:doc:`TSContScheduleOnPool.en`
:doc:`TSContScheduleOnThread.en`
diff --git a/doc/developer-guide/api/functions/TSContScheduleOnThread.en.rst
b/doc/developer-guide/api/functions/TSContScheduleEvery.en.rst
similarity index 67%
copy from doc/developer-guide/api/functions/TSContScheduleOnThread.en.rst
copy to doc/developer-guide/api/functions/TSContScheduleEvery.en.rst
index 41148a9..bc61392 100644
--- a/doc/developer-guide/api/functions/TSContScheduleOnThread.en.rst
+++ b/doc/developer-guide/api/functions/TSContScheduleEvery.en.rst
@@ -18,8 +18,8 @@
.. default-domain:: c
-TSContScheduleOnThread
-**********************
+TSContScheduleEvery
+*******************
Synopsis
========
@@ -28,24 +28,24 @@ Synopsis
#include <ts/ts.h>
-.. function:: TSAction TSContScheduleOnThread(TSCont contp, TSHRTime timeout,
TSEventThread ethread)
+.. function:: TSAction TSContScheduleEvery(TSCont contp, TSHRTime every)
Description
===========
-Schedules :arg:`contp` to run :arg:`timeout` milliseconds in the future, on
the thread specified by
-:arg:`ethread`. The :arg:`timeout` is an approximation, meaning it will be at
least :arg:`timeout`
-milliseconds but possibly more. Resolutions finer than roughly 5 milliseconds
will not be effective.
-Note that :arg:`contp` is required to have a mutex, which is provided to
:func:`TSContCreate`.
+Schedules :arg:`contp` to periodically run every :arg:`delay` milliseconds in
the future.
+This is approximate. The delay will be at least :arg:`delay` but possibly more.
+Resolutions finer than roughly 5 milliseconds will not be effective.
:arg:`contp` is
+required to have a mutex, which is provided to :func:`TSContCreate`.
The return value can be used to cancel the scheduled event via
:func:`TSActionCancel`. This is
effective until the continuation :arg:`contp` is being dispatched. However, if
it is scheduled on
another thread this can be problematic to be correctly timed. The return value
can be checked with
:func:`TSActionDone` to see if the continuation ran before the return, which
is possible if
-:arg:`timeout` is `0`.
+:arg:`timeout` is `0`. Returns ``nullptr`` if thread affinity was cleared.
-If :arg:`contp` has no thread affinity set, the thread it is now scheduled on
will be set
-as its thread affinity thread.
+TSContSchedule() or TSContScheduleEvery() will default to set the thread
affinity to the calling thread
+when no affinity is already set for example, using
:func:`TSContThreadAffinitySet`
Note that the TSContSchedule() family of API shall only be called from an ATS
EThread.
Calling it from raw non-EThreads can result in unpredictable behavior.
@@ -53,5 +53,6 @@ Calling it from raw non-EThreads can result in unpredictable
behavior.
See Also
========
+:doc:`TSContSchedule.en`
:doc:`TSContScheduleOnPool.en`
-:doc:`TSContScheduleEveryOnPool.en`
+:doc:`TSContScheduleOnThread.en`
diff --git a/doc/developer-guide/api/functions/TSContScheduleOnPool.en.rst
b/doc/developer-guide/api/functions/TSContScheduleOnPool.en.rst
index 3acf484..1517f87 100644
--- a/doc/developer-guide/api/functions/TSContScheduleOnPool.en.rst
+++ b/doc/developer-guide/api/functions/TSContScheduleOnPool.en.rst
@@ -33,16 +33,11 @@ Synopsis
Description
===========
-Schedules :arg:`contp` to run :arg:`timeout` milliseconds in the future, on a
random thread that
-belongs to :arg:`tp`. The :arg:`timeout` is an approximation, meaning it will
be at least
-:arg:`timeout` milliseconds but possibly more. Resolutions finer than roughly
5 milliseconds will
-not be effective. Note that :arg:`contp` is required to have a mutex, which is
provided to
-:func:`TSContCreate`.
+Mostly the same as :func:`TSContSchedule`. Schedules :arg:`contp` on a random
thread that belongs to :arg:`tp`.
+If thread type of the thread specified by thread affinity is the same as
:arg:`tp`, the :arg:`contp` will
+be scheduled on the thread specified by thread affinity.
-The continuation is scheduled for a particular thread selected from a group of
similar threads,
-as indicated by :arg:`tp`. If :arg:`contp` already has an thread affinity set,
and the thread
-type of thread affinity is the same as :arg:`tp`, then :arg:`contp` will be
scheduled on the
-thread specified by thread affinity.
+The continuation is scheduled for a particular thread selected from a group of
similar threads, as indicated by :arg:`tp`.
===========================
=======================================================================================
Pool Properties
@@ -59,15 +54,6 @@ called and continuations that use them have the same
restrictions. ``TS_THREAD_P
are threads that exist to perform long or blocking actions, although
sufficiently long operation can
impact system performance by blocking other continuations on the threads.
-The return value can be used to cancel the scheduled event via
:func:`TSActionCancel`. This is
-effective until the continuation :arg:`contp` is being dispatched. However, if
it is scheduled on
-another thread this can be problematic to be correctly timed. The return value
can be checked with
-:func:`TSActionDone` to see if the continuation ran before the return, which
is possible if
-:arg:`timeout` is `0`.
-
-If :arg:`contp` has no thread affinity set, the thread it is now scheduled on
will be set
-as its thread affinity thread.
-
Note that the TSContSchedule() family of API shall only be called from an ATS
EThread.
Calling it from raw non-EThreads can result in unpredictable behavior.
@@ -138,5 +124,6 @@ the same continuation on two different threads of the same
type.
See Also
========
-:doc:`TSContScheduleEveryOnPool.en`
+:doc:`TSContSchedule.en`
+:doc:`TSContScheduleEvery.en`
:doc:`TSContScheduleOnThread.en`
diff --git a/doc/developer-guide/api/functions/TSContScheduleOnThread.en.rst
b/doc/developer-guide/api/functions/TSContScheduleOnThread.en.rst
index 41148a9..0f91166 100644
--- a/doc/developer-guide/api/functions/TSContScheduleOnThread.en.rst
+++ b/doc/developer-guide/api/functions/TSContScheduleOnThread.en.rst
@@ -33,19 +33,7 @@ Synopsis
Description
===========
-Schedules :arg:`contp` to run :arg:`timeout` milliseconds in the future, on
the thread specified by
-:arg:`ethread`. The :arg:`timeout` is an approximation, meaning it will be at
least :arg:`timeout`
-milliseconds but possibly more. Resolutions finer than roughly 5 milliseconds
will not be effective.
-Note that :arg:`contp` is required to have a mutex, which is provided to
:func:`TSContCreate`.
-
-The return value can be used to cancel the scheduled event via
:func:`TSActionCancel`. This is
-effective until the continuation :arg:`contp` is being dispatched. However, if
it is scheduled on
-another thread this can be problematic to be correctly timed. The return value
can be checked with
-:func:`TSActionDone` to see if the continuation ran before the return, which
is possible if
-:arg:`timeout` is `0`.
-
-If :arg:`contp` has no thread affinity set, the thread it is now scheduled on
will be set
-as its thread affinity thread.
+Mostly the same as :func:`TSContSchedule`. Schedules :arg:`contp` on
:arg:`ethread`.
Note that the TSContSchedule() family of API shall only be called from an ATS
EThread.
Calling it from raw non-EThreads can result in unpredictable behavior.
@@ -53,5 +41,6 @@ Calling it from raw non-EThreads can result in unpredictable
behavior.
See Also
========
+:doc:`TSContSchedule.en`
+:doc:`TSContScheduleEvery.en`
:doc:`TSContScheduleOnPool.en`
-:doc:`TSContScheduleEveryOnPool.en`
diff --git a/doc/developer-guide/api/functions/TSContThreadAffinitySet.en.rst
b/doc/developer-guide/api/functions/TSContThreadAffinitySet.en.rst
index 64417de..e78979c 100644
--- a/doc/developer-guide/api/functions/TSContThreadAffinitySet.en.rst
+++ b/doc/developer-guide/api/functions/TSContThreadAffinitySet.en.rst
@@ -34,10 +34,10 @@ Description
===========
Set the thread affinity of continuation :arg:`contp` to :arg:`ethread`. Future
calls to
-:func:`TSContScheduleOnPool`, and :func:`TSContScheduleOnPool` that has the
same type as :arg:`ethread`
+:func:`TSContSchedule`, and :func:`TSContScheduleOnPool` that has the same
type as :arg:`ethread`
will schedule the continuation on :arg:`ethread`, rather than an arbitrary
thread of that type.
-:func:`TSContScheduleOnPool` and :func:`TSContScheduleEveryOnPool` will
default the affinity to calling thread
+:func:`TSContSchedule` and :func:``TSContScheduleEvery` will default the
affinity to calling thread
when invoked without explicitly setting the thread affinity.
Return Values
diff --git
a/doc/developer-guide/plugins/continuations/activating-continuations.en.rst
b/doc/developer-guide/plugins/continuations/activating-continuations.en.rst
index 8ff2448..6b4135f 100644
--- a/doc/developer-guide/plugins/continuations/activating-continuations.en.rst
+++ b/doc/developer-guide/plugins/continuations/activating-continuations.en.rst
@@ -23,7 +23,7 @@ Activating Continuations
************************
Continuations are activated when they receive an event or by
-``TSContScheduleOnPool`` (which schedules a continuation to receive an event).
+``TSContSchedule`` (which schedules a continuation to receive an event).
Continuations might receive an event because:
- Your plugin calls ``TSContCall``
diff --git a/doc/developer-guide/plugins/continuations/index.en.rst
b/doc/developer-guide/plugins/continuations/index.en.rst
index 41722b1..94bd132 100644
--- a/doc/developer-guide/plugins/continuations/index.en.rst
+++ b/doc/developer-guide/plugins/continuations/index.en.rst
@@ -54,7 +54,7 @@ one of the following:
transactions uses ``TSContDataSet/Get``
- uses ``TSCacheXXX``, ``TSNetXXX``, ``TSHostLookup``, or
- ``TSContScheduleOnPool`` APIs
+ ``TSContSchedule`` APIs
Before being activated, a caller must grab the continuation's mutex.
This requirement makes it possible for a continuation's handler function
diff --git
a/doc/developer-guide/plugins/continuations/writing-handler-functions.en.rst
b/doc/developer-guide/plugins/continuations/writing-handler-functions.en.rst
index 8fafbfd..7250f25 100644
--- a/doc/developer-guide/plugins/continuations/writing-handler-functions.en.rst
+++ b/doc/developer-guide/plugins/continuations/writing-handler-functions.en.rst
@@ -95,6 +95,7 @@ Event Event Sender
:data:`TS_EVENT_CACHE_LOOKUP_COMPLETE`
:data:`TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK` :type:`TSHttpTxn`
:data:`TS_EVENT_IMMEDIATE` :func:`TSVConnClose`
:func:`TSVIOReenable`
+ :func:`TSContSchedule`
:func:`TSContScheduleOnPool`
:func:`TSContScheduleOnThread`
:data:`TS_EVENT_IMMEDIATE`
:data:`TS_HTTP_REQUEST_TRANSFORM_HOOK`
@@ -112,7 +113,8 @@ Event Event Sender
:func:`TSHttpTxnServerIntercept`
:func:`TSHttpTxnIntercept`
:data:`TS_EVENT_HOST_LOOKUP` :func:`TSHostLookup`
:type:`TSHostLookupResult`
-:data:`TS_EVENT_TIMEOUT` :func:`TSContScheduleOnPool`
+:data:`TS_EVENT_TIMEOUT` :func:`TSContSchedule`
+ :func:`TSContScheduleOnPool`
:func:`TSContScheduleOnThread`
:data:`TS_EVENT_ERROR`
:data:`TS_EVENT_VCONN_READ_READY` :func:`TSVConnRead`
:type:`TSVIO`
@@ -135,5 +137,6 @@ The continuation functions are listed below:
- :func:`TSContDataSet`
- :func:`TSContDestroy`
- :func:`TSContMutexGet`
+- :func:`TSContSchedule`
- :func:`TSContScheduleOnPool`
- :func:`TSContScheduleOnThread`
diff --git
a/doc/locale/ja/LC_MESSAGES/developer-guide/api/functions/TSContScheduleOnPool.en.po
b/doc/locale/ja/LC_MESSAGES/developer-guide/api/functions/TSContSchedule.en.po
similarity index 81%
rename from
doc/locale/ja/LC_MESSAGES/developer-guide/api/functions/TSContScheduleOnPool.en.po
rename to
doc/locale/ja/LC_MESSAGES/developer-guide/api/functions/TSContSchedule.en.po
index d41276f..e35760b 100644
---
a/doc/locale/ja/LC_MESSAGES/developer-guide/api/functions/TSContScheduleOnPool.en.po
+++
b/doc/locale/ja/LC_MESSAGES/developer-guide/api/functions/TSContSchedule.en.po
@@ -29,18 +29,18 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.1.1\n"
-#: ../../developer-guide/api/functions/TSContScheduleOnPool.en.rst:32
+#: ../../developer-guide/api/functions/TSContSchedule.en.rst:32
msgid "Description"
msgstr "解説"
-#: ../../developer-guide/api/functions/TSContScheduleOnPool.en.rst:25
+#: ../../developer-guide/api/functions/TSContSchedule.en.rst:25
msgid "Synopsis"
msgstr "概要"
-#: ../../developer-guide/api/functions/TSContScheduleOnPool.en.rst:22
-msgid "TSContScheduleOnPool"
+#: ../../developer-guide/api/functions/TSContSchedule.en.rst:22
+msgid "TSContSchedule"
msgstr ""
-#: ../../developer-guide/api/functions/TSContScheduleOnPool.en.rst:27
+#: ../../developer-guide/api/functions/TSContSchedule.en.rst:27
msgid "`#include <ts/ts.h>`"
msgstr "`#include <ts/ts.h>`"
diff --git
a/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/activating-continuations.en.po
b/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/activating-continuations.en.po
index 928db61..5e8bbaa 100644
---
a/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/activating-continuations.en.po
+++
b/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/activating-continuations.en.po
@@ -48,10 +48,10 @@ msgstr ""
#:
../../developer-guide/plugins/continuations/activating-continuations.en.rst:25
msgid ""
"Continuations are activated when they receive an event or by "
-"``TSContScheduleOnPool`` (which schedules a continuation to receive an
event). "
+"``TSContSchedule`` (which schedules a continuation to receive an event). "
"Continuations might receive an event because:"
msgstr ""
-"継続は、イベントを受け取った際か ``TSContScheduleOnPool`` (イベントを受け取るため"
+"継続は、イベントを受け取った際か ``TSContSchedule`` (イベントを受け取るため"
"継続をスケジュールする関数)によってアクティベートされます。下記の理由により"
"継続がイベントを受け取る可能性があります。 :"
diff --git
a/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/index.en.po
b/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/index.en.po
index b51a939..b2595d9 100644
---
a/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/index.en.po
+++
b/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/index.en.po
@@ -220,8 +220,8 @@ msgstr ""
#: ../../developer-guide/plugins/continuations/index.en.rst:56
msgid ""
-"uses ``TSCacheXXX``, ``TSNetXXX``, ``TSHostLookup``, or
``TSContScheduleOnPool`` "
+"uses ``TSCacheXXX``, ``TSNetXXX``, ``TSHostLookup``, or ``TSContSchedule`` "
"APIs"
msgstr ""
-"``TSCacheXXX``, ``TSNetXXX``, ``TSHostLookup``, もしくは ``TSContScheduleOnPool``
"
+"``TSCacheXXX``, ``TSNetXXX``, ``TSHostLookup``, もしくは ``TSContSchedule`` "
"API を使用する。"
diff --git
a/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/writing-handler-functions.en.po
b/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/writing-handler-functions.en.po
index df4b712..bdc58ce 100644
---
a/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/writing-handler-functions.en.po
+++
b/doc/locale/ja/LC_MESSAGES/developer-guide/plugins/continuations/writing-handler-functions.en.po
@@ -229,8 +229,8 @@ msgid ":data:`TS_EVENT_IMMEDIATE`"
msgstr ":data:`TS_EVENT_IMMEDIATE`"
#:
../../../developer-guide/plugins/continuations/writing-handler-functions.en.rst:90
-msgid ":func:`TSVConnClose` :func:`TSVIOReenable` :func:`TSContScheduleOnPool`"
-msgstr ":func:`TSVConnClose` :func:`TSVIOReenable`
:func:`TSContScheduleOnPool`"
+msgid ":func:`TSVConnClose` :func:`TSVIOReenable` :func:`TSContSchedule`"
+msgstr ":func:`TSVConnClose` :func:`TSVIOReenable` :func:`TSContSchedule`"
#:
../../../developer-guide/plugins/continuations/writing-handler-functions.en.rst:93
msgid ":data:`TS_HTTP_REQUEST_TRANSFORM_HOOK`"
@@ -329,8 +329,8 @@ msgstr ":data:`TS_EVENT_TIMEOUT`"
#:
../../../developer-guide/plugins/continuations/writing-handler-functions.en.rst:108
#:
../../../developer-guide/plugins/continuations/writing-handler-functions.en.rst:130
-msgid ":func:`TSContScheduleOnPool`"
-msgstr ":func:`TSContScheduleOnPool`"
+msgid ":func:`TSContSchedule`"
+msgstr ":func:`TSContSchedule`"
#:
../../../developer-guide/plugins/continuations/writing-handler-functions.en.rst:109
msgid ":data:`TS_EVENT_ERROR`"
diff --git a/include/ts/ts.h b/include/ts/ts.h
index c805a7a..5fef637 100644
--- a/include/ts/ts.h
+++ b/include/ts/ts.h
@@ -1233,8 +1233,10 @@ tsapi TSCont TSContCreate(TSEventFunc funcp, TSMutex
mutexp);
tsapi void TSContDestroy(TSCont contp);
tsapi void TSContDataSet(TSCont contp, void *data);
tsapi void *TSContDataGet(TSCont contp);
+tsapi TSAction TSContSchedule(TSCont contp, TSHRTime timeout);
tsapi TSAction TSContScheduleOnPool(TSCont contp, TSHRTime timeout,
TSThreadPool tp);
tsapi TSAction TSContScheduleOnThread(TSCont contp, TSHRTime timeout,
TSEventThread ethread);
+tsapi TSAction TSContScheduleEvery(TSCont contp, TSHRTime every /* millisecs
*/);
tsapi TSAction TSContScheduleEveryOnPool(TSCont contp, TSHRTime every /*
millisecs */, TSThreadPool tp);
tsapi TSAction TSContScheduleEveryOnThread(TSCont contp, TSHRTime every /*
millisecs */, TSEventThread ethread);
tsapi TSReturnCode TSContThreadAffinitySet(TSCont contp, TSEventThread
ethread);
diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc
index 18ebfca..0d6c20c 100644
--- a/src/traffic_server/InkAPI.cc
+++ b/src/traffic_server/InkAPI.cc
@@ -4626,6 +4626,40 @@ TSContDataGet(TSCont contp)
}
TSAction
+TSContSchedule(TSCont contp, TSHRTime timeout)
+{
+ sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS);
+
+ /* ensure we are on a EThread */
+ sdk_assert(sdk_sanity_check_null_ptr((void *)this_ethread()) == TS_SUCCESS);
+
+ FORCE_PLUGIN_SCOPED_MUTEX(contp);
+
+ INKContInternal *i = reinterpret_cast<INKContInternal *>(contp);
+
+ if (ink_atomic_increment(static_cast<int *>(&i->m_event_count), 1) < 0) {
+ ink_assert(!"not reached");
+ }
+
+ EThread *eth = i->getThreadAffinity();
+ if (eth == nullptr) {
+ eth = this_ethread();
+ i->setThreadAffinity(eth);
+ }
+
+ TSAction action;
+ if (timeout == 0) {
+ action = reinterpret_cast<TSAction>(eth->schedule_imm(i));
+ } else {
+ action = reinterpret_cast<TSAction>(eth->schedule_in(i,
HRTIME_MSECONDS(timeout)));
+ }
+
+ /* This is a hack. Should be handled in ink_types */
+ action = (TSAction)((uintptr_t)action | 0x1);
+ return action;
+}
+
+TSAction
TSContScheduleOnPool(TSCont contp, TSHRTime timeout, TSThreadPool tp)
{
sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS);
@@ -4706,6 +4740,35 @@ TSContScheduleOnThread(TSCont contp, TSHRTime timeout,
TSEventThread ethread)
}
TSAction
+TSContScheduleEvery(TSCont contp, TSHRTime every /* millisecs */)
+{
+ sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS);
+
+ /* ensure we are on a EThread */
+ sdk_assert(sdk_sanity_check_null_ptr((void *)this_ethread()) == TS_SUCCESS);
+
+ FORCE_PLUGIN_SCOPED_MUTEX(contp);
+
+ INKContInternal *i = reinterpret_cast<INKContInternal *>(contp);
+
+ if (ink_atomic_increment(static_cast<int *>(&i->m_event_count), 1) < 0) {
+ ink_assert(!"not reached");
+ }
+
+ EThread *eth = i->getThreadAffinity();
+ if (eth == nullptr) {
+ eth = this_ethread();
+ i->setThreadAffinity(eth);
+ }
+
+ TSAction action = reinterpret_cast<TSAction>(eth->schedule_every(i,
HRTIME_MSECONDS(every)));
+
+ /* This is a hack. Should be handled in ink_types */
+ action = (TSAction)((uintptr_t)action | 0x1);
+ return action;
+}
+
+TSAction
TSContScheduleEveryOnPool(TSCont contp, TSHRTime every, TSThreadPool tp)
{
sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS);
diff --git a/tests/gold_tests/cont_schedule/gold/schedule.gold
b/tests/gold_tests/cont_schedule/gold/schedule.gold
new file mode 100644
index 0000000..7b5d1f6
--- /dev/null
+++ b/tests/gold_tests/cont_schedule/gold/schedule.gold
@@ -0,0 +1,4 @@
+``
+``(TSContSchedule_test.check) pass [should be the same thread]
+``(TSContSchedule_test.check) pass [should not be the same thread]
+``
diff --git a/tests/gold_tests/cont_schedule/schedule.test.py
b/tests/gold_tests/cont_schedule/schedule.test.py
new file mode 100644
index 0000000..c82db17
--- /dev/null
+++ b/tests/gold_tests/cont_schedule/schedule.test.py
@@ -0,0 +1,49 @@
+'''
+'''
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import os
+
+Test.Summary = 'Test TSContSchedule API'
+Test.ContinueOnFail = True
+
+# Define default ATS
+ts = Test.MakeATSProcess('ts')
+
+Test.testName = 'Test TSContSchedule API'
+
+ts.Disk.records_config.update({
+ 'proxy.config.exec_thread.autoconfig': 0,
+ 'proxy.config.exec_thread.autoconfig.scale': 1.5,
+ 'proxy.config.exec_thread.limit': 32,
+ 'proxy.config.accept_threads': 1,
+ 'proxy.config.task_threads': 2,
+ 'proxy.config.diags.debug.enabled': 1,
+ 'proxy.config.diags.debug.tags': 'TSContSchedule_test'
+})
+
+# Load plugin
+Test.PreparePlugin(os.path.join(Test.Variables.AtsTestToolsDir, 'plugins',
'cont_schedule.cc'), ts)
+
+# www.example.com Host
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'printf "Test TSContSchedule API"'
+tr.Processes.Default.ReturnCode = 0
+tr.Processes.Default.StartBefore(ts)
+ts.Streams.All = "gold/schedule.gold"
+ts.Streams.All += Testers.ExcludesExpression('fail', 'should not contain
"fail"')
diff --git a/tests/tools/plugins/cont_schedule.cc
b/tests/tools/plugins/cont_schedule.cc
index 7706d89..4b8aa31 100644
--- a/tests/tools/plugins/cont_schedule.cc
+++ b/tests/tools/plugins/cont_schedule.cc
@@ -42,6 +42,8 @@ static TSEventThread thread_2 = nullptr;
static TSCont contp_1 = nullptr;
static TSCont contp_2 = nullptr;
+static int TSContSchedule_handler_1(TSCont contp, TSEvent event, void *edata);
+static int TSContSchedule_handler_2(TSCont contp, TSEvent event, void *edata);
static int TSContScheduleOnPool_handler_1(TSCont contp, TSEvent event, void
*edata);
static int TSContScheduleOnPool_handler_2(TSCont contp, TSEvent event, void
*edata);
static int TSContScheduleOnThread_handler_1(TSCont contp, TSEvent event, void
*edata);
@@ -49,6 +51,71 @@ static int TSContScheduleOnThread_handler_2(TSCont contp,
TSEvent event, void *e
static int TSContThreadAffinity_handler(TSCont contp, TSEvent event, void
*edata);
static int
+TSContSchedule_handler_1(TSCont contp, TSEvent event, void *edata)
+{
+ TSDebug(DEBUG_TAG_HDL, "TSContSchedule handler 1 thread [%p]",
TSThreadSelf());
+ if (thread_1 == nullptr) {
+ // First time entering this handler, before everything else starts.
+ thread_1 = TSEventThreadSelf();
+
+ // Set the affinity of contp_2 to thread_1, and schedule it twice.
+ // Since it's on the same thread, we don't need a delay.
+ TSDebug(DEBUG_TAG_HDL, "[%s] scheduling continuation", plugin_name);
+ TSContThreadAffinitySet(contp_2, thread_1);
+ TSContSchedule(contp_2, 0);
+ TSContSchedule(contp_2, 0);
+ } else if (thread_2 == nullptr) {
+ TSDebug(DEBUG_TAG_CHK, "fail [schedule delay not applied]");
+ } else {
+ // Second time in here, should be after the two scheduled handler_2 runs.
+ // Since handler_1 has no affinity set, we should be on a different thread
now.
+ // Also, thread_2 should be the same as thread_1, since thread_1 was set as
+ // affinity for handler_2.
+ if (thread_2 != TSEventThreadSelf() && thread_2 == thread_1) {
+ TSDebug(DEBUG_TAG_CHK, "pass [should not be the same thread]");
+ } else {
+ TSDebug(DEBUG_TAG_CHK, "fail [on the same thread]");
+ }
+ }
+ return 0;
+}
+
+static int
+TSContSchedule_handler_2(TSCont contp, TSEvent event, void *edata)
+{
+ TSDebug(DEBUG_TAG_HDL, "TSContSchedule handler 2 thread [%p]",
TSThreadSelf());
+ if (thread_2 == nullptr) {
+ // First time in this handler, should get here after handler_1,
+ // and also record the thread id.
+ thread_2 = TSEventThreadSelf();
+ } else if (thread_2 == TSEventThreadSelf()) {
+ // Second time in here, since the affinity is set to thread_1, we should be
+ // on the same thread as last time.
+ TSDebug(DEBUG_TAG_CHK, "pass [should be the same thread]");
+ } else {
+ TSDebug(DEBUG_TAG_CHK, "fail [not the same thread]");
+ }
+ return 0;
+}
+
+void
+TSContSchedule_test()
+{
+ contp_1 = TSContCreate(TSContSchedule_handler_1, TSMutexCreate());
+ contp_2 = TSContCreate(TSContSchedule_handler_2, TSMutexCreate());
+
+ if (contp_1 == nullptr || contp_2 == nullptr) {
+ TSDebug(DEBUG_TAG_SCHD, "[%s] could not create continuation", plugin_name);
+ abort();
+ } else {
+ TSDebug(DEBUG_TAG_SCHD, "[%s] scheduling continuation", plugin_name);
+ TSContScheduleOnPool(contp_1, 0, TS_THREAD_POOL_NET);
+ TSContThreadAffinityClear(contp_1);
+ TSContScheduleOnPool(contp_1, 200, TS_THREAD_POOL_NET);
+ }
+}
+
+static int
TSContScheduleOnPool_handler_1(TSCont contp, TSEvent event, void *edata)
{
// This runs on ET_NET threads.
@@ -113,7 +180,7 @@ TSContScheduleOnPool_test()
static int
TSContScheduleOnThread_handler_1(TSCont contp, TSEvent event, void *edata)
{
- // Mostly same as TSContScheduleOnPool_handler_1, no need to set affinity
+ // Mostly same as TSContSchedule_handler_1, no need to set affinity
// since we are scheduling directly on to a thread.
TSDebug(DEBUG_TAG_HDL, "TSContScheduleOnThread handler 1 thread [%p]",
TSThreadSelf());
if (thread_1 == nullptr) {
@@ -213,12 +280,15 @@ LifecycleHookTracer(TSCont contp, TSEvent event, void
*edata)
if (event == TS_EVENT_LIFECYCLE_TASK_THREADS_READY) {
switch (test_flag) {
case 1:
- TSContScheduleOnPool_test();
+ TSContSchedule_test();
break;
case 2:
- TSContScheduleOnThread_test();
+ TSContScheduleOnPool_test();
break;
case 3:
+ TSContScheduleOnThread_test();
+ break;
+ case 4:
TSContThreadAffinity_test();
break;
default:
@@ -231,17 +301,20 @@ LifecycleHookTracer(TSCont contp, TSEvent event, void
*edata)
void
TSPluginInit(int argc, const char *argv[])
{
- if (argc == 2) {
+ if (argc == 1) {
+ TSDebug(DEBUG_TAG_INIT, "initializing plugin for testing TSContSchedule");
+ test_flag = 1;
+ } else if (argc == 2) {
int len = strlen(argv[1]);
if (len == 4 && strncmp(argv[1], "pool", 4) == 0) {
TSDebug(DEBUG_TAG_INIT, "initializing plugin for testing
TSContScheduleOnPool");
- test_flag = 1;
+ test_flag = 2;
} else if (len == 6 && strncmp(argv[1], "thread", 6) == 0) {
TSDebug(DEBUG_TAG_INIT, "initializing plugin for testing
TSContScheduleOnThread");
- test_flag = 2;
+ test_flag = 3;
} else if (len == 8 && strncmp(argv[1], "affinity", 8) == 0) {
TSDebug(DEBUG_TAG_INIT, "initializing plugin for testing
TSContThreadAffinity");
- test_flag = 3;
+ test_flag = 4;
} else {
goto Lerror;
}