Check for SYS/GL during library init. Reason is that
[AROS.git] / rom / utility / remnamedobject.c
blob6c2d21ab4a3cf879f1bcefdfa0cff3001f69b791
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: RemNamedObject() - Remove a NamedObject from a NameSpace.
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include "intern.h"
11 /*****************************************************************************
13 NAME */
14 #include <utility/name.h>
15 #include <proto/utility.h>
17 AROS_LH2(void, RemNamedObject,
19 /* SYNOPSIS */
20 AROS_LHA(struct NamedObject *, object, A0),
21 AROS_LHA(struct Message *, message, A1),
23 /* LOCATION */
24 struct UtilityBase *, UtilityBase, 44, Utility)
26 /* FUNCTION
27 Remove a NamedObject from a namespace.
29 If the NamedObject cannot be removed at the time of this call, then
30 the call will return without removing the NamedObject. It will
31 mark the NamedObject as "waiting for removal".
33 When the NamedObject is ready to be freed, the supplied message
34 will be ReplyMsg()'d with the message->mn_Node.ln_Name field
35 containing either:
36 - the address of the NamedObject that was removed. In this case
37 you can free the NamedObject yourself.
38 - NULL. In this case, another Task has freed the NamedObject,
39 and you should not do so.
41 INPUTS
42 object - The NamedObject to attempt to remove.
43 message - The message to send. This message is a standard
44 Exec Message, which MUST have the mn_ReplyPort
45 field correctly set. The mn_Node.ln_Name field
46 will contain the address of the NamedObject or NULL
47 upon arrival at your port.
49 RESULT
50 The NamedObject will be removed if possible, or marked for removal
51 at the next best moment.
53 NOTES
54 Since this function effectively does a ReleaseNamedObject(), you
55 must have found this object first.
57 EXAMPLE
59 BUGS
61 SEE ALSO
62 AttemptRemNamedObject(), AddNamedObject()
64 INTERNALS
65 AttemptRemNamedObject() calls this function with a NULL message,
66 expecting that we remove the object if possible, or just return.
68 ReleaseNamedObject() also calls this with a NULL message.
70 HISTORY
71 29-10-95 digulla automatically created from
72 utility_lib.fd and clib/utility_protos.h
73 11-08-96 iaint Adapted for AROS for stuff I did earlier.
74 09-02-1997 iaint Improved Message handling.
76 *****************************************************************************/
78 AROS_LIBFUNC_INIT
80 struct NameSpace *ns;
81 struct IntNamedObject *no;
83 if(object)
85 no = GetIntNamedObject( object );
86 ns = no->no_ParentSpace;
88 /* If ns == 0, then this node hasn't been added to anywhere */
89 if( ns )
91 /* Whether we free now, or later, the message handling is
92 the same. So we use the same code.
94 The Forbid() is to prevent two tasks from trying to
95 attach a message at the same time.
97 Forbid();
99 if( message )
101 if( no->no_FreeMessage == NULL)
103 /* This is the message, mark for later */
104 message->mn_Node.ln_Name = (STRPTR)object;
105 no->no_FreeMessage = message;
107 else
109 /* This message is not it, return NULL name. */
110 message->mn_Node.ln_Name = NULL;
111 ReplyMsg(message);
115 Permit();
117 if(no->no_UseCount == 0)
119 /* Ok, so we can remove the NamedObject */
120 ObtainSemaphore( &ns->ns_Lock );
122 Remove( (struct Node *)&no->no_Node );
124 if(no->no_FreeMessage)
126 ReplyMsg( no->no_FreeMessage );
128 ReleaseSemaphore( &ns->ns_Lock );
131 } /* if ( ns ) */
133 } /* if( object ) */
135 AROS_LIBFUNC_EXIT
137 } /* RemNamedObject */