39 #include "nsAutoLock.h"
41 #include "nsArrayEnumerator.h"
42 #include "nsWeakReference.h"
55 NS_INTERFACE_MAP_ENTRY(nsIArray)
56 NS_INTERFACE_MAP_ENTRY(nsIMutableArray)
57 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(
nsISupports, nsIMutableArray)
62 mLock = nsAutoLock::NewLock(
"nsThreadsafeArray::mLock");
63 NS_ASSERTION(mLock,
"Failed to create lock");
68 mLock = nsAutoLock::NewLock(
"nsThreadsafeArray::mLock");
69 NS_ASSERTION(mLock,
"Failed to create lock");
76 nsAutoLock::DestroyLock(mLock);
84 sbArray::GetLength(PRUint32* aLength)
86 nsAutoLock lock(mLock);
87 *aLength = mArray.Count();
92 sbArray::QueryElementAt(PRUint32 aIndex,
96 nsAutoLock lock(mLock);
98 if (!obj)
return NS_ERROR_ILLEGAL_VALUE;
102 return obj->QueryInterface(aIID, aResult);
106 sbArray::IndexOf(PRUint32 aStartIndex,
nsISupports* aElement,
109 nsAutoLock lock(mLock);
112 if (aStartIndex == 0) {
113 *aResult = mArray.
IndexOf(aElement);
115 return NS_ERROR_FAILURE;
122 return NS_ERROR_FAILURE;
131 return NS_NewArrayEnumerator(aResult, static_cast<nsIArray*>(
this));
137 sbArray::AppendElement(
nsISupports* aElement, PRBool aWeak)
141 nsCOMPtr<nsISupports> elementRef =
142 getter_AddRefs(static_cast<nsISupports*>
143 (NS_GetWeakReference(aElement)));
144 NS_ASSERTION(elementRef,
"AppendElement: Trying to use weak references on an object that doesn't support it");
146 return NS_ERROR_FAILURE;
148 nsAutoLock lock(mLock);
155 nsAutoLock lock(mLock);
158 return result ?
NS_OK : NS_ERROR_FAILURE;
162 sbArray::RemoveElementAt(PRUint32 aIndex)
164 nsAutoLock lock(mLock);
166 return result ?
NS_OK : NS_ERROR_FAILURE;
170 sbArray::InsertElementAt(
nsISupports* aElement, PRUint32 aIndex, PRBool aWeak)
172 nsCOMPtr<nsISupports> elementRef;
175 getter_AddRefs(static_cast<nsISupports*>
176 (NS_GetWeakReference(aElement)));
177 NS_ASSERTION(elementRef,
"InsertElementAt: Trying to use weak references on an object that doesn't support it");
179 return NS_ERROR_FAILURE;
181 elementRef = aElement;
184 nsAutoLock lock(mLock);
186 return result ?
NS_OK : NS_ERROR_FAILURE;
191 sbArray::ReplaceElementAt(
nsISupports* aElement, PRUint32 aIndex, PRBool aWeak)
193 nsCOMPtr<nsISupports> elementRef;
196 getter_AddRefs(static_cast<nsISupports*>
197 (NS_GetWeakReference(aElement)));
198 NS_ASSERTION(elementRef,
"ReplaceElementAt: Trying to use weak references on an object that doesn't support it");
200 return NS_ERROR_FAILURE;
202 elementRef = aElement;
205 nsAutoLock lock(mLock);
207 return result ?
NS_OK : NS_ERROR_FAILURE;
214 nsAutoLock lock(mLock);
PR_STATIC_CALLBACK(PRBool) FindElementCallback(void *aElement
PRBool InsertObjectAt(nsISupports *aObject, PRInt32 aIndex)
PRBool RemoveObjectAt(PRInt32 aIndex)
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
PRBool FindElementCallback(void *aElement, void *aClosure)
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
PRInt32 IndexOf(nsISupports *aObject) const
PRBool ReplaceObjectAt(nsISupports *aObject, PRInt32 aIndex)
PRBool EnumerateForwards(nsVoidArrayEnumFunc aFunc, void *aData)
nsISupports * targetElement
PRBool AppendObject(nsISupports *aObject)
nsISupports * SafeObjectAt(PRInt32 aIndex) const