This is an automated email from the ASF dual-hosted git repository.
bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push:
new c5c4675 GEODE-6300: Fix AddDomain gripe in CLI tests (#436)
c5c4675 is described below
commit c5c46751ad6198438ca95e9023d2970edf765e5c
Author: Blake Bender <[email protected]>
AuthorDate: Tue Jan 22 11:01:53 2019 -0800
GEODE-6300: Fix AddDomain gripe in CLI tests (#436)
* Make sure *everything* run in thread pool gets the right
AppDomain context
Co-authored-by: Matthew Reddington <[email protected]>
---
cppcache/src/ThreadPool.cpp | 56 ++++++++++++++++++++++++++-------------------
cppcache/src/ThreadPool.hpp | 3 +++
2 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/cppcache/src/ThreadPool.cpp b/cppcache/src/ThreadPool.cpp
index a20af5c..f9212d9 100644
--- a/cppcache/src/ThreadPool.cpp
+++ b/cppcache/src/ThreadPool.cpp
@@ -25,32 +25,40 @@ namespace client {
const char* ThreadPool::NC_Pool_Thread = "NC Pool Thread";
-ThreadPool::ThreadPool(size_t threadPoolSize) : shutdown_(false) {
+ThreadPool::ThreadPool(size_t threadPoolSize)
+ : shutdown_(false), appDomainContext_(createAppDomainContext()) {
workers_.reserve(threadPoolSize);
- for (size_t i = 0; i < threadPoolSize; i++) {
- workers_.emplace_back([this] {
- DistributedSystemImpl::setThreadName(NC_Pool_Thread);
- while (true) {
- std::unique_lock<decltype(queueMutex_)> lock(queueMutex_);
- queueCondition_.wait(lock,
- [this] { return shutdown_ || !queue_.empty(); });
-
- if (shutdown_) {
- break;
- }
-
- auto work = queue_.front();
- queue_.pop_front();
-
- lock.unlock();
-
- try {
- work->call();
- } catch (...) {
- // ignore
- }
+
+ std::function<void()> executeWork = [this] {
+ DistributedSystemImpl::setThreadName(NC_Pool_Thread);
+ while (true) {
+ std::unique_lock<decltype(queueMutex_)> lock(queueMutex_);
+ queueCondition_.wait(lock,
+ [this] { return shutdown_ || !queue_.empty(); });
+
+ if (shutdown_) {
+ break;
+ }
+
+ auto work = queue_.front();
+ queue_.pop_front();
+
+ lock.unlock();
+
+ try {
+ work->call();
+ } catch (...) {
+ // ignore
}
- });
+ }
+ };
+
+ if (appDomainContext_) {
+ executeWork = [executeWork, this] { appDomainContext_->run(executeWork); };
+ }
+
+ for (size_t i = 0; i < threadPoolSize; i++) {
+ workers_.emplace_back(executeWork);
}
}
diff --git a/cppcache/src/ThreadPool.hpp b/cppcache/src/ThreadPool.hpp
index a8dd49d..d72f12a 100644
--- a/cppcache/src/ThreadPool.hpp
+++ b/cppcache/src/ThreadPool.hpp
@@ -27,6 +27,8 @@
#include <thread>
#include <vector>
+#include "AppDomainContext.hpp"
+
namespace apache {
namespace geode {
namespace client {
@@ -90,6 +92,7 @@ class ThreadPool {
std::mutex queueMutex_;
std::condition_variable queueCondition_;
static const char* NC_Pool_Thread;
+ AppDomainContext* appDomainContext_;
};
} // namespace client