nsLayoutStatics.h (1715B)
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 "MainThreadUtils.h" 11 #include "nsDebug.h" 12 #include "nsISupportsImpl.h" 13 #include "nscore.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 public: 21 // Called by the layout module constructor. This call performs an AddRef() 22 // internally. 23 static nsresult Initialize(); 24 25 static void AddRef() { 26 NS_ASSERTION(NS_IsMainThread(), 27 "nsLayoutStatics reference counting must be on main thread"); 28 29 NS_ASSERTION(sLayoutStaticRefcnt, 30 "nsLayoutStatics already dropped to zero!"); 31 32 ++sLayoutStaticRefcnt; 33 NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt, "nsLayoutStatics", 34 1); 35 } 36 static void Release() { 37 NS_ASSERTION(NS_IsMainThread(), 38 "nsLayoutStatics reference counting must be on main thread"); 39 40 --sLayoutStaticRefcnt; 41 NS_LOG_RELEASE(&sLayoutStaticRefcnt, sLayoutStaticRefcnt, 42 "nsLayoutStatics"); 43 44 if (!sLayoutStaticRefcnt) { 45 Shutdown(); 46 } 47 } 48 49 private: 50 // not to be called! 51 nsLayoutStatics(); 52 53 static void Shutdown(); 54 55 static nsrefcnt sLayoutStaticRefcnt; 56 }; 57 58 #endif // nsLayoutStatics_h__