LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vcl/generic/app - geninst.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 55 76.4 %
Date: 2013-07-09 Functions: 11 14 78.6 %
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             : #include <string.h>
      21             : #include <stdio.h>
      22             : #include <stdlib.h>
      23             : 
      24             : #include "osl/module.hxx"
      25             : #include "tools/solarmutex.hxx"
      26             : 
      27             : #include "generic/geninst.h"
      28             : 
      29             : // -------------------------------------------------------------------------
      30             : //
      31             : // SalYieldMutex
      32             : //
      33             : // -------------------------------------------------------------------------
      34             : 
      35         151 : SalYieldMutex::SalYieldMutex()
      36             : {
      37         151 :     mnCount     = 0;
      38         151 :     mnThreadId  = 0;
      39         151 :     ::tools::SolarMutex::SetSolarMutex( this );
      40         151 : }
      41             : 
      42         282 : SalYieldMutex::~SalYieldMutex()
      43             : {
      44          94 :     ::tools::SolarMutex::SetSolarMutex( NULL );
      45         188 : }
      46             : 
      47     8899121 : void SalYieldMutex::acquire()
      48             : {
      49     8899121 :     SolarMutexObject::acquire();
      50     8899122 :     mnThreadId = osl::Thread::getCurrentIdentifier();
      51     8899122 :     mnCount++;
      52     8899122 : }
      53             : 
      54     8899065 : void SalYieldMutex::release()
      55             : {
      56             :     OSL_ENSURE(mnCount > 0, "SalYieldMutex::release() called with zero count");
      57     8899065 :     if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
      58             :     {
      59     8899065 :         if ( mnCount == 1 )
      60      449592 :             mnThreadId = 0;
      61     8899065 :         mnCount--;
      62             :     }
      63     8899065 :     SolarMutexObject::release();
      64     8899065 : }
      65             : 
      66           0 : bool SalYieldMutex::tryToAcquire()
      67             : {
      68           0 :     if ( SolarMutexObject::tryToAcquire() )
      69             :     {
      70           0 :         mnThreadId = osl::Thread::getCurrentIdentifier();
      71           0 :         mnCount++;
      72           0 :         return true;
      73             :     }
      74             :     else
      75           0 :         return false;
      76             : }
      77             : 
      78     5536400 : comphelper::SolarMutex* SalGenericInstance::GetYieldMutex()
      79             : {
      80     5536400 :     return mpSalYieldMutex;
      81             : }
      82             : 
      83      222529 : sal_uLong SalGenericInstance::ReleaseYieldMutex()
      84             : {
      85      222529 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
      86      445058 :     if ( pYieldMutex->GetThreadId() ==
      87      222529 :          osl::Thread::getCurrentIdentifier() )
      88             :     {
      89      222529 :         sal_uLong nCount = pYieldMutex->GetAcquireCount();
      90      222529 :         sal_uLong n = nCount;
      91      672801 :         while ( n )
      92             :         {
      93      227743 :             pYieldMutex->release();
      94      227743 :             n--;
      95             :         }
      96             : 
      97      222529 :         return nCount;
      98             :     }
      99             :     else
     100           0 :         return 0;
     101             : }
     102             : 
     103      222586 : void SalGenericInstance::AcquireYieldMutex( sal_uLong nCount )
     104             : {
     105      222586 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
     106      672972 :     while ( nCount )
     107             :     {
     108      227800 :         pYieldMutex->acquire();
     109      227800 :         nCount--;
     110             :     }
     111      222586 : }
     112             : 
     113           0 : bool SalGenericInstance::CheckYieldMutex()
     114             : {
     115           0 :     bool bRet = true;
     116             : 
     117           0 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
     118           0 :     if ( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier() )
     119           0 :         bRet = false;
     120             : 
     121           0 :     return bRet;
     122             : }
     123             : 
     124         188 : SalGenericInstance::~SalGenericInstance()
     125             : {
     126          94 :     ::tools::SolarMutex::SetSolarMutex( 0 );
     127          94 :     delete mpSalYieldMutex;
     128         559 : }

Generated by: LCOV version 1.10