/work/obj-fuzz/dist/include/nsLayoutStatics.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef nsLayoutStatics_h__ |
8 | | #define nsLayoutStatics_h__ |
9 | | |
10 | | #include "nscore.h" |
11 | | #include "MainThreadUtils.h" |
12 | | #include "nsISupportsImpl.h" |
13 | | #include "nsDebug.h" |
14 | | |
15 | | // This isn't really a class, it's a namespace for static methods. |
16 | | // Documents and other objects can hold a reference to the layout static |
17 | | // objects so that they last past the xpcom-shutdown notification. |
18 | | |
19 | | class nsLayoutStatics |
20 | | { |
21 | | public: |
22 | | // Called by the layout module constructor. This call performs an AddRef() |
23 | | // internally. |
24 | | static nsresult Initialize(); |
25 | | |
26 | | static void AddRef() |
27 | 0 | { |
28 | 0 | NS_ASSERTION(NS_IsMainThread(), |
29 | 0 | "nsLayoutStatics reference counting must be on main thread"); |
30 | 0 |
|
31 | 0 | NS_ASSERTION(sLayoutStaticRefcnt, |
32 | 0 | "nsLayoutStatics already dropped to zero!"); |
33 | 0 |
|
34 | 0 | ++sLayoutStaticRefcnt; |
35 | 0 | NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt, |
36 | 0 | "nsLayoutStatics", 1); |
37 | 0 | } |
38 | | static void Release() |
39 | 0 | { |
40 | 0 | NS_ASSERTION(NS_IsMainThread(), |
41 | 0 | "nsLayoutStatics reference counting must be on main thread"); |
42 | 0 |
|
43 | 0 | --sLayoutStaticRefcnt; |
44 | 0 | NS_LOG_RELEASE(&sLayoutStaticRefcnt, sLayoutStaticRefcnt, |
45 | 0 | "nsLayoutStatics"); |
46 | 0 |
|
47 | 0 | if (!sLayoutStaticRefcnt) |
48 | 0 | Shutdown(); |
49 | 0 | } |
50 | | |
51 | | private: |
52 | | // not to be called! |
53 | | nsLayoutStatics(); |
54 | | |
55 | | static void Shutdown(); |
56 | | |
57 | | static nsrefcnt sLayoutStaticRefcnt; |
58 | | }; |
59 | | |
60 | | class nsLayoutStaticsRef |
61 | | { |
62 | | public: |
63 | | nsLayoutStaticsRef() |
64 | 0 | { |
65 | 0 | nsLayoutStatics::AddRef(); |
66 | 0 | } |
67 | | ~nsLayoutStaticsRef() |
68 | 0 | { |
69 | 0 | nsLayoutStatics::Release(); |
70 | 0 | } |
71 | | }; |
72 | | |
73 | | #endif // nsLayoutStatics_h__ |