< Previous by Date Date Index Next by Date >
  Thread Index  

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


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)