Skip to content

Commit 4015ab5

Browse files
authored
Merge pull request #33 from awslabs/FB-CallableExecutor
Fb callable executor
2 parents 2598f41 + a5fb897 commit 4015ab5

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

aws-cpp-sdk-core/include/aws/core/utils/threading/Executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <aws/core/utils/memory/stl/AWSQueue.h>
2121
#include <aws/core/utils/memory/stl/AWSVector.h>
2222
#include <functional>
23+
#include <future>
2324
#include <mutex>
2425
#include <condition_variable>
2526

@@ -49,7 +50,6 @@ namespace Aws
4950
return SubmitToThread(AWS_BUILD_TYPED_FUNCTION(std::bind(std::forward<Fn>(fn), std::forward<Args>(args)...), void()));
5051
}
5152

52-
5353
protected:
5454
/**
5555
* To implement your own executor implementation, then simply subclass Executor and implement this method.

aws-cpp-sdk-core/source/utils/threading/Executor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
static const char* POOLED_CLASS_TAG = "PooledThreadExecutor";
2121

22-
using namespace Aws::Utils::Threading;
22+
using namespace Aws::Utils::Threading;
2323

2424
bool DefaultExecutor::SubmitToThread(std::function<void()>&& fx)
2525
{

code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/JsonServiceOperationsSource.vm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ ${operation.name}Outcome ${className}::${operation.name}(const ${operation.reque
4646

4747
${operation.name}OutcomeCallable ${className}::${operation.name}Callable(const ${operation.request.shape.name}& request) const
4848
{
49-
return std::async(std::launch::async, [this, request](){ return this->${operation.name}(request); } );
49+
auto task = Aws::MakeShared< std::packaged_task< ${operation.name}Outcome() > >(ALLOCATION_TAG, [this, request](){ return this->${operation.name}(request); } );
50+
auto packagedFunction = [task]() { (*task)(); };
51+
m_executor->Submit(packagedFunction);
52+
return task->get_future();
5053
}
5154

5255
void ${className}::${operation.name}Async(const ${operation.request.shape.name}& request, const ${operation.name}ResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
@@ -90,7 +93,10 @@ ${operation.name}Outcome ${className}::${operation.name}() const
9093

9194
${operation.name}OutcomeCallable ${className}::${operation.name}Callable() const
9295
{
93-
return std::async(std::launch::async, [this](){ return this->${operation.name}(); } );
96+
auto task = Aws::MakeShared< std::packaged_task< ${operation.name}Outcome() > >(ALLOCATION_TAG, [this](){ return this->${operation.name}(); } );
97+
auto packagedFunction = [task]() { (*task)(); };
98+
m_executor->Submit(packagedFunction);
99+
return task->get_future();
94100
}
95101

96102
void ${className}::${operation.name}Async(const ${operation.name}ResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const

code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/machinelearning/MachineLearningServiceClientSource.vm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ ${operation.name}Outcome ${className}::${operation.name}(const ${operation.reque
6767

6868
${operation.name}OutcomeCallable ${className}::${operation.name}Callable(const ${operation.request.shape.name}& request) const
6969
{
70-
return std::async(std::launch::async, [this, request](){ return this->${operation.name}( request ); } );
70+
auto task = Aws::MakeShared< std::packaged_task< ${operation.name}Outcome() > >(ALLOCATION_TAG, [this, request](){ return this->${operation.name}(request); } );
71+
auto packagedFunction = [task]() { (*task)(); };
72+
m_executor->Submit(packagedFunction);
73+
return task->get_future();
7174
}
7275

7376
void ${className}::${operation.name}Async(const ${operation.request.shape.name}& request, const ${operation.name}ResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const

code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/sqs/SQSServiceClientSource.vm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ ${operation.name}Outcome ${className}::${operation.name}(const ${operation.reque
6868

6969
${operation.name}OutcomeCallable ${className}::${operation.name}Callable(const ${operation.request.shape.name}& request) const
7070
{
71-
return std::async(std::launch::async, [this, request](){ return this->${operation.name}(request); });
71+
auto task = Aws::MakeShared< std::packaged_task< ${operation.name}Outcome() > >(ALLOCATION_TAG, [this, request](){ return this->${operation.name}(request); } );
72+
auto packagedFunction = [task]() { (*task)(); };
73+
m_executor->Submit(packagedFunction);
74+
return task->get_future();
7275
}
7376

7477
void ${className}::${operation.name}Async(const ${operation.request.shape.name}& request, const ${operation.name}ResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const

code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/xml/rest/RestXmlServiceClientOperations.vm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ ${operation.name}Outcome ${className}::${operation.name}(const ${operation.reque
4545

4646
${operation.name}OutcomeCallable ${className}::${operation.name}Callable(const ${operation.request.shape.name}& request) const
4747
{
48-
return std::async(std::launch::async, [this, request](){ return this->${operation.name}( request ); } );
48+
auto task = Aws::MakeShared< std::packaged_task< ${operation.name}Outcome() > >(ALLOCATION_TAG, [this, request](){ return this->${operation.name}(request); } );
49+
auto packagedFunction = [task]() { (*task)(); };
50+
m_executor->Submit(packagedFunction);
51+
return task->get_future();
4952
}
5053

5154
void ${className}::${operation.name}Async(const ${operation.request.shape.name}& request, const ${operation.name}ResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
@@ -88,7 +91,10 @@ ${operation.name}Outcome ${className}::${operation.name}() const
8891

8992
${operation.name}OutcomeCallable ${className}::${operation.name}Callable() const
9093
{
91-
return std::async(std::launch::async, [this](){ return this->${operation.name}(); } );
94+
auto task = Aws::MakeShared< std::packaged_task< ${operation.name}Outcome() > >(ALLOCATION_TAG, [this](){ return this->${operation.name}(); } );
95+
auto packagedFunction = [task]() { (*task)(); };
96+
m_executor->Submit(packagedFunction);
97+
return task->get_future();
9298
}
9399

94100
void ${className}::${operation.name}Async(const ${operation.name}ResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const

0 commit comments

Comments
 (0)