]> git.saurik.com Git - apple/security.git/blobdiff - cdsa/cdsa_utilities/globalizer.cpp
Security-177.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / globalizer.cpp
index 0f7fa6299524ee84d64f8541b558e07980b483fa..03051e601995f509f9906ae02b649f50d8000608 100644 (file)
 //
 // @@@ Assumption: {bool,T*} atomic unless PTHREAD_STRICT
 //
-#ifdef __MWERKS__
-#define _CPP_GLOBALIZER
-#endif
 #include <Security/globalizer.h>
+#include <Security/debugging.h>
 #include <cstdlib>
 
 
 //
 // The Error class thrown if Nexus operations fail
 //
-GlobalNexus::Error::~Error()
+GlobalNexus::Error::~Error() throw()
 {
 }
 
@@ -70,8 +68,8 @@ GlobalNexus::Error::~Error()
 // WARNING:
 // This code makes the following non-portable assumptions:
 //  (a) NULL == 0 (binary representation of NULL pointer is zero value)
-//     Pointers acquired from new have at least their LSB zero (are at
-//  (b) least two-byte aligned).
+//     (b) Pointers acquired from new have at least their LSB zero (are at
+//      least two-byte aligned).
 // It seems like it's been a while since anyone made a machine/runtime that
 // violated either of those. But you have been warned.
 //
@@ -98,16 +96,17 @@ AtomicWord ModuleNexusCommon::create(void *(*make)())
                 void *singleton = make();
                 pointer = AtomicWord(singleton);
                 // we need a write barrier here, but the mutex->unlock below provides it for free
-                debug("nexus", "ModuleNexus %p constructed object 0x%x", this, pointer);
             } catch (...) {
-                               debug("nexus", "ModuleNexus %p construction failed", this);
+                               secdebug("nexus", "ModuleNexus %p construction failed", this);
                 mutex->unlock();
-                sync--;
-                //@@@ set up for retry here?
+                if (--sync == 0) {
+                    delete mutex;
+                    pointer = 0;
+                }
                 throw;
             }
         } else {
-            mutex = reinterpret_cast<Mutex *>(pointer & ~0x1);
+            mutex = reinterpret_cast<Mutex *>(initialPointer & ~0x1);
             mutex->lock();     // we'll wait here
         }
         mutex->unlock();