]> git.saurik.com Git - apple/securityd.git/blobdiff - src/structure.cpp
securityd-55199.3.tar.gz
[apple/securityd.git] / src / structure.cpp
index 4d6dd364edf5eaaf4e032a3c76017e5adb65365d..effd439e56c07dc2b195980f7d0899de3d3d75f6 100644 (file)
@@ -3,8 +3,6 @@
  * 
  * @APPLE_LICENSE_HEADER_START@
  * 
  * 
  * @APPLE_LICENSE_HEADER_START@
  * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
- * 
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
@@ -43,6 +41,56 @@ NodeCore::~NodeCore()
 }
 
 
 }
 
 
+//
+// Basic object mesh maintainance
+//
+void NodeCore::parent(NodeCore &p)
+{
+       StLock<Mutex> _(*this);
+       mParent = &p;
+}
+
+void NodeCore::referent(NodeCore &r)
+{
+       StLock<Mutex> _(*this);
+       assert(!mReferent);
+       mReferent = &r;
+}
+       
+void NodeCore::clearReferent()
+{
+       StLock<Mutex> _(*this);
+       if (mReferent)
+               assert(!mReferent->hasReference(*this));
+       mReferent = NULL;
+}
+
+
+void NodeCore::addReference(NodeCore &p)
+{
+       StLock<Mutex> _(*this);
+       assert(p.mReferent == this);
+       mReferences.insert(&p);
+}
+
+void NodeCore::removeReference(NodeCore &p)
+{
+       StLock<Mutex> _(*this);
+       assert(hasReference(p));
+       mReferences.erase(&p);
+}
+
+#if !defined(NDEBUG)
+
+bool NodeCore::hasReference(NodeCore &p)
+{
+       assert(p.refCountForDebuggingOnly() > 0);
+       return mReferences.find(&p) != mReferences.end();
+}
+
+#endif //NDEBUG
+
+
 //
 // ClearReferences clears the reference set but does not propagate
 // anything; it is NOT recursive.
 //
 // ClearReferences clears the reference set but does not propagate
 // anything; it is NOT recursive.
@@ -72,6 +120,15 @@ void NodeCore::kill()
 }
 
 
 }
 
 
+void NodeCore::kill(NodeCore &ref)
+{
+       StLock<Mutex> _(*this);
+       assert(hasReference(ref));
+       ref.kill();
+       removeReference(ref);
+}
+
+
 //
 // NodeCore-level support for state dumping.
 // Call NodeCore::dumpAll() to debug-dump all nodes.
 //
 // NodeCore-level support for state dumping.
 // Call NodeCore::dumpAll() to debug-dump all nodes.
@@ -96,7 +153,7 @@ NodeCore::NodeCore()
 // override this to add text to your Node type's state dump output
 void NodeCore::dumpNode()
 {
 // override this to add text to your Node type's state dump output
 void NodeCore::dumpNode()
 {
      Debug::dump("%s@%p rc=%u", Debug::typeName(*this).c_str(), this, unsigned(refCountForDebuggingOnly()));
+ Debug::dump("%s@%p rc=%u", Debug::typeName(*this).c_str(), this, unsigned(refCountForDebuggingOnly()));
        if (mParent)
                Debug::dump(" parent=%p", mParent.get());
        if (mReferent)
        if (mParent)
                Debug::dump(" parent=%p", mParent.get());
        if (mReferent)
@@ -107,11 +164,14 @@ void NodeCore::dumpNode()
 // override this to completely re-implement the dump format for your Node type
 void NodeCore::dump()
 {
 // override this to completely re-implement the dump format for your Node type
 void NodeCore::dump()
 {
      dumpNode();
+ dumpNode();
        if (!mReferences.empty()) {
                Debug::dump(" {");
        if (!mReferences.empty()) {
                Debug::dump(" {");
-               for (ReferenceSet::const_iterator it = mReferences.begin(); it != mReferences.end(); it++)
+               for (ReferenceSet::const_iterator it = mReferences.begin(); it != mReferences.end(); it++) {
                        Debug::dump(" %p", it->get());
                        Debug::dump(" %p", it->get());
+                       if ((*it)->mReferent != this)
+                               Debug::dump("!*INVALID*");
+               }
                Debug::dump(" }");
        }
        Debug::dump("\n");
                Debug::dump(" }");
        }
        Debug::dump("\n");
@@ -120,7 +180,7 @@ void NodeCore::dump()
 // dump all known nodes
 void NodeCore::dumpAll()
 {
 // dump all known nodes
 void NodeCore::dumpAll()
 {
      StLock<Mutex> _(mCoreLock);
+ StLock<Mutex> _(mCoreLock);
        time_t now; time(&now);
        Debug::dump("\nNODE DUMP (%24.24s)\n", ctime(&now));
        for (set<NodeCore *>::const_iterator it = mCoreNodes.begin(); it != mCoreNodes.end(); it++)
        time_t now; time(&now);
        Debug::dump("\nNODE DUMP (%24.24s)\n", ctime(&now));
        for (set<NodeCore *>::const_iterator it = mCoreNodes.begin(); it != mCoreNodes.end(); it++)