pull in the exec smp setting via etask.h
[AROS.git] / rom / utility / addnamedobject.c
blob695df5596fdd4956eae2cef21aa7d00540fcbd04
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: AddNamedObject() - adds a NamedObject to a given NameSpace.
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include "intern.h"
11 /*****************************************************************************
13 NAME */
14 #include <proto/utility.h>
16 AROS_LH2(BOOL, AddNamedObject,
18 /* SYNOPSIS */
19 AROS_LHA(struct NamedObject *, nameSpace, A0),
20 AROS_LHA(struct NamedObject *, object, A1),
22 /* LOCATION */
23 struct UtilityBase *, UtilityBase, 37, Utility)
25 /* FUNCTION
26 Adds a given NamedObject to a NameSpace which is addressed through
27 a second NamedObject. Allows you to link a common group of
28 NamedObjects together. If the NameSpace doesn't support duplicate
29 names, then a search for a duplicate will be made, and FALSE returned
30 if one is found.
32 INPUTS
33 nameSpace - The NameSpace to add the NamedObject object to.
34 If this value is NULL, then the NamedObject will
35 be added to the root NameSpace. This is useful
36 for sharing NamedObjects between Tasks.
37 object - The NamedObject to add to the NameSpace.
39 RESULT
40 If the NamedObject can be added to either the supplied NameSpace or
41 the system global NameSpace, this function will return TRUE.
43 Otherwise it will return FALSE. This will generally happen when
44 the NSF_NODUPS flag is set and this NamedObject has the same name
45 as a second object, or when the object is already in a NameSpace.
47 NOTES
48 See BUGS.
50 EXAMPLE
52 BUGS
53 Although the AmigaOS 3.1 autodocs did not say so, under 3.0 you
54 couldn't add a NamedObject to a NameSpace when the NamedObject you
55 were adding had a NameSpace itself. This has changed. This is
56 because the autodocs did not say this, and they are right :)
58 SEE ALSO
59 utility/name.h, RemNamedObject()
61 INTERNALS
63 HISTORY
64 29-10-95 digulla automatically created from
65 utility_lib.fd and clib/utility_protos.h
67 *****************************************************************************/
69 AROS_LIBFUNC_INIT
71 struct NameSpace *ns;
72 struct IntNamedObject *no; /* for object */
73 BOOL ret; /* return value */
75 /* Set to FALSE so lack of object returns FALSE */
76 ret = FALSE;
78 if(object)
80 /* Set true since now only failure will set as false */
81 ret = TRUE;
83 ns = GetNameSpace(nameSpace, UtilityBase);
84 no = GetIntNamedObject(object);
86 /* First of all, see if we are already in a NameSpace, if so, just
87 exit. This way we don't do any damage to any linked lists.
89 if(no->no_ParentSpace)
90 return FALSE;
92 ObtainSemaphore(&ns->ns_Lock);
95 By checking whether the Tail node exists, we check whether the
96 list has any nodes in it. If it doesn't then obviously we don't
97 have to check any other members of the list for name matches
99 Don't use FindName() here because the comparison may not be
100 case sensitive. IntFindNamedObj() does all that.
102 if((ns->ns_Flags & NSF_NODUPS) && ns->ns_List.mlh_Tail)
104 if(IntFindNamedObj(ns, (struct Node *)ns->ns_List.mlh_Head, no->no_Node.ln_Name, UtilityBase))
105 ret = FALSE;
106 else
107 Enqueue((struct List *)ns, (struct Node *)&no->no_Node);
109 else
110 Enqueue((struct List *)ns, (struct Node *)&no->no_Node);
112 if(ret == TRUE) /* Added to NameSpace ns */
113 no->no_ParentSpace = ns;
115 ReleaseSemaphore( &ns->ns_Lock );
117 } /* if( object ) */
119 return ret;
121 AROS_LIBFUNC_EXIT
123 } /* AddNamedObject */