Commit a093a97f authored by Nika Layzell's avatar Nika Layzell
Browse files

Bug 18426589 - Part 2: Use refcounting macros for nsHtml5OwningUTF16Buffer, r=mccr8, a=dsmith

When the code was originally added in bug 18426589, it was to use non-atomic
refcounting across multiple threads due to some invariants preventing
concurrent access. That was changed in bug 1607762 to fix a race issue.

We should be able to switch to using the macros now, which will simplify the
code here a bit.

Depends on D183203

Differential Revision: https://phabricator.services.mozilla.com/D183204
parent 2b3d1ab9
Loading
Loading
Loading
Loading
+0 −22
Original line number Diff line number Diff line
@@ -55,25 +55,3 @@ Span<char16_t> nsHtml5OwningUTF16Buffer::TailAsSpan(int32_t aBufferSize) {
void nsHtml5OwningUTF16Buffer::AdvanceEnd(int32_t aNumberOfCodeUnits) {
  setEnd(getEnd() + aNumberOfCodeUnits);
}

// Not using macros for AddRef and Release in order to be able to refcount on
// and create on different threads.

nsrefcnt nsHtml5OwningUTF16Buffer::AddRef() {
  MOZ_ASSERT(int32_t(mRefCnt) >= 0, "Illegal refcount.");
  ++mRefCnt;
  NS_LOG_ADDREF(this, mRefCnt, "nsHtml5OwningUTF16Buffer", sizeof(*this));
  return mRefCnt;
}

nsrefcnt nsHtml5OwningUTF16Buffer::Release() {
  MOZ_ASSERT(0 != mRefCnt, "Release without AddRef.");
  --mRefCnt;
  NS_LOG_RELEASE(this, mRefCnt, "nsHtml5OwningUTF16Buffer");
  if (mRefCnt == 0) {
    mRefCnt = 1; /* stabilize */
    delete this;
    return 0;
  }
  return mRefCnt;
}
+3 −6
Original line number Diff line number Diff line
@@ -9,6 +9,9 @@
#include "mozilla/Span.h"

class nsHtml5OwningUTF16Buffer : public nsHtml5UTF16Buffer {
 public:
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHtml5OwningUTF16Buffer)

 private:
  /**
   * Passes a buffer and its length to the superclass constructor.
@@ -56,12 +59,6 @@ class nsHtml5OwningUTF16Buffer : public nsHtml5UTF16Buffer {
   * Add the argument to `end`.
   */
  void AdvanceEnd(int32_t aNumberOfCodeUnits);

  nsrefcnt AddRef();
  nsrefcnt Release();

 private:
  mozilla::ThreadSafeAutoRefCnt mRefCnt;
};

#endif  // nsHtml5OwningUTF16Buffer_h