Copilot commented on code in PR #3116:
URL: https://github.com/apache/brpc/pull/3116#discussion_r2425113701
##########
src/bvar/reducer.h:
##########
@@ -283,41 +421,112 @@ class Maxer : public Reducer<T, detail::MaxTo<T> > {
}
};
+#if WITH_BABYLON_COUNTER
+namespace detail {
+template <typename T>
+class ConcurrentMaxer : public babylon::GenericsConcurrentMaxer<T> {
+ typedef babylon::GenericsConcurrentMaxer<T> Base;
+public:
+ ConcurrentMaxer() = default;
+ ConcurrentMaxer(T default_value) : _default_value(default_value) {}
+
+ T value() const {
+ T result;
+ if (!Base::value(result)) {
+ return _default_value;
+ }
+ return std::max(result, _default_value);
+ }
+private:
+ T _default_value{0};
+};
+} // namespace detail
+
+// Numerical types supported by babylon counter.
+template <typename T>
+class Maxer<T,
std::enable_if<std::is_constructible<detail::ConcurrentMaxer<T>>::value>>
+ : public detail::BabylonVariable<T, detail::ConcurrentMaxer<T>,
+ detail::MaxTo<T>, detail::VoidOp> {
+public:
+ typedef T value_type;
+private:
+ typedef detail::BabylonVariable<T, detail::ConcurrentMaxer<T>,
+ detail::MaxTo<value_type>, detail::VoidOp>
Base;
+public:
+ typedef detail::MaxTo<value_type> Op;
+ typedef detail::VoidOp InvOp;
+ typedef typename Base::sampler_type sampler_type;
+
+ COMMON_VARIABLE_CONSTRUCTOR(Maxer);
+
+private:
+friend class detail::LatencyRecorderBase;
+
+ Maxer(T default_value) : Base(default_value) {}
+ Maxer(T default_value, const butil::StringPiece& prefix, const
butil::StringPiece& name)
+ : Base(default_value) {
+ Variable::expose_as(prefix, name);
+ }
+ Maxer(T default_value, const butil::StringPiece& name)
+ : Base(default_value) {
+ Variable::expose(name);
+ }
+};
+#endif // WITH_BABYLON_COUNTER
+
// bvar::Miner<int> min_value;
// min_value << 1 << 2 << 3 << 4;
// LOG(INFO) << min_value.get_value(); // 1
namespace detail {
-
-template <typename Tp>
+template <typename Tp>
struct MinTo {
- void operator()(Tp & lhs,
+ void operator()(Tp & lhs,
typename butil::add_cr_non_integral<Tp>::type rhs) const {
if (rhs < lhs) {
lhs = rhs;
}
}
};
-
} // namespace detail
-template <typename T>
+template <typename T, typename = void>
class Miner : public Reducer<T, detail::MinTo<T> > {
public:
typedef Reducer<T, detail::MinTo<T> > Base;
typedef T value_type;
typedef typename Base::sampler_type sampler_type;
-public:
+
Miner() : Base(std::numeric_limits<T>::max()) {}
- explicit Miner(const butil::StringPiece& name)
+ Miner(const butil::StringPiece& name)
: Base(std::numeric_limits<T>::max()) {
this->expose(name);
}
Miner(const butil::StringPiece& prefix, const butil::StringPiece& name)
: Base(std::numeric_limits<T>::max()) {
this->expose_as(prefix, name);
}
- ~Miner() { Variable::hide(); }
+ ~Miner() override { Variable::hide(); }
+};
+
+#if WITH_BABYLON_COUNTER
+// Numerical types supported by babylon counter.
+template <typename T>
+class Miner<T,
std::enable_if<std::is_constructible<babylon::GenericsConcurrentMiner<T>>::value>>
Review Comment:
The template specialization is missing the second template parameter type.
Should be
`std::enable_if<std::is_constructible<babylon::GenericsConcurrentMiner<T>>::value>::type`.
```suggestion
class Miner<T, typename
std::enable_if<std::is_constructible<babylon::GenericsConcurrentMiner<T>>::value>::type>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]