]> git.lyx.org Git - lyx.git/blob - development/Win32/vld/src/vldapi.cpp
add leak tool for msvc 'Visual Leak Detection' 1.9f: original files
[lyx.git] / development / Win32 / vld / src / vldapi.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2 //  $Id: vldapi.cpp,v 1.19 2006/11/18 03:12:35 dmouldin Exp $
3 //
4 //  Visual Leak Detector - Exported APIs
5 //  Copyright (c) 2005-2006 Dan Moulding
6 //
7 //  This library is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU Lesser General Public
9 //  License as published by the Free Software Foundation; either
10 //  version 2.1 of the License, or (at your option) any later version.
11 //
12 //  This library is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //  Lesser General Public License for more details.
16 //
17 //  You should have received a copy of the GNU Lesser General Public
18 //  License along with this library; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 //
21 //  See COPYING.txt for the full terms of the GNU Lesser General Public License.
22 //
23 ////////////////////////////////////////////////////////////////////////////////
24
25 #define VLDBUILD     // Declares that we are building Visual Leak Detector.
26 #include "vldint.h"  // Provides access to the Visual Leak Detector internals.
27 #include "vldheap.h" // Provides internal new and delete operators.
28
29 // Imported global variables.
30 extern VisualLeakDetector vld;
31
32 ////////////////////////////////////////////////////////////////////////////////
33 //
34 //  Visual Leak Detector APIs - see vldapi.h for each function's details.
35 //
36
37 extern "C" __declspec(dllexport) void VLDDisable ()
38 {
39     tls_t *tls;
40
41     if (vld.m_options & VLD_OPT_VLDOFF) {
42         // VLD has been turned off.
43         return;
44     }
45
46     // Disable memory leak detection for the current thread. There are two flags
47     // because if neither flag is set, it means that we are in the default or
48     // "starting" state, which could be either enabled or disabled depending on
49     // the configuration.
50     tls = vld.gettls();
51     tls->flags &= ~VLD_TLS_ENABLED;
52     tls->flags |= VLD_TLS_DISABLED;
53 }
54
55 extern "C" __declspec(dllexport) void VLDEnable ()
56 {
57     tls_t *tls;
58
59     if (vld.m_options & VLD_OPT_VLDOFF) {
60         // VLD has been turned off.
61         return;
62     }
63
64     // Enable memory leak detection for the current thread.
65     tls = vld.gettls();
66     tls->flags &= ~VLD_TLS_DISABLED;
67     tls->flags |= VLD_TLS_ENABLED;
68     vld.m_status &= ~VLD_STATUS_NEVER_ENABLED;
69 }