New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/[SE] scheduler #992
Feature/[SE] scheduler #992
Conversation
5bee6ad
to
b43e11a
Compare
d9b877d
to
3ee170e
Compare
auto tid = manager->dispatcher()->bind(scheduler); | ||
ASSERT_TRUE(tid); | ||
|
||
utils::WaitForSingleObject complete[2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils::WaitForSingleObject complete[2]; |
Can be removed because the test is single-threaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
* @and they subscribe to different events in a single current scheduler | ||
* @and both events are notified followed by dispose and process | ||
* @then the handlers of each subscriber must be called once and process finish | ||
* it's loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* it's loop | |
* its loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} | ||
|
||
bool unbind(Tid tid) override { | ||
return binded_.exclusiveAccess([tid](BoundContexts &bound) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return binded_.exclusiveAccess([tid](BoundContexts &bound) { | |
return bound_.exclusiveAccess([tid](BoundContexts &bound) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
3ee170e
to
eb8e856
Compare
private: | ||
using Parent = IDispatcher<kCount, kPoolSize>; | ||
using Parent = IDispatcher; | ||
|
||
struct ThreadHandlerContext { | ||
/// Worker thread to execute tasks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a thread from now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
} | ||
|
||
void addDelayed(std::chrono::microseconds timeout, Task &&t) override { | ||
#ifdef SE_SYNC_CALL_IF_SAME_THREAD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use templated constant or constexpr contruction-time constant or anything but not define.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Template parameter allows you to execute both kind of code. But you can't.
* If you need to execute task, that was made in this thread and want to be | ||
* executed in the same thread without delay - you need to uncomment this define | ||
*/ | ||
//#define SE_SYNC_CALL_IF_SAME_THREAD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no-no-no! Looks like a dead code in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
@@ -6,6 +6,7 @@ | |||
#ifndef IROHA_SUBSCRIPTION_SUBSCRIPTION_ENGINE_HPP | |||
#define IROHA_SUBSCRIPTION_SUBSCRIPTION_ENGINE_HPP | |||
|
|||
#include <assert.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <assert.h> | |
#include <cassert> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_assert
is not defined in cassert
@@ -91,18 +92,17 @@ namespace iroha::subscription { | |||
* be kept valid in case the other subscriber will be deleted from this | |||
* container) | |||
*/ | |||
template <typename Dispatcher::Tid kTid> | |||
IteratorType subscribe(SubscriptionSetId set_id, | |||
IteratorType subscribe(typename Dispatcher::Tid tid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls also fix doc @tparam
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
subscriber1->subscribe(1ull, event_id); | ||
subscriber2->subscribe(1ull, event_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subscriber1->subscribe(1ull, event_id); | |
subscriber2->subscribe(1ull, event_id); | |
subscriber1->subscribe(1, event_id); | |
subscriber2->subscribe(1, event_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. If so, we need 1u
. 1
is a signed int type.
if (!scheduler) | ||
return std::nullopt; | ||
|
||
return bound_.exclusiveAccess([scheduler(std::move(scheduler))]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for readability less parenthes:
return bound_.exclusiveAccess([scheduler(std::move(scheduler))]( | |
return bound_.exclusiveAccess([scheduler=std::move(scheduler)]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The meaning here is the construction of an object and you need to call it as a constructor.
BoundContexts &bound) { | ||
auto const execution_tid = kHandlersCount + bound.next_tid_offset; | ||
assert(bound.contexts.find(execution_tid) == bound.contexts.end()); | ||
bound.contexts[execution_tid] = ThreadHandlerContext{scheduler, false}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have replaced terminology ThreadHandler with Sceduler - pls rename class.
bound.contexts[execution_tid] = ThreadHandlerContext{scheduler, false}; | |
bound.contexts[execution_tid] = ShedulerContext{scheduler, false}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
try { | ||
if (task) | ||
task(); | ||
} catch (...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure? let's log error at least!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the last barrier
|
||
class SchedulerBase : public IScheduler, utils::NoCopy, utils::NoMove { | ||
private: | ||
using Time = std::chrono::high_resolution_clock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer same terminology as std:: and boost::
using Time = std::chrono::high_resolution_clock; | |
using Clock = std::chrono::high_resolution_clock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like time
and timestamp
much more than clock
and time-point
.
0313a4d
to
32ce6b4
Compare
32ce6b4
to
0a7cd27
Compare
bind/unbind additional schedulers to dispatcher Signed-off-by: iceseer <iceseer@gmail.com>
0a7cd27
to
2330cd7
Compare
Description of the Change
Added scheduler with execution thread loop. Can be used to manage your own process loop in a current thread.
Benefits
Possible Drawbacks
Usage Examples or Tests [optional]
Alternate Designs [optional]