layout/build/nsLayoutStatics.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/build/nsLayoutStatics.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef nsLayoutStatics_h__
     1.9 +#define nsLayoutStatics_h__
    1.10 +
    1.11 +#include "nscore.h"
    1.12 +#include "MainThreadUtils.h"
    1.13 +#include "nsISupportsImpl.h"
    1.14 +#include "nsDebug.h"
    1.15 +
    1.16 +// This isn't really a class, it's a namespace for static methods.
    1.17 +// Documents and other objects can hold a reference to the layout static
    1.18 +// objects so that they last past the xpcom-shutdown notification.
    1.19 +
    1.20 +class nsLayoutStatics
    1.21 +{
    1.22 +public:
    1.23 +  // Called by the layout module constructor. This call performs an AddRef()
    1.24 +  // internally.
    1.25 +  static nsresult Initialize();
    1.26 +
    1.27 +  static void AddRef()
    1.28 +  {
    1.29 +    NS_ASSERTION(NS_IsMainThread(),
    1.30 +                 "nsLayoutStatics reference counting must be on main thread");
    1.31 +
    1.32 +    NS_ASSERTION(sLayoutStaticRefcnt,
    1.33 +                 "nsLayoutStatics already dropped to zero!");
    1.34 +
    1.35 +    ++sLayoutStaticRefcnt;
    1.36 +    NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
    1.37 +                  "nsLayoutStatics", 1);
    1.38 +  }
    1.39 +  static void Release()
    1.40 +  {
    1.41 +    NS_ASSERTION(NS_IsMainThread(),
    1.42 +                 "nsLayoutStatics reference counting must be on main thread");
    1.43 +
    1.44 +    --sLayoutStaticRefcnt;
    1.45 +    NS_LOG_RELEASE(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
    1.46 +                   "nsLayoutStatics");
    1.47 +
    1.48 +    if (!sLayoutStaticRefcnt)
    1.49 +      Shutdown();
    1.50 +  }
    1.51 +
    1.52 +private:
    1.53 +  // not to be called!
    1.54 +  nsLayoutStatics();
    1.55 +
    1.56 +  static void Shutdown();
    1.57 +
    1.58 +  static nsrefcnt sLayoutStaticRefcnt;
    1.59 +};
    1.60 +
    1.61 +class nsLayoutStaticsRef
    1.62 +{
    1.63 +public:
    1.64 +  nsLayoutStaticsRef()
    1.65 +  {
    1.66 +    nsLayoutStatics::AddRef();
    1.67 +  }
    1.68 +  ~nsLayoutStaticsRef()
    1.69 +  {
    1.70 +    nsLayoutStatics::Release();
    1.71 +  }
    1.72 +};
    1.73 +
    1.74 +#endif // nsLayoutStatics_h__

mercurial