Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _NULLCANVAS_USAGECOUNTER_HXX
21 : #define _NULLCANVAS_USAGECOUNTER_HXX
22 :
23 : #include <osl/interlck.h>
24 : #include <boost/current_function.hpp>
25 :
26 : namespace nullcanvas
27 : {
28 : /** Little resource tracking counter.
29 :
30 : When using this object, a global use counter, specific to the
31 : given type is incremented on object construction, and
32 : decremented on object destruction.
33 : */
34 : template< class Type > class UsageCounter
35 : {
36 : public:
37 0 : UsageCounter()
38 : {
39 : OSL_TRACE( "%s, %d objects currently in use.\n",
40 : BOOST_CURRENT_FUNCTION,
41 : osl_atomic_increment( &s_nCount ) );
42 0 : }
43 :
44 0 : ~UsageCounter()
45 : {
46 0 : const sal_Int32 nCount( osl_atomic_decrement( &s_nCount ) );
47 :
48 : if( !nCount )
49 : {
50 : OSL_TRACE( "%s, last instance deleted.\n",
51 : BOOST_CURRENT_FUNCTION );
52 : }
53 : else
54 : {
55 : OSL_TRACE( "%s, %d instances left.\n",
56 : BOOST_CURRENT_FUNCTION,
57 : nCount );
58 : }
59 0 : }
60 :
61 : private:
62 : static oslInterlockedCount s_nCount;
63 : };
64 :
65 : template< class Type > oslInterlockedCount UsageCounter<Type>::s_nCount = 0;
66 : }
67 :
68 : #endif /* _NULLCANVAS_USAGECOUNTER_HXX */
69 :
70 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|