[reSIProcate] [Patch] Fix assert in mac with ContentsFactoryBase

Aron Rosenberg arosenberg at logitech.com
Fri Mar 25 14:31:00 CDT 2011


I am seeing an assert with gcc on Mac in debug mode where the assertion in
ContentsFactoryBase.cxx line 14 is being triggered all the time

ContentsFactoryBase::ContentsFactoryBase(const Mime& contentType)
    : mContentType(contentType)
{
   assert(ContentsFactoryBase::getFactoryMap().count(contentType) == 0);
<----- Here
   ContentsFactoryBase::getFactoryMap()[contentType] = this;
}

This is occurring because of how the all the various Contents classes are
inited, and an issue with multi-core and static / global initializers

Using  SdpContents as an example

SdpContents.hxx:
class SdpContents { .. }
static bool invokeSdpContentsInit = SdpContents::init();

In gcc, because "static" means file local, every file which includes the
SdpContents.hxx gets an invocation to SdpContents::init() in its own .o
file.

Then due to the fact that in functions, static member initializers aren't
multi-thread and multi-core safe (See Scott's rev 8871 changes), this causes
SdpContents::init() to be called for every file which included
SdpContents.hxx and triggering the eventual assertion in
ContentsFactoryBase.

The following patch fixes the issue, but is there a better way?? If I don't
hear anything, I will commit the change next week.

Index: resip/stack/ContentsFactoryBase.cxx
===================================================================
--- resip/stack/ContentsFactoryBase.cxx (revision 9087)
+++ resip/stack/ContentsFactoryBase.cxx (working copy)
@@ -11,8 +11,10 @@
 ContentsFactoryBase::ContentsFactoryBase(const Mime& contentType)
    : mContentType(contentType)
 {
-   assert(ContentsFactoryBase::getFactoryMap().count(contentType) == 0);
-   ContentsFactoryBase::getFactoryMap()[contentType] = this;
+   // .amr. Due to multiple static initializers, this can be called more
than once for a mimetype
+   // so gracefully handle it
+   if(ContentsFactoryBase::getFactoryMap().count(contentType) == 0)
+      ContentsFactoryBase::getFactoryMap()[contentType] = this;
 }

 ContentsFactoryBase::~ContentsFactoryBase()



Aron Rosenberg
Sr. Director, Engineering
Logitech Inc. (SightSpeed Group)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.resiprocate.org/pipermail/resiprocate-devel/attachments/20110325/e8c8eae2/attachment.htm>


More information about the resiprocate-devel mailing list