Skip to content

Commit

Permalink
perf: 优化更多原子操作
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Nov 29, 2023
1 parent 071eee8 commit 586025b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Magpie.Core/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,17 @@ bool Renderer::_BuildEffects() {

// 并行编译所有效果
std::vector<EffectDesc> effectDescs(effectsOption.size());
std::atomic<bool> allSuccess = true;
std::atomic<bool> anyFailure;

int duration = Utils::Measure([&]() {
Win32Utils::RunParallel([&](uint32_t id) {
if (!CompileEffect(id == effectCount - 1, effectsOption[id], effectDescs[id])) {
allSuccess = false;
anyFailure.store(true, std::memory_order_relaxed);
}
}, effectCount);
});

if (!allSuccess) {
if (anyFailure.load(std::memory_order_relaxed)) {
return false;
}

Expand Down Expand Up @@ -390,12 +390,12 @@ bool Renderer::_BuildEffects() {
id == 0 ? effectsOption.back() : downscalingEffectOption,
id == 0 ? effectDescs.back() : downscalingEffectDesc
)) {
allSuccess = false;
anyFailure.store(true, std::memory_order_relaxed);
}
}, 2);
});

if (!allSuccess) {
if (anyFailure.load(std::memory_order_relaxed)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Shared/Win32Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ struct TPContext {

static void CALLBACK TPCallback(PTP_CALLBACK_INSTANCE, PVOID context, PTP_WORK) {
TPContext* ctxt = (TPContext*)context;
uint32_t id = ++ctxt->id;
const uint32_t id = ctxt->id.fetch_add(1, std::memory_order_relaxed) + 1;
ctxt->func(id);
}

Expand Down

0 comments on commit 586025b

Please sign in to comment.