Skip to content

Commit 00fdd7b

Browse files
authored
Add ClassWithAsync for CsWinRT async benchmarks. (#74)
1 parent 749efc7 commit 00fdd7b

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

BenchmarkComponent/BenchmarkComponent.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "ClassWithMarshalingRoutines.g.cpp"
55
#include "WrappedClass.g.cpp"
66
#include "EventOperations.g.cpp"
7+
#include "ClassWithAsync.g.cpp"
78
#include "Composable.g.cpp"
89
#include "ClassWithFastAbi.g.cpp"
910
#include "ClassWithFastAbiDerived.g.cpp"
@@ -161,7 +162,7 @@ namespace winrt::BenchmarkComponent::implementation
161162
{
162163
return createList();
163164
}
164-
165+
165166
Windows::Foundation::IInspectable ClassWithMarshalingRoutines::NewTypeErasedKeyValuePairObject()
166167
{
167168
return createKeyValuePairObject();
@@ -273,7 +274,7 @@ namespace winrt::BenchmarkComponent::implementation
273274
}
274275
Windows::Foundation::IReference<BenchmarkComponent::BlittableStruct> ClassWithMarshalingRoutines::NullableBlittableStruct()
275276
{
276-
return IReference<BenchmarkComponent::BlittableStruct>(BenchmarkComponent::BlittableStruct{2});
277+
return IReference<BenchmarkComponent::BlittableStruct>(BenchmarkComponent::BlittableStruct{ 2 });
277278
}
278279
void ClassWithMarshalingRoutines::NullableBlittableStruct(Windows::Foundation::IReference<BenchmarkComponent::BlittableStruct> const& value)
279280
{
@@ -385,16 +386,16 @@ namespace winrt::BenchmarkComponent::implementation
385386
void EventOperations::AddIntEvent()
386387
{
387388
intEventToken = events.IntPropertyChanged([this](IInspectable const& sender, int32_t value)
388-
{
389-
intVal = value;
390-
});
389+
{
390+
intVal = value;
391+
});
391392
}
392393
void EventOperations::AddDoubleEvent()
393394
{
394395
doubleEventToken = events.DoublePropertyChanged([this](IInspectable const& sender, double_t value)
395-
{
396-
doubleVal = value;
397-
});
396+
{
397+
doubleVal = value;
398+
});
398399
}
399400
void EventOperations::RemoveIntEvent()
400401
{
@@ -412,6 +413,24 @@ namespace winrt::BenchmarkComponent::implementation
412413
{
413414
events.RaiseDoubleChanged();
414415
}
416+
IAsyncAction ClassWithAsync::Complete()
417+
{
418+
co_return;
419+
}
420+
IAsyncAction ClassWithAsync::YieldComplete()
421+
{
422+
co_await resume_background();
423+
co_return;
424+
}
425+
IAsyncOperation<int32_t> ClassWithAsync::Return(int32_t value)
426+
{
427+
co_return value;
428+
}
429+
IAsyncOperation<int32_t> ClassWithAsync::YieldReturn(int32_t value)
430+
{
431+
co_await resume_background();
432+
co_return value;
433+
}
415434
int32_t ClassWithFastAbi::DefaultIntProperty()
416435
{
417436
return 1;

BenchmarkComponent/BenchmarkComponent.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "ClassWithFastAbiDerived.g.h"
77
#include "WrappedClass.g.h"
88
#include "EventOperations.g.h"
9+
#include "ClassWithAsync.g.h"
910
#include "Composable.g.h"
1011

1112
namespace winrt::BenchmarkComponent::implementation
@@ -163,6 +164,17 @@ namespace winrt::BenchmarkComponent::implementation
163164
void FireDoubleEvent();
164165
};
165166

167+
struct ClassWithAsync : ClassWithAsyncT<ClassWithAsync>
168+
{
169+
public:
170+
ClassWithAsync() = default;
171+
172+
Windows::Foundation::IAsyncAction Complete();
173+
Windows::Foundation::IAsyncAction YieldComplete();
174+
Windows::Foundation::IAsyncOperation<int32_t> Return(int32_t value);
175+
Windows::Foundation::IAsyncOperation<int32_t> YieldReturn(int32_t value);
176+
};
177+
166178
struct Composable : ComposableT<Composable>
167179
{
168180
Composable() = default;
@@ -214,4 +226,8 @@ namespace winrt::BenchmarkComponent::factory_implementation
214226
struct ClassWithFastAbiDerived : ClassWithFastAbiDerivedT<ClassWithFastAbiDerived, implementation::ClassWithFastAbiDerived>
215227
{
216228
};
229+
230+
struct ClassWithAsync : ClassWithAsyncT<ClassWithAsync, implementation::ClassWithAsync>
231+
{
232+
};
217233
}

BenchmarkComponent/BenchmarkComponent.idl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,15 @@ namespace BenchmarkComponent
159159
void FireIntEvent();
160160
void FireDoubleEvent();
161161
}
162+
163+
[default_interface]
164+
runtimeclass ClassWithAsync
165+
{
166+
ClassWithAsync();
167+
168+
Windows.Foundation.IAsyncAction Complete();
169+
Windows.Foundation.IAsyncAction YieldComplete();
170+
Windows.Foundation.IAsyncOperation<Int32> Return(Int32 number);
171+
Windows.Foundation.IAsyncOperation<Int32> YieldReturn(Int32 number);
172+
}
162173
}

0 commit comments

Comments
 (0)