michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* A memory allocator for zlib use in SPDY that reports to about:memory. */ michael@0: michael@0: #include "mozilla/Assertions.h" michael@0: #include "mozilla/Atomics.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsIMemoryReporter.h" michael@0: #include "zlib.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class SpdyZlibReporter MOZ_FINAL : public nsIMemoryReporter michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: SpdyZlibReporter() michael@0: { michael@0: #ifdef DEBUG michael@0: // There must be only one instance of this class, due to |sAmount| michael@0: // being static. michael@0: static bool hasRun = false; michael@0: MOZ_ASSERT(!hasRun); michael@0: hasRun = true; michael@0: #endif michael@0: sAmount = 0; michael@0: } michael@0: michael@0: static void* Alloc(void*, uInt items, uInt size); michael@0: static void Free(void*, void* p); michael@0: michael@0: private: michael@0: // |sAmount| can be (implicitly) accessed by multiple threads, so it michael@0: // must be thread-safe. michael@0: static Atomic sAmount; michael@0: michael@0: MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf) michael@0: MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(MallocSizeOfOnAlloc) michael@0: MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(MallocSizeOfOnFree) michael@0: michael@0: NS_IMETHODIMP michael@0: CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData); michael@0: }; michael@0: michael@0: } // namespace mozilla