From e169691109f3d8db2e55fdf7a3a8222c39d8d672 Mon Sep 17 00:00:00 2001 From: Agner Esteves Ballejo Date: Thu, 16 Apr 2020 19:03:10 -0300 Subject: [PATCH 1/8] Adjust wrong code cast --- src/backward.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backward.h b/src/backward.h index 940116e..c924a70 100644 --- a/src/backward.h +++ b/src/backward.h @@ -3057,7 +3057,7 @@ class TraceResolverDarwinImpl : public Tra if (st.size() == 0) { return; } - _symbols.reset(backtrace_symbols(st.begin(), st.size())); + _symbols.reset(backtrace_symbols(st.begin(), (int) st.size())); } ResolvedTrace resolve(ResolvedTrace trace) From 78e0964a01697ec6fd1279f46ce46b8657eb5ddf Mon Sep 17 00:00:00 2001 From: Agner Esteves Ballejo Date: Fri, 17 Apr 2020 10:04:31 -0300 Subject: [PATCH 2/8] Add thread to run handler --- src/runtime.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/runtime.cpp b/src/runtime.cpp index 2c12542..e0b8a6e 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -19,6 +19,7 @@ #include "aws/logging/logging.h" #include "aws/http/response.h" +#include #include #include #include // for ULONG_MAX @@ -27,6 +28,7 @@ #include #include // for strtoul #include +#include #define AWS_LAMBDA_RUNTIME_API __attribute__((visibility("default"))) @@ -395,6 +397,18 @@ static bool handle_post_outcome(runtime::post_outcome const& o, std::string cons return false; } +void listen_messages() { + logging::log_info(LOG_TAG, "Executing thread"); + std::this_thread::sleep_for(std::chrono::milliseconds (20000)); + std::function handler; + run_handler(handler); +} + +void start_listener() { + std::thread t1(listen_messages, "Hello"); + t1.join(); +} + AWS_LAMBDA_RUNTIME_API void run_handler(std::function const& handler) { From 7b9d85ccd70b060d073c1267315eeaad09a4441d Mon Sep 17 00:00:00 2001 From: Agner Esteves Ballejo Date: Fri, 17 Apr 2020 10:07:46 -0300 Subject: [PATCH 3/8] run listener --- src/runtime.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime.cpp b/src/runtime.cpp index e0b8a6e..c948f71 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -405,6 +405,7 @@ void listen_messages() { } void start_listener() { + logging::log_info(LOG_TAG, "Starting listener"); std::thread t1(listen_messages, "Hello"); t1.join(); } @@ -412,6 +413,8 @@ void start_listener() { AWS_LAMBDA_RUNTIME_API void run_handler(std::function const& handler) { + start_listener(); + logging::log_info(LOG_TAG, "Initializing the C++ Lambda Runtime version %s", aws::lambda_runtime::get_version()); std::string endpoint("http://"); if (auto ep = std::getenv("AWS_LAMBDA_RUNTIME_API")) { From 85694fc5808e3f8e89bc4ea6a75b6da87107292e Mon Sep 17 00:00:00 2001 From: Agner Esteves Ballejo Date: Fri, 17 Apr 2020 10:14:56 -0300 Subject: [PATCH 4/8] add message --- src/runtime.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime.cpp b/src/runtime.cpp index c948f71..54a05c1 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -397,8 +397,8 @@ static bool handle_post_outcome(runtime::post_outcome const& o, std::string cons return false; } -void listen_messages() { - logging::log_info(LOG_TAG, "Executing thread"); +void listen_messages(std::string message) { + logging::log_info(LOG_TAG, "Executing thread %s", message.c_str()); std::this_thread::sleep_for(std::chrono::milliseconds (20000)); std::function handler; run_handler(handler); From 0fa3a9740d44e0054bc6a13c34a430e5dc4b7a06 Mon Sep 17 00:00:00 2001 From: Agner Esteves Ballejo Date: Fri, 17 Apr 2020 10:53:09 -0300 Subject: [PATCH 5/8] add async instead of thread --- src/runtime.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime.cpp b/src/runtime.cpp index 54a05c1..46bc033 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -29,6 +29,7 @@ #include // for strtoul #include #include +#include #define AWS_LAMBDA_RUNTIME_API __attribute__((visibility("default"))) @@ -406,8 +407,7 @@ void listen_messages(std::string message) { void start_listener() { logging::log_info(LOG_TAG, "Starting listener"); - std::thread t1(listen_messages, "Hello"); - t1.join(); + std::async(std::launch::async, listen_messages, "Hello"); } AWS_LAMBDA_RUNTIME_API From 8b911149cec346543cfd906255821f6941fa872c Mon Sep 17 00:00:00 2001 From: Agner Esteves Ballejo Date: Fri, 17 Apr 2020 10:58:44 -0300 Subject: [PATCH 6/8] remove join of thread --- src/runtime.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime.cpp b/src/runtime.cpp index 46bc033..d3972d6 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -29,7 +29,6 @@ #include // for strtoul #include #include -#include #define AWS_LAMBDA_RUNTIME_API __attribute__((visibility("default"))) @@ -407,7 +406,8 @@ void listen_messages(std::string message) { void start_listener() { logging::log_info(LOG_TAG, "Starting listener"); - std::async(std::launch::async, listen_messages, "Hello"); + std::thread t1(listen_messages, "Hello"); +// t1.join(); } AWS_LAMBDA_RUNTIME_API From c35ba971cf188687d37b481b4d769b3a9fd8fb1d Mon Sep 17 00:00:00 2001 From: Agner Esteves Ballejo Date: Fri, 17 Apr 2020 11:02:23 -0300 Subject: [PATCH 7/8] detache thread --- src/runtime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime.cpp b/src/runtime.cpp index d3972d6..b5e7168 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -407,7 +407,7 @@ void listen_messages(std::string message) { void start_listener() { logging::log_info(LOG_TAG, "Starting listener"); std::thread t1(listen_messages, "Hello"); -// t1.join(); + t1.detach(); } AWS_LAMBDA_RUNTIME_API From 3e5e5e5e7b04da09d2936a3140bb223dec83a121 Mon Sep 17 00:00:00 2001 From: Agner Esteves Ballejo Date: Fri, 17 Apr 2020 11:05:57 -0300 Subject: [PATCH 8/8] set handler --- src/runtime.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/runtime.cpp b/src/runtime.cpp index b5e7168..53aa2fb 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -397,23 +397,22 @@ static bool handle_post_outcome(runtime::post_outcome const& o, std::string cons return false; } -void listen_messages(std::string message) { - logging::log_info(LOG_TAG, "Executing thread %s", message.c_str()); +void listen_messages(std::function const& handler) { + logging::log_info(LOG_TAG, "Executing thread"); std::this_thread::sleep_for(std::chrono::milliseconds (20000)); - std::function handler; run_handler(handler); } -void start_listener() { +void start_listener(std::function const& handler) { logging::log_info(LOG_TAG, "Starting listener"); - std::thread t1(listen_messages, "Hello"); + std::thread t1(listen_messages, handler); t1.detach(); } AWS_LAMBDA_RUNTIME_API void run_handler(std::function const& handler) { - start_listener(); + start_listener(handler); logging::log_info(LOG_TAG, "Initializing the C++ Lambda Runtime version %s", aws::lambda_runtime::get_version()); std::string endpoint("http://");