LCOV - code coverage report
Current view: top level - libreoffice/package/inc - mutexholder.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 28 100.0 %
Date: 2012-12-27 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          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 __MUTEXHOLDER_HXX_
      21             : #define __MUTEXHOLDER_HXX_
      22             : 
      23             : #include <osl/mutex.hxx>
      24             : 
      25        9000 : class SotMutexHolder
      26             : {
      27             :     ::osl::Mutex m_aMutex;
      28             :     sal_Int32    m_nRefCount;
      29             : 
      30             :     public:
      31       12111 :     SotMutexHolder() : m_nRefCount( 0 ) {}
      32             : 
      33       33834 :     void AddRef()
      34             :     {
      35       33834 :         m_nRefCount++;
      36       33834 :     }
      37             : 
      38       28339 :     void ReleaseRef()
      39             :     {
      40       28339 :         if ( !--m_nRefCount )
      41        9000 :             delete this;
      42       28339 :     }
      43             : 
      44      243061 :     ::osl::Mutex& GetMutex() { return m_aMutex; }
      45             : };
      46             : 
      47             : class SotMutexHolderRef
      48             : {
      49             :     SotMutexHolder* m_pHolder;
      50             : 
      51             : public:
      52             :     SotMutexHolderRef()
      53             :     : m_pHolder( NULL )
      54             :     {}
      55             : 
      56       12111 :     SotMutexHolderRef( SotMutexHolder* pHolder )
      57       12111 :     : m_pHolder( pHolder )
      58             :     {
      59       12111 :         if ( m_pHolder )
      60       12111 :             m_pHolder->AddRef();
      61       12111 :     }
      62             : 
      63       21723 :     SotMutexHolderRef( const SotMutexHolderRef& rRef )
      64       21723 :     : m_pHolder( rRef.m_pHolder )
      65             :     {
      66       21723 :         if ( m_pHolder )
      67       21723 :             m_pHolder->AddRef();
      68       21723 :     }
      69             : 
      70       28339 :     ~SotMutexHolderRef()
      71             :     {
      72       28339 :         if ( m_pHolder )
      73       28339 :             m_pHolder->ReleaseRef();
      74       28339 :     }
      75             : 
      76             :     SotMutexHolderRef& operator =( const SotMutexHolderRef& rRef )
      77             :     {
      78             :         if ( m_pHolder )
      79             :             m_pHolder->ReleaseRef();
      80             : 
      81             :         m_pHolder = rRef.m_pHolder;
      82             : 
      83             :         if ( m_pHolder )
      84             :             m_pHolder->AddRef();
      85             : 
      86             :         return *this;
      87             :     }
      88             : 
      89             :     SotMutexHolderRef& operator =( SotMutexHolder* pHolder )
      90             :     {
      91             :         if ( m_pHolder )
      92             :             m_pHolder->ReleaseRef();
      93             : 
      94             :         m_pHolder = pHolder;
      95             : 
      96             :         if ( m_pHolder )
      97             :             m_pHolder->AddRef();
      98             :         return *this;
      99             :     }
     100             : 
     101      243061 :     SotMutexHolder* operator ->() const
     102             :     {
     103      243061 :         return m_pHolder;
     104             :     }
     105             : 
     106             :     SotMutexHolder& operator *() const
     107             :     {
     108             :         return *m_pHolder;
     109             :     }
     110             : 
     111             :     operator SotMutexHolder*() const
     112             :     {
     113             :         return m_pHolder;
     114             :     }
     115             : 
     116        5058 :     sal_Bool Is() const
     117             :     {
     118        5058 :         return m_pHolder != NULL;
     119             :     }
     120             : };
     121             : 
     122             : #endif
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10