1 : /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Benjamin Smedberg <benjamin@smedbergs.us>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsProxyRelease_h__
40 : #define nsProxyRelease_h__
41 :
42 : #include "nsIEventTarget.h"
43 : #include "nsCOMPtr.h"
44 : #include "nsAutoPtr.h"
45 :
46 : #ifdef XPCOM_GLUE_AVOID_NSPR
47 : #error NS_ProxyRelease implementation depends on NSPR.
48 : #endif
49 :
50 : /**
51 : * Ensure that a nsCOMPtr is released on the target thread.
52 : *
53 : * @see NS_ProxyRelease(nsIEventTarget*, nsISupports*, bool)
54 : */
55 : template <class T>
56 : inline NS_HIDDEN_(nsresult)
57 318 : NS_ProxyRelease
58 : (nsIEventTarget *target, nsCOMPtr<T> &doomed, bool alwaysProxy=false)
59 : {
60 318 : T* raw = nsnull;
61 318 : doomed.swap(raw);
62 318 : return NS_ProxyRelease(target, raw, alwaysProxy);
63 : }
64 :
65 : /**
66 : * Ensure that a nsRefPtr is released on the target thread.
67 : *
68 : * @see NS_ProxyRelease(nsIEventTarget*, nsISupports*, bool)
69 : */
70 : template <class T>
71 : inline NS_HIDDEN_(nsresult)
72 8771 : NS_ProxyRelease
73 : (nsIEventTarget *target, nsRefPtr<T> &doomed, bool alwaysProxy=false)
74 : {
75 8771 : T* raw = nsnull;
76 8771 : doomed.swap(raw);
77 8771 : return NS_ProxyRelease(target, raw, alwaysProxy);
78 : }
79 :
80 : /**
81 : * Ensures that the delete of a nsISupports object occurs on the target thread.
82 : *
83 : * @param target
84 : * the target thread where the doomed object should be released.
85 : * @param doomed
86 : * the doomed object; the object to be released on the target thread.
87 : * @param alwaysProxy
88 : * normally, if NS_ProxyRelease is called on the target thread, then the
89 : * doomed object will released directly. however, if this parameter is
90 : * true, then an event will always be posted to the target thread for
91 : * asynchronous release.
92 : */
93 : NS_COM_GLUE nsresult
94 : NS_ProxyRelease
95 : (nsIEventTarget *target, nsISupports *doomed, bool alwaysProxy=false);
96 :
97 : #endif
|