Skip to content

Commit 7614d91

Browse files
authored
Merge pull request #884 from redboltz/remove_redundant_comp_from_bench
Removed redundant comparison code.
2 parents befeca5 + 51221ab commit 7614d91

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

example/bench.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@
1818

1919
namespace as = boost::asio;
2020

21-
template <typename T>
22-
bool compare_decrement(std::atomic<T>& val, T comp) {
23-
T old = val.load();
24-
do {
25-
if (old == comp) return true;
26-
} while (!val.compare_exchange_weak(old, old - 1));
27-
return false;
28-
}
29-
3021
int main(int argc, char **argv) {
3122
try {
3223
boost::program_options::options_description desc;
@@ -577,7 +568,7 @@ int main(int argc, char **argv) {
577568
async_wait_pub(ci);
578569
}
579570

580-
if (compare_decrement(rest_times, std::uint64_t(1))) finish_proc();
571+
if (--rest_times == 0) finish_proc();
581572
return true;
582573
};
583574

@@ -592,7 +583,7 @@ int main(int argc, char **argv) {
592583
[&]
593584
(bool /*sp*/, MQTT_NS::connect_return_code connack_return_code) {
594585
if (connack_return_code == MQTT_NS::connect_return_code::accepted) {
595-
if (compare_decrement(rest_connect, std::size_t(1))) sub_proc();
586+
if (--rest_connect == 0) sub_proc();
596587
}
597588
else {
598589
std::cout << "connack error:" << connack_return_code << std::endl;
@@ -604,7 +595,7 @@ int main(int argc, char **argv) {
604595
[&]
605596
(bool /*sp*/, MQTT_NS::v5::connect_reason_code reason_code, MQTT_NS::v5::properties /*props*/) {
606597
if (reason_code == MQTT_NS::v5::connect_reason_code::success) {
607-
if (compare_decrement(rest_connect, std::size_t(1))) sub_proc();
598+
if (--rest_connect == 0) sub_proc();
608599
}
609600
else {
610601
std::cout << "connack error:" << reason_code << std::endl;
@@ -620,7 +611,7 @@ int main(int argc, char **argv) {
620611
if (results.front() == MQTT_NS::suback_return_code::success_maximum_qos_0 ||
621612
results.front() == MQTT_NS::suback_return_code::success_maximum_qos_1 ||
622613
results.front() == MQTT_NS::suback_return_code::success_maximum_qos_2) {
623-
if (compare_decrement(rest_sub, std::size_t(1))) pub_proc();
614+
if (--rest_sub == 0) pub_proc();
624615
}
625616
return true;
626617
}
@@ -634,7 +625,7 @@ int main(int argc, char **argv) {
634625
if (reasons.front() == MQTT_NS::v5::suback_reason_code::granted_qos_0 ||
635626
reasons.front() == MQTT_NS::v5::suback_reason_code::granted_qos_1 ||
636627
reasons.front() == MQTT_NS::v5::suback_reason_code::granted_qos_2) {
637-
if (compare_decrement(rest_sub, std::size_t(1))) pub_proc();
628+
if (--rest_sub == 0) pub_proc();
638629
}
639630
return true;
640631
}

0 commit comments

Comments
 (0)