Skip to content

Commit 013a64c

Browse files
committed
fixed thread safe inject
1 parent 78a2cce commit 013a64c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • framework/global/thirdparty/kors_modularity/modularity

framework/global/thirdparty/kors_modularity/modularity/ioc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class InjectBase
118118
{
119119
static std::string_view module = "";
120120
m_i = ioc->template resolve<I>(module);
121-
if (m_i) {
121+
if (m_i && m_isSubscribe) {
122122
m_subscriber.onChanged = [this](const std::shared_ptr<I>& p) {
123123
m_i = p;
124124
};
@@ -129,6 +129,7 @@ class InjectBase
129129
const ContextPtr m_ctx;
130130
const Contextable* m_inj = nullptr;
131131
mutable std::shared_ptr<I> m_i = nullptr;
132+
bool m_isSubscribe = true;
132133
mutable Subscriber<I> m_subscriber;
133134
};
134135

@@ -148,6 +149,9 @@ class ThreadSafeInjectBase : public InjectBase<I>
148149
}
149150

150151
std::unique_lock lock(m_mutex);
152+
//! NOTE Subscribing to changes is not thread-safe,
153+
// so it is disabled for ThreadSafeInject.
154+
InjectBase<I>::m_isSubscribe = false;
151155
return InjectBase<I>::get();
152156
}
153157

0 commit comments

Comments
 (0)