Minor fixes to comments.
[AROS.git] / rom / intuition / freeclass.c
blob2341d237df161c05965afb885bc9aedb11d11c0f
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
6 Free a BOOPSI Class.
7 */
9 #include <proto/exec.h>
10 #include "intuition_intern.h"
12 /*****************************************************************************
14 NAME */
15 #include <intuition/classes.h>
16 #include <proto/intuition.h>
18 AROS_LH1(BOOL, FreeClass,
20 /* SYNOPSIS */
21 AROS_LHA(struct IClass *, iclass, A0),
23 /* LOCATION */
24 struct IntuitionBase *, IntuitionBase, 119, Intuition)
26 /* FUNCTION
27 Only for class implementatores.
29 Tries to free a class which has been created with MakeClass() in the
30 first place. This will not succeed in all cases: Classes which
31 still have living objects or which are still being used by subclasses
32 can't simply be freed. In this case this call will fail.
34 Public classes will always be removed with RemoveClass() no matter
35 if FreeClass() would succeed or not. This gurantees that after the
36 call to FreeClass() no new objects can be created.
38 If you have a pointer to allocated memory in cl_UserData, you must
39 make a copy of that pointer, call FreeClass() and if the call
40 succeeded, you may free the memory. If you don't follow these rules,
41 you might end up with a class which is partially freed.
43 INPUTS
44 iclass - The pointer you got from MakeClass().
46 RESULT
47 FALSE if the class couldn't be freed at this time. This can happen
48 either if there are still objects from this class or if the class
49 is used a SuperClass of at least another class.
51 TRUE if the class could be freed. You must not use iclass after
52 that.
54 NOTES
55 *Always* calls RemoveClass().
57 EXAMPLE
58 // Free a public class with dynamic memory in cl_UserD
60 int freeMyClass (Class * cl)
62 struct MyPerClassData * mpcd;
64 mpcd = (struct MyPerClassData *)cl->cl_UserData;
66 if (FreeClass (cl)
68 FreeMem (mpcd, sizeof (struct MyPerClassData));
69 return (TRUE);
72 return (FALSE);
75 BUGS
77 SEE ALSO
79 INTERNALS
80 MakeClass(), "Basic Object-Oriented Programming System for Intuition"
81 and "boopsi Class Reference" Dokument.
83 *****************************************************************************/
85 AROS_LIBFUNC_INIT
87 BOOL rv = FALSE;
89 SANITY_CHECKR(iclass,FALSE)
91 ObtainSemaphore(&GetPrivIBase(IntuitionBase)->ClassListLock);
94 Make sure no one creates another object from this class. For private
95 classes, this call does nothing.
97 RemoveClass(iclass);
99 if (iclass->cl_SubclassCount == 0 && iclass->cl_ObjectCount == 0)
101 AROS_ATOMIC_DEC(iclass->cl_Super->cl_SubclassCount);
103 DeletePool(iclass->cl_MemoryPool);
104 FreeMem(iclass, sizeof(Class));
106 rv = TRUE;
109 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->ClassListLock);
111 return rv;
113 AROS_LIBFUNC_EXIT
114 } /* FreeClass() */