diff --git a/src/load_balancing.cpp b/src/load_balancing.cpp index 06ce918ed..5d9d577d8 100644 --- a/src/load_balancing.cpp +++ b/src/load_balancing.cpp @@ -18,16 +18,18 @@ namespace cass { ControlConnection* LoadBalancingPolicy::control_connection() { - return session_ == NULL ? NULL : session_->control_connection(); + auto* session = session_.load(std::memory_order_acquire); + return session ? session->control_connection() : nullptr; } const Metadata* LoadBalancingPolicy::metadata() const { - const Session* s = session_; // const cast - return s == NULL ? NULL : &s->metadata(); + const auto* session = session_.load(std::memory_order_acquire); + return session ? &session->metadata() : nullptr; } const TokenMap* LoadBalancingPolicy::token_map() const { - return session_ == NULL ? NULL : session_->token_map(); + auto* session = session_.load(std::memory_order_acquire); + return session ? session->token_map() : nullptr; } } // namespace cass diff --git a/src/load_balancing.hpp b/src/load_balancing.hpp index b42b26edf..d4831b0da 100644 --- a/src/load_balancing.hpp +++ b/src/load_balancing.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -82,7 +83,7 @@ class LoadBalancingPolicy : public Host::StateListener, public RefCounted Ptr; LoadBalancingPolicy() - : RefCounted(), session_(NULL) {} + : RefCounted() {} virtual ~LoadBalancingPolicy() {} @@ -112,7 +113,8 @@ class LoadBalancingPolicy : public Host::StateListener, public RefCounted session_{nullptr}; }; diff --git a/src/partition_aware_policy.cpp b/src/partition_aware_policy.cpp index 204d77df0..d4140e2ff 100644 --- a/src/partition_aware_policy.cpp +++ b/src/partition_aware_policy.cpp @@ -202,7 +202,8 @@ QueryPlan* PartitionAwarePolicy::new_query_plan(const std::string& keyspace, RequestHandler* request_handler) { QueryPlan* const child_plan = child_policy_->new_query_plan(keyspace, request_handler); - if (request_handler == NULL || request_handler->request() == NULL || metadata() == NULL) { + auto* metadata = this->metadata(); + if (request_handler == NULL || request_handler->request() == NULL || metadata == NULL) { LOG_TRACE("Request or metadata is not available - child policy will be used"); return child_plan; } @@ -215,7 +216,7 @@ QueryPlan* PartitionAwarePolicy::new_query_plan(const std::string& keyspace, return child_plan; } - const Metadata::SchemaSnapshot schema = metadata()->schema_snapshot( + const Metadata::SchemaSnapshot schema = metadata->schema_snapshot( CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION, VersionNumber(3, 0, 0)); const TableSplitMetadata::MapPtr& partitions = schema.get_partitions();