]>
git.saurik.com Git - apple/securityd.git/blob - src/structure.cpp
4d6dd364edf5eaaf4e032a3c76017e5adb65365d
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 // structure - structural framework for securityd objects
30 #include "structure.h"
34 // NodeCore always has a destructor (because it's virtual),
35 // but its dump support is conditionally included.
39 #if defined(DEBUGDUMP)
40 StLock
<Mutex
> _(mCoreLock
);
41 mCoreNodes
.erase(this);
47 // ClearReferences clears the reference set but does not propagate
48 // anything; it is NOT recursive.
50 void NodeCore::clearReferences()
52 StLock
<Mutex
> _(*this);
53 secdebug("ssnode", "%p clearing all %d references",
54 this, int(mReferences
.size()));
55 mReferences
.erase(mReferences
.begin(), mReferences
.end());
60 // Kill should be overloaded by Nodes to implement any cleanup and release
61 // operations that should happen at LOGICAL death of the represented object.
62 // This is where you should release ports, close files, etc.
63 // This default behavior, which you MUST include in your override,
64 // propagates kills to all active references, recursively.
68 StLock
<Mutex
> _(*this);
69 for (ReferenceSet::const_iterator it
= mReferences
.begin(); it
!= mReferences
.end(); it
++)
76 // NodeCore-level support for state dumping.
77 // Call NodeCore::dumpAll() to debug-dump all nodes.
78 // Note that enabling DEBUGDUMP serializes all node creation/destruction
79 // operations, and thus may cause significant shifts in thread interactions.
81 #if defined(DEBUGDUMP)
83 // The (uncounted) set of all known NodeCores in existence, with protective lock
84 set
<NodeCore
*> NodeCore::mCoreNodes
;
85 Mutex
NodeCore::mCoreLock
;
87 // add a new NodeCore to the known set
89 : Mutex(Mutex::recursive
)
91 StLock
<Mutex
> _(mCoreLock
);
92 mCoreNodes
.insert(this);
95 // partial-line common dump text for any NodeCore
96 // override this to add text to your Node type's state dump output
97 void NodeCore::dumpNode()
99 Debug::dump("%s@%p rc=%u", Debug::typeName(*this).c_str(), this, unsigned(refCountForDebuggingOnly()));
101 Debug::dump(" parent=%p", mParent
.get());
103 Debug::dump(" referent=%p", mReferent
.get());
106 // full-line dump of a NodeCore
107 // override this to completely re-implement the dump format for your Node type
108 void NodeCore::dump()
111 if (!mReferences
.empty()) {
113 for (ReferenceSet::const_iterator it
= mReferences
.begin(); it
!= mReferences
.end(); it
++)
114 Debug::dump(" %p", it
->get());
120 // dump all known nodes
121 void NodeCore::dumpAll()
123 StLock
<Mutex
> _(mCoreLock
);
124 time_t now
; time(&now
);
125 Debug::dump("\nNODE DUMP (%24.24s)\n", ctime(&now
));
126 for (set
<NodeCore
*>::const_iterator it
= mCoreNodes
.begin(); it
!= mCoreNodes
.end(); it
++)
128 Debug::dump("END NODE DUMP\n\n");