]>
git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSObject.cpp
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* OSObject.cpp created by gvdl on Fri 1998-11-17 */
24 #include <libkern/c++/OSObject.h>
25 #include <libkern/c++/OSSerialize.h>
26 #include <libkern/c++/OSSymbol.h>
27 #include <libkern/c++/OSLib.h>
28 #include <libkern/c++/OSCPPDebug.h>
29 #include <libkern/OSAtomic.h>
36 #define ACCUMSIZE(s) do { debug_ivars_size += (s); } while(0)
41 // OSDefineMetaClassAndAbstractStructors(OSObject, 0);
42 /* Class global data */
43 OSObject::MetaClass
OSObject::gMetaClass
;
44 const OSMetaClass
* const OSObject::metaClass
= &OSObject::gMetaClass
;
45 const OSMetaClass
* const OSObject::superClass
= 0;
47 /* Class member functions - Can't use defaults */
48 OSObject::OSObject() { retainCount
= 1; }
49 OSObject::OSObject(const OSMetaClass
*) { retainCount
= 1; }
50 OSObject::~OSObject() { }
51 const OSMetaClass
* OSObject::getMetaClass() const
52 { return &gMetaClass
; }
53 OSObject
*OSObject::MetaClass::alloc() const { return 0; }
55 /* The OSObject::MetaClass constructor */
56 OSObject::MetaClass::MetaClass()
57 : OSMetaClass("OSObject", OSObject::superClass
, sizeof(OSObject
))
61 OSMetaClassDefineReservedUnused(OSObject
, 0);
62 OSMetaClassDefineReservedUnused(OSObject
, 1);
63 OSMetaClassDefineReservedUnused(OSObject
, 2);
64 OSMetaClassDefineReservedUnused(OSObject
, 3);
65 OSMetaClassDefineReservedUnused(OSObject
, 4);
66 OSMetaClassDefineReservedUnused(OSObject
, 5);
67 OSMetaClassDefineReservedUnused(OSObject
, 6);
68 OSMetaClassDefineReservedUnused(OSObject
, 7);
69 OSMetaClassDefineReservedUnused(OSObject
, 8);
70 OSMetaClassDefineReservedUnused(OSObject
, 9);
71 OSMetaClassDefineReservedUnused(OSObject
, 10);
72 OSMetaClassDefineReservedUnused(OSObject
, 11);
73 OSMetaClassDefineReservedUnused(OSObject
, 12);
74 OSMetaClassDefineReservedUnused(OSObject
, 13);
75 OSMetaClassDefineReservedUnused(OSObject
, 14);
76 OSMetaClassDefineReservedUnused(OSObject
, 15);
77 OSMetaClassDefineReservedUnused(OSObject
, 16);
78 OSMetaClassDefineReservedUnused(OSObject
, 17);
79 OSMetaClassDefineReservedUnused(OSObject
, 18);
80 OSMetaClassDefineReservedUnused(OSObject
, 19);
81 OSMetaClassDefineReservedUnused(OSObject
, 20);
82 OSMetaClassDefineReservedUnused(OSObject
, 21);
83 OSMetaClassDefineReservedUnused(OSObject
, 22);
84 OSMetaClassDefineReservedUnused(OSObject
, 23);
85 OSMetaClassDefineReservedUnused(OSObject
, 24);
86 OSMetaClassDefineReservedUnused(OSObject
, 25);
87 OSMetaClassDefineReservedUnused(OSObject
, 26);
88 OSMetaClassDefineReservedUnused(OSObject
, 27);
89 OSMetaClassDefineReservedUnused(OSObject
, 28);
90 OSMetaClassDefineReservedUnused(OSObject
, 29);
91 OSMetaClassDefineReservedUnused(OSObject
, 30);
92 OSMetaClassDefineReservedUnused(OSObject
, 31);
95 bool OSObject::init() { return true; }
98 const OSMetaClass
*meta
= getMetaClass();
101 meta
->instanceDestructed();
105 int OSObject::getRetainCount() const
110 void OSObject::retain() const
112 OSIncrementAtomic((SInt32
*) &retainCount
);
115 void OSObject::release(int when
) const
117 if (OSDecrementAtomic((SInt32
*) &retainCount
) <= when
)
118 ((OSObject
*) this)->free();
121 void OSObject::release() const
126 bool OSObject::serialize(OSSerialize
*s
) const
128 if (s
->previouslySerialized(this)) return true;
130 if (!s
->addXMLStartTag(this, "string")) return false;
132 const OSMetaClass
*meta
= getMetaClass();
133 const char *className
= (meta
)? meta
->getClassName() : "unknown class?";
135 if (!s
->addString(className
)) return false;
136 if (!s
->addString(" is not serializable")) return false;
138 return s
->addXMLEndTag("string");
141 void *OSObject::operator new(size_t size
)
143 void *mem
= (void *) kalloc(size
);
152 void OSObject::operator delete(void *mem
, size_t size
)
154 kfree((vm_offset_t
) mem
, size
);