diff --git a/src/core/all_cases/all_cases.h b/src/core/all_cases/all_cases.h index 8b6d804..8164546 100644 --- a/src/core/all_cases/all_cases.h +++ b/src/core/all_cases/all_cases.h @@ -45,7 +45,7 @@ namespace klotski::cases { -// ------------------------------------------------------------------------------------- // +// ----------------------------------------------------------------------------------------- // class BasicRanges { public: @@ -71,7 +71,7 @@ private: KLSK_INSTANCE(BasicRanges) }; -// ------------------------------------------------------------------------------------- // +// ----------------------------------------------------------------------------------------- // class AllCases { public: @@ -97,7 +97,7 @@ private: KLSK_INSTANCE(AllCases) }; -// ------------------------------------------------------------------------------------- // +// ----------------------------------------------------------------------------------------- // } // namespace klotski::cases diff --git a/src/core/all_cases/internal/all_cases.cc b/src/core/all_cases/internal/all_cases.cc index 610aaf1..b9be571 100644 --- a/src/core/all_cases/internal/all_cases.cc +++ b/src/core/all_cases/internal/all_cases.cc @@ -54,7 +54,7 @@ void AllCases::build() { if (available_) { return; // reduce consumption of mutex } - std::lock_guard guard {building_}; + const std::lock_guard guard {building_}; if (available_) { return; // data is already available } @@ -68,6 +68,7 @@ void AllCases::build() { build_cases(ranges, reversed, get_cases()[head], head); } available_ = true; + KLSK_MEM_BARRIER; } void AllCases::build_async(Executor &&executor, Notifier &&callback) { @@ -97,6 +98,7 @@ void AllCases::build_async(Executor &&executor, Notifier &&callback) { worker.then([this, callback = std::move(callback)] { available_ = true; + KLSK_MEM_BARRIER; building_.unlock(); callback(); }); diff --git a/src/core/all_cases/internal/basic_ranges.cc b/src/core/all_cases/internal/basic_ranges.cc index 6aa079f..e194aec 100644 --- a/src/core/all_cases/internal/basic_ranges.cc +++ b/src/core/all_cases/internal/basic_ranges.cc @@ -8,9 +8,9 @@ using klotski::cases::Ranges; using klotski::cases::BasicRanges; using klotski::cases::TYPE_ID_LIMIT; -typedef Ranges::iterator RangesIter; -typedef std::tuple RangeType; -typedef std::array RangeTypeUnion; +using RangesIter = Ranges::iterator ; +using RangeType = std::tuple ; +using RangeTypeUnion = std::array; /// Generate all possible basic-ranges permutations. consteval static RangeTypeUnion range_types() { @@ -34,8 +34,9 @@ static void inplace_merge(RangesIter begin, RangesIter mid, const RangesIter end for (auto p = tmp.begin();;) { if (*p <= *mid) { *(begin++) = *(p++); // stored in original span - if (p == tmp.end()) // left array is consumed + if (p == tmp.end()) { // left array is consumed return; + } continue; } *(begin++) = *(mid++); // stored in original span @@ -50,7 +51,7 @@ void BasicRanges::build() { if (available_) { return; // reduce consumption of mutex } - std::lock_guard guard {building_}; + const std::lock_guard guard {building_}; if (available_) { return; // data is already available } @@ -78,6 +79,7 @@ void BasicRanges::build() { } while (points.size() > 2); // merge until only one interval remains available_ = true; + KLSK_MEM_BARRIER; } void BasicRanges::build_async(Executor &&executor, Notifier &&callback) { @@ -94,6 +96,7 @@ void BasicRanges::build_async(Executor &&executor, Notifier &&callback) { auto all_done = [this, callback = std::move(callback)] { available_ = true; + KLSK_MEM_BARRIER; building_.unlock(); callback(); };