-
Notifications
You must be signed in to change notification settings - Fork 578
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 generate a mutex for each Locked<T>, share one per object #10117
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -454,8 +454,14 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) | |
m_Header << "template<>" << std::endl | ||
<< "class ObjectImpl<" << klass.Name << ">" | ||
<< " : public " << (klass.Parent.empty() ? "Object" : klass.Parent) << std::endl | ||
<< "{" << std::endl | ||
<< "public:" << std::endl | ||
<< "{" << std::endl; | ||
|
||
if (klass.Parent.empty()) { | ||
m_Header << "protected:" << std::endl | ||
<< "\tmutable LockedMutex m_FieldsMutex;" << std::endl << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And the cool "side" effect here is that the amount of mutexes scales linear with the amount of objects. So, in contrast to a central array of mutexes created at reload time, you guaranteed won't ever have too few mutexes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you think there would be a problem with "too few mutexes"? Like you'll have a more or less fixed number of threads started by Icinga 2, so that limits the concurrency and would be a good candidate for sizing the number of mutexes in a I'm not opposed to the idea of using one mutex per object, however, the current PR introduces a quite strange interface with Nonetheless, I still don't think that would be necessary and having a global array of mutexes would suffice and keep the implementation simpler. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No. I don't. I don't know. I don't know how many mutexes are enough – The more radically you change a running system in an amount of time, the more likely you hit a (delayed) black swan. Like JSON-RPC crash one (v2.11.3), JSON-RPC crash two (v2.11.4), IcingaDB(?) OOM ref/NC/820479 (v2.?) ...
👍Btw. I'm neither opposed to yours.
No, yes and no.
mkclass is surely a good tool for stuff that would be significantly(?) more difficult in vanilla C++. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I went down the rabbit hole quite a bit. The GCC implementation for the These function use a RAII-style locker called To be honest, that wasn't really what I was expecting and I knew I found something different when initially suggesting this. Luckily I found it again, it was this answer on Stack Overflow for a somewhat related but different question, namely how For completeness: |
||
} | ||
|
||
m_Header << "public:" << std::endl | ||
<< "\t" << "DECLARE_PTR_TYPEDEFS(ObjectImpl<" << klass.Name << ">);" << std::endl << std::endl; | ||
|
||
/* Validate */ | ||
|
@@ -815,7 +821,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) | |
<< "{" << std::endl; | ||
|
||
if (field.GetAccessor.empty() && !(field.Attributes & FANoStorage)) | ||
m_Impl << "\t" << "return m_" << field.GetFriendlyName() << ".load();" << std::endl; | ||
m_Impl << "\t" << "return m_" << field.GetFriendlyName() << ".load(m_FieldsMutex);" << std::endl; | ||
else | ||
m_Impl << field.GetAccessor << std::endl; | ||
|
||
|
@@ -853,7 +859,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) | |
<< "\t" << "auto *dobj = dynamic_cast<ConfigObject *>(this);" << std::endl; | ||
|
||
if (field.SetAccessor.empty() && !(field.Attributes & FANoStorage)) | ||
m_Impl << "\t" << "m_" << field.GetFriendlyName() << ".store(value);" << std::endl; | ||
m_Impl << "\t" << "m_" << field.GetFriendlyName() << ".store(value, m_FieldsMutex);" << std::endl; | ||
else | ||
m_Impl << field.SetAccessor << std::endl << std::endl; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed it. :)