Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use stacks #690

Merged
merged 1 commit into from Jul 29, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/autowiring/CoreContext.cpp
Expand Up @@ -15,7 +15,6 @@
#include "thread_specific_ptr.h"
#include "ThreadPool.h"
#include <sstream>
#include <stack>
#include <stdexcept>

using namespace autowiring;
Expand Down Expand Up @@ -819,22 +818,22 @@ void CoreContext::SatisfyAutowiring(std::unique_lock<std::mutex>& lk, MemoEntry&
// Now we need to take on the responsibility of satisfying this deferral. We will do this by
// nullifying the flink, and by ensuring that the memo is satisfied at the point where we
// release the lock.
std::stack<DeferrableAutowiring*> stk;
stk.push(entry.pFirst);
std::vector<DeferrableAutowiring*> stk;
stk.push_back(entry.pFirst);
entry.pFirst = nullptr;

// Depth-first search
while (!stk.empty()) {
auto top = stk.top();
stk.pop();
auto top = stk.back();
stk.pop_back();

for (DeferrableAutowiring* pCur = top; pCur; pCur = pCur->GetFlink()) {
pCur->SatisfyAutowiring(entry.m_value);

// See if there's another chain we need to process:
auto child = pCur->ReleaseDependentChain();
if (child)
stk.push(child);
stk.push_back(child);

// Not everyone needs to be finalized. The entities that don't require finalization
// are identified by an empty strategy, and we just skip them.
Expand Down Expand Up @@ -892,7 +891,7 @@ void CoreContext::UpdateDeferredElements(std::unique_lock<std::mutex>&& lk, cons
// also removed at the same time.
//
// Each connected nonroot deferrable autowiring is referred to as a "dependant chain".
std::stack<DeferrableAutowiring*> stk;
std::vector<DeferrableAutowiring*> stk;
for (auto& cur : m_typeMemos) {
MemoEntry& value = cur.second;

Expand All @@ -915,21 +914,21 @@ void CoreContext::UpdateDeferredElements(std::unique_lock<std::mutex>&& lk, cons
// Now we need to take on the responsibility of satisfying this deferral. We will do this by
// nullifying the flink, and by ensuring that the memo is satisfied at the point where we
// release the lock.
stk.push(value.pFirst);
stk.push_back(value.pFirst);
value.pFirst = nullptr;

// Finish satisfying the remainder of the chain while we hold the lock:
while (!stk.empty()) {
auto top = stk.top();
stk.pop();
auto top = stk.back();
stk.pop_back();

for (DeferrableAutowiring* pNext = top; pNext; pNext = pNext->GetFlink()) {
pNext->SatisfyAutowiring(value.m_value);

// See if there's another chain we need to process:
auto child = pNext->ReleaseDependentChain();
if (child)
stk.push(child);
stk.push_back(child);

// Not everyone needs to be finalized. The entities that don't require finalization
// are identified by an empty strategy, and we just skip them.
Expand Down