Skip to content

Commit 73efac8

Browse files
committed
YT-23303: Rework TInvokerWrapper to no longer always inherit from IInvoker virtually
done commit_hash:cb0fb004fbbe049eaf7ad8025faa97e1602b6579
1 parent 47ff3a8 commit 73efac8

File tree

7 files changed

+58
-22
lines changed

7 files changed

+58
-22
lines changed

yt/yt/core/actions/cancelable_context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace NYT {
1010
////////////////////////////////////////////////////////////////////////////////
1111

1212
class TCancelableContext::TCancelableInvoker
13-
: public TInvokerWrapper
13+
: public TInvokerWrapper<false>
1414
{
1515
public:
1616
TCancelableInvoker(

yt/yt/core/actions/invoker_detail.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,60 @@ namespace NYT {
1010

1111
////////////////////////////////////////////////////////////////////////////////
1212

13-
TInvokerWrapper::TInvokerWrapper(IInvokerPtr underlyingInvoker)
13+
template <bool VirtualizeBase>
14+
TInvokerWrapper<VirtualizeBase>::TInvokerWrapper(IInvokerPtr underlyingInvoker)
1415
: UnderlyingInvoker_(std::move(underlyingInvoker))
1516
{
1617
YT_VERIFY(UnderlyingInvoker_);
1718
}
1819

19-
void TInvokerWrapper::Invoke(TClosure callback)
20+
template <bool VirtualizeBase>
21+
void TInvokerWrapper<VirtualizeBase>::Invoke(TClosure callback)
2022
{
2123
return UnderlyingInvoker_->Invoke(std::move(callback));
2224
}
2325

24-
void TInvokerWrapper::Invoke(TMutableRange<TClosure> callbacks)
26+
template <bool VirtualizeBase>
27+
void TInvokerWrapper<VirtualizeBase>::Invoke(TMutableRange<TClosure> callbacks)
2528
{
2629
return UnderlyingInvoker_->Invoke(callbacks);
2730
}
2831

29-
NThreading::TThreadId TInvokerWrapper::GetThreadId() const
32+
template <bool VirtualizeBase>
33+
NThreading::TThreadId TInvokerWrapper<VirtualizeBase>::GetThreadId() const
3034
{
3135
return UnderlyingInvoker_->GetThreadId();
3236
}
3337

34-
bool TInvokerWrapper::CheckAffinity(const IInvokerPtr& invoker) const
38+
template <bool VirtualizeBase>
39+
bool TInvokerWrapper<VirtualizeBase>::CheckAffinity(const IInvokerPtr& invoker) const
3540
{
3641
return
3742
invoker.Get() == this ||
3843
UnderlyingInvoker_->CheckAffinity(invoker);
3944
}
4045

41-
bool TInvokerWrapper::IsSerialized() const
46+
template <bool VirtualizeBase>
47+
bool TInvokerWrapper<VirtualizeBase>::IsSerialized() const
4248
{
4349
return UnderlyingInvoker_->IsSerialized();
4450
}
4551

46-
void TInvokerWrapper::RegisterWaitTimeObserver(TWaitTimeObserver waitTimeObserver)
52+
template <bool VirtualizeBase>
53+
void TInvokerWrapper<VirtualizeBase>::RegisterWaitTimeObserver(IInvoker::TWaitTimeObserver waitTimeObserver)
4754
{
4855
return UnderlyingInvoker_->RegisterWaitTimeObserver(waitTimeObserver);
4956
}
5057

5158
////////////////////////////////////////////////////////////////////////////////
5259

60+
template class TInvokerWrapper<true>;
61+
template class TInvokerWrapper<false>;
62+
// template struct NDetail::TMaybeVirtualInvokerBase<true>; // Primary template.
63+
template struct NDetail::TMaybeVirtualInvokerBase<false>;
64+
65+
////////////////////////////////////////////////////////////////////////////////
66+
5367
TInvokerProfileWrapper::TInvokerProfileWrapper(NProfiling::IRegistryImplPtr registry, const TString& invokerFamily, const NProfiling::TTagSet& tagSet)
5468
{
5569
auto profiler = NProfiling::TProfiler("/invoker", NProfiling::TProfiler::DefaultNamespace, tagSet, registry).WithHot();

yt/yt/core/actions/invoker_detail.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,27 @@ namespace NYT {
1111

1212
////////////////////////////////////////////////////////////////////////////////
1313

14-
class TInvokerWrapper
14+
namespace NDetail {
15+
16+
template <bool VirtualizeBase>
17+
struct TMaybeVirtualInvokerBase
18+
: public IInvoker
19+
{ };
20+
21+
////////////////////////////////////////////////////////////////////////////////
22+
23+
template <>
24+
struct TMaybeVirtualInvokerBase<true>
1525
: public virtual IInvoker
26+
{ };
27+
28+
} // namespace NDetail
29+
30+
////////////////////////////////////////////////////////////////////////////////
31+
32+
template <bool VirtualizeBase>
33+
class TInvokerWrapper
34+
: public NDetail::TMaybeVirtualInvokerBase<VirtualizeBase>
1635
{
1736
public:
1837
void Invoke(TClosure callback) override;
@@ -22,7 +41,7 @@ class TInvokerWrapper
2241
NThreading::TThreadId GetThreadId() const override;
2342
bool CheckAffinity(const IInvokerPtr& invoker) const override;
2443
bool IsSerialized() const override;
25-
void RegisterWaitTimeObserver(TWaitTimeObserver waitTimeObserver) override;
44+
void RegisterWaitTimeObserver(IInvoker::TWaitTimeObserver waitTimeObserver) override;
2645

2746
protected:
2847
explicit TInvokerWrapper(IInvokerPtr underlyingInvoker);

yt/yt/core/concurrency/action_queue.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const IInvokerPtr& TActionQueue::GetInvoker()
110110
////////////////////////////////////////////////////////////////////////////////
111111

112112
class TSerializedInvoker
113-
: public TInvokerWrapper
113+
: public TInvokerWrapper<false>
114114
, public TInvokerProfileWrapper
115115
{
116116
public:
@@ -260,7 +260,7 @@ IInvokerPtr CreateSerializedInvoker(IInvokerPtr underlyingInvoker, const TString
260260
////////////////////////////////////////////////////////////////////////////////
261261

262262
class TPrioritizedInvoker
263-
: public TInvokerWrapper
263+
: public TInvokerWrapper<true>
264264
, public TInvokerProfileWrapper
265265
, public virtual IPrioritizedInvoker
266266
{
@@ -333,7 +333,7 @@ IPrioritizedInvokerPtr CreatePrioritizedInvoker(IInvokerPtr underlyingInvoker, c
333333
////////////////////////////////////////////////////////////////////////////////
334334

335335
class TFakePrioritizedInvoker
336-
: public TInvokerWrapper
336+
: public TInvokerWrapper<true>
337337
, public virtual IPrioritizedInvoker
338338
{
339339
public:
@@ -357,7 +357,7 @@ IPrioritizedInvokerPtr CreateFakePrioritizedInvoker(IInvokerPtr underlyingInvoke
357357
////////////////////////////////////////////////////////////////////////////////
358358

359359
class TFixedPriorityInvoker
360-
: public TInvokerWrapper
360+
: public TInvokerWrapper<false>
361361
{
362362
public:
363363
TFixedPriorityInvoker(
@@ -397,7 +397,7 @@ class TBoundedConcurrencyInvoker;
397397
YT_DEFINE_THREAD_LOCAL(TBoundedConcurrencyInvoker*, CurrentBoundedConcurrencyInvoker);
398398

399399
class TBoundedConcurrencyInvoker
400-
: public TInvokerWrapper
400+
: public TInvokerWrapper<false>
401401
{
402402
public:
403403
TBoundedConcurrencyInvoker(
@@ -559,16 +559,19 @@ void SetMaxConcurrentInvocations(
559559
TTaggedInterface<IInvoker, TBoundedConcurrencyInvokerTag> invoker,
560560
int maxConcurrentInvocations)
561561
{
562-
// TODO(apachee): Fix inheritance from IInvoker so that it is possible to use static_cast here instead of dynamic_cast in non-debug builds.
562+
#ifdef NDEBUG
563+
auto boundedConcurrencyInvoker = static_cast<TBoundedConcurrencyInvoker*>(invoker.Get());
564+
#else
563565
auto boundedConcurrencyInvoker = dynamic_cast<TBoundedConcurrencyInvoker*>(invoker.Get());
564566
YT_VERIFY(boundedConcurrencyInvoker);
567+
#endif
565568
boundedConcurrencyInvoker->SetMaxConcurrentInvocations(maxConcurrentInvocations);
566569
}
567570

568571
////////////////////////////////////////////////////////////////////////////////
569572

570573
class TSuspendableInvoker
571-
: public TInvokerWrapper
574+
: public TInvokerWrapper<true>
572575
, public virtual ISuspendableInvoker
573576
{
574577
public:
@@ -710,7 +713,7 @@ ISuspendableInvokerPtr CreateSuspendableInvoker(IInvokerPtr underlyingInvoker)
710713
////////////////////////////////////////////////////////////////////////////////
711714

712715
class TCodicilGuardedInvoker
713-
: public TInvokerWrapper
716+
: public TInvokerWrapper<false>
714717
{
715718
public:
716719
TCodicilGuardedInvoker(IInvokerPtr invoker, TString codicil)
@@ -745,7 +748,7 @@ IInvokerPtr CreateCodicilGuardedInvoker(IInvokerPtr underlyingInvoker, TString c
745748
////////////////////////////////////////////////////////////////////////////////
746749

747750
class TWatchdogInvoker
748-
: public TInvokerWrapper
751+
: public TInvokerWrapper<false>
749752
{
750753
public:
751754
TWatchdogInvoker(

yt/yt/core/concurrency/fair_share_invoker_pool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ class TFairShareInvokerPool
533533
};
534534

535535
class TInvoker
536-
: public TInvokerWrapper
536+
: public TInvokerWrapper<false>
537537
{
538538
public:
539539
TInvoker(IInvokerPtr underlyingInvoker_, int index, TWeakPtr<TFairShareInvokerPool> parent)

yt/yt/core/concurrency/unittests/invoker_pool_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ using IMockInvokerPoolPtr = TIntrusivePtr<IMockInvokerPool>;
4949
////////////////////////////////////////////////////////////////////////////////
5050

5151
class TMockInvoker
52-
: public TInvokerWrapper
52+
: public TInvokerWrapper<false>
5353
{
5454
public:
5555
explicit TMockInvoker(IInvokerPtr underlyingInvoker)

yt/yt/core/concurrency/unittests/scheduler_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ class TVerifyingMemoryTagGuard
10681068
};
10691069

10701070
class TWrappingInvoker
1071-
: public TInvokerWrapper
1071+
: public TInvokerWrapper<false>
10721072
{
10731073
public:
10741074
explicit TWrappingInvoker(IInvokerPtr underlyingInvoker)

0 commit comments

Comments
 (0)