Skip to content

Commit

Permalink
Replaces goto with deferer object
Browse files Browse the repository at this point in the history
  • Loading branch information
vimes committed Dec 12, 2024
1 parent a731187 commit e8acf78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
22 changes: 22 additions & 0 deletions common/deferer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace utils
{

template<typename F>
class Deferer
{
F action_;

public:
Deferer(F&& action): action_{std::move(action)}
{}
Deferer(const Deferer& other) = delete;
Deferer(Deferer&& other) = delete;
Deferer& operator=(const Deferer& other) = delete;
Deferer& operator=(Deferer&& other) = delete;
~Deferer()
{
action_();
}
};

} // namespace utils
6 changes: 3 additions & 3 deletions dataplane/globalbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "common/counters.h"
#include "common/define.h"
#include "common/deferer.h"

#include "debug_latch.h"

Expand Down Expand Up @@ -1612,6 +1613,7 @@ balancer_real_id_t* generation::rebuild_service_ring_one_wrr(
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service)
{
utils::Deferer defer([](){YADECAP_MEMORY_BARRIER_COMPILE;});
for (uint32_t real_idx = service->real_start;
real_idx < service->real_start + service->real_size;
++real_idx)
Expand All @@ -1631,15 +1633,13 @@ balancer_real_id_t* generation::rebuild_service_ring_one_wrr(
if (start == do_not_exceed)
{
YANET_LOG_ERROR("Balancer service exceeded ring chunk bounds\n");
goto finish;
return start;
}
*start = real_id;
++start;
}
}

finish:
YADECAP_MEMORY_BARRIER_COMPILE;
return start;
}

Expand Down

0 comments on commit e8acf78

Please sign in to comment.