netwerk/protocol/http/SpdyZlibReporter.h

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:406d1c78e94a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et 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 /* A memory allocator for zlib use in SPDY that reports to about:memory. */
8
9 #include "mozilla/Assertions.h"
10 #include "mozilla/Atomics.h"
11 #include "mozilla/Attributes.h"
12 #include "nsIMemoryReporter.h"
13 #include "zlib.h"
14
15 namespace mozilla {
16
17 class SpdyZlibReporter MOZ_FINAL : public nsIMemoryReporter
18 {
19 public:
20 NS_DECL_ISUPPORTS
21
22 SpdyZlibReporter()
23 {
24 #ifdef DEBUG
25 // There must be only one instance of this class, due to |sAmount|
26 // being static.
27 static bool hasRun = false;
28 MOZ_ASSERT(!hasRun);
29 hasRun = true;
30 #endif
31 sAmount = 0;
32 }
33
34 static void* Alloc(void*, uInt items, uInt size);
35 static void Free(void*, void* p);
36
37 private:
38 // |sAmount| can be (implicitly) accessed by multiple threads, so it
39 // must be thread-safe.
40 static Atomic<size_t> sAmount;
41
42 MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
43 MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(MallocSizeOfOnAlloc)
44 MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(MallocSizeOfOnFree)
45
46 NS_IMETHODIMP
47 CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData);
48 };
49
50 } // namespace mozilla

mercurial