Skip to content

Commit

Permalink
fix(server): Fix lambda capture in RunInParallel functions (#507)
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
  • Loading branch information
dranikpg authored Nov 21, 2022
1 parent 235ff67 commit da03cd8
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/server/engine_shard_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extern "C" {
#include "util/proactor_pool.h"
#include "util/sliding_counter.h"


namespace dfly {

namespace journal {
Expand Down Expand Up @@ -98,7 +97,6 @@ class EngineShard {
return &shard_lock_;
}


// TODO: Awkward interface. I should solve it somehow.
void ShutdownMulti(Transaction* multi);

Expand All @@ -113,7 +111,9 @@ class EngineShard {
// Returns used memory for this shard.
size_t UsedMemory() const;

TieredStorage* tiered_storage() { return tiered_storage_.get(); }
TieredStorage* tiered_storage() {
return tiered_storage_.get();
}

// Adds blocked transaction to the watch-list.
void AddBlocked(Transaction* trans);
Expand All @@ -125,13 +125,8 @@ class EngineShard {
// for everyone to use for string transformations during atomic cpu sequences.
sds tmp_str1;


// Moving average counters.
enum MovingCnt {
TTL_TRAVERSE,
TTL_DELETE,
COUNTER_TOTAL
};
enum MovingCnt { TTL_TRAVERSE, TTL_DELETE, COUNTER_TOTAL };

// Returns moving sum over the last 6 seconds.
uint32_t GetMovingSum6(MovingCnt type) const {
Expand All @@ -158,7 +153,6 @@ class EngineShard {

void CacheStats();


::util::fibers_ext::FiberQueue queue_;
::boost::fibers::fiber fiber_q_;

Expand Down Expand Up @@ -257,8 +251,8 @@ void EngineShardSet::RunBriefInParallel(U&& func, P&& pred) const {

bc.Add(1);
util::ProactorBase* dest = pp_->at(i);
dest->DispatchBrief([f = std::forward<U>(func), bc]() mutable {
f(EngineShard::tlocal());
dest->DispatchBrief([&func, bc]() mutable {
func(EngineShard::tlocal());
bc.Dec();
});
}
Expand All @@ -272,7 +266,7 @@ template <typename U> void EngineShardSet::RunBlockingInParallel(U&& func) {
util::ProactorBase* dest = pp_->at(i);

// the "Dispatch" call spawns a fiber underneath.
dest->Dispatch([func, bc]() mutable {
dest->Dispatch([&func, bc]() mutable {
func(EngineShard::tlocal());
bc.Dec();
});
Expand All @@ -285,7 +279,6 @@ inline ShardId Shard(std::string_view v, ShardId shard_num) {
return hash % shard_num;
}


// absl::GetCurrentTimeNanos is twice faster than clock_gettime(CLOCK_REALTIME) on my laptop
// and 4 times faster than on a VM. it takes 5-10ns to do a call.

Expand All @@ -295,7 +288,6 @@ inline uint64_t GetCurrentTimeMs() {
return TEST_current_time_ms ? TEST_current_time_ms : absl::GetCurrentTimeNanos() / 1000000;
}


extern EngineShardSet* shard_set;

} // namespace dfly

0 comments on commit da03cd8

Please sign in to comment.