tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaActorUtils.h (3061B)


      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 #ifndef include_dom_media_ipc_MediaActorUtils_h
      7 #define include_dom_media_ipc_MediaActorUtils_h
      8 
      9 #include "nsISupportsImpl.h"
     10 
     11 // This refcounting specialization allows the implementing class to supply a
     12 // method to call when there is only one reference left. This allows for media
     13 // IPDL actors to be refcounted normally, and when the last reference is the
     14 // IPDL actor, we can choose to self destroy.
     15 #define MEDIA_INLINE_DECL_THREADSAFE_REFCOUNTING_META(_class, _decl, _destroy, \
     16                                                      _last_ref, ...)          \
     17 public:                                                                       \
     18  _decl(MozExternalRefCountType) AddRef(void) __VA_ARGS__ {                    \
     19    MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class)                                 \
     20    MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");                       \
     21    nsrefcnt count = ++mRefCnt;                                                \
     22    NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                        \
     23    return (nsrefcnt)count;                                                    \
     24  }                                                                            \
     25  _decl(MozExternalRefCountType) Release(void) __VA_ARGS__ {                   \
     26    MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");                           \
     27    nsrefcnt count = --mRefCnt;                                                \
     28    NS_LOG_RELEASE(this, count, #_class);                                      \
     29    if (count == 0) {                                                          \
     30      _destroy;                                                                \
     31      return 0;                                                                \
     32    }                                                                          \
     33    if (count == 1) {                                                          \
     34      _last_ref;                                                               \
     35    }                                                                          \
     36    return count;                                                              \
     37  }                                                                            \
     38  using HasThreadSafeRefCnt = std::true_type;                                  \
     39                                                                               \
     40 protected:                                                                    \
     41  ::mozilla::ThreadSafeAutoRefCnt mRefCnt;                                     \
     42                                                                               \
     43 public:
     44 
     45 #endif  // include_dom_media_ipc_MediaActorUtils_h