1 | /*
|
---|
2 | * Copyright (C) 2008 Apple Inc. All rights reserved.
|
---|
3 | *
|
---|
4 | * This library is free software; you can redistribute it and/or
|
---|
5 | * modify it under the terms of the GNU Library General Public
|
---|
6 | * License as published by the Free Software Foundation; either
|
---|
7 | * version 2 of the License, or (at your option) any later version.
|
---|
8 | *
|
---|
9 | * This library is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
12 | * Library General Public License for more details.
|
---|
13 | *
|
---|
14 | * You should have received a copy of the GNU Library General Public License
|
---|
15 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
17 | * Boston, MA 02110-1301, USA.
|
---|
18 | *
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "config.h"
|
---|
22 |
|
---|
23 | #include "RefCountedLeakCounter.h"
|
---|
24 | #include "UnusedParam.h"
|
---|
25 |
|
---|
26 | namespace WTF {
|
---|
27 |
|
---|
28 | #ifndef NDEBUG
|
---|
29 | static bool logLeakMessages = true;
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | void setLogLeakMessages(bool _logLeakMessages )
|
---|
33 | {
|
---|
34 | UNUSED_PARAM(_logLeakMessages);
|
---|
35 | #ifndef NDEBUG
|
---|
36 | logLeakMessages = _logLeakMessages;
|
---|
37 | #endif
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | #ifndef NDEBUG
|
---|
42 | #define LOG_CHANNEL_PREFIX Log
|
---|
43 | static WTFLogChannel LogRefCountedLeaks = { 0x00000000, "", WTFLogChannelOn };
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | RefCountedLeakCounter::~RefCountedLeakCounter()
|
---|
47 | {
|
---|
48 | #ifndef NDEBUG
|
---|
49 | if (count && logLeakMessages)
|
---|
50 | LOG(RefCountedLeaks, "LEAK: %u %s\n", count, description);
|
---|
51 | #endif
|
---|
52 | }
|
---|
53 |
|
---|
54 | RefCountedLeakCounter::RefCountedLeakCounter(const char* desc)
|
---|
55 | {
|
---|
56 | UNUSED_PARAM(desc);
|
---|
57 | #ifndef NDEBUG
|
---|
58 | description = desc;
|
---|
59 | #endif
|
---|
60 | }
|
---|
61 |
|
---|
62 | #if USE(MULTIPLE_THREADS)
|
---|
63 |
|
---|
64 | void RefCountedLeakCounter::increment()
|
---|
65 | {
|
---|
66 | #ifndef NDEBUG
|
---|
67 | atomicIncrement(&count);
|
---|
68 | #endif
|
---|
69 | }
|
---|
70 |
|
---|
71 | void RefCountedLeakCounter::decrement()
|
---|
72 | {
|
---|
73 | #ifndef NDEBUG
|
---|
74 | atomicDecrement(&count);
|
---|
75 | #endif
|
---|
76 | }
|
---|
77 |
|
---|
78 | #else
|
---|
79 |
|
---|
80 | void RefCountedLeakCounter::increment()
|
---|
81 | {
|
---|
82 | #ifndef NDEBUG
|
---|
83 | ++count;
|
---|
84 | #endif
|
---|
85 | }
|
---|
86 |
|
---|
87 | void RefCountedLeakCounter::decrement()
|
---|
88 | {
|
---|
89 | #ifndef NDEBUG
|
---|
90 | --count;
|
---|
91 | #endif
|
---|
92 | }
|
---|
93 |
|
---|
94 | #endif
|
---|
95 |
|
---|
96 | } // Namespace WTF
|
---|