LCOV - code coverage report
Current view: top level - vcl/generic/app - geninst.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 47 55 85.5 %
Date: 2014-11-03 Functions: 12 14 85.7 %
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             : // SalYieldMutex
      30             : 
      31         373 : SalYieldMutex::SalYieldMutex()
      32             : {
      33         373 :     mnCount     = 0;
      34         373 :     mnThreadId  = 0;
      35         373 :     ::tools::SolarMutex::SetSolarMutex( this );
      36         373 : }
      37             : 
      38        1101 : SalYieldMutex::~SalYieldMutex()
      39             : {
      40         367 :     ::tools::SolarMutex::SetSolarMutex( NULL );
      41         734 : }
      42             : 
      43    35560976 : void SalYieldMutex::acquire()
      44             : {
      45    35560976 :     m_mutex.acquire();
      46    35561084 :     mnThreadId = osl::Thread::getCurrentIdentifier();
      47    35561084 :     mnCount++;
      48    35561084 : }
      49             : 
      50    35561080 : void SalYieldMutex::release()
      51             : {
      52             :     OSL_ENSURE(mnCount > 0, "SalYieldMutex::release() called with zero count");
      53    35561080 :     if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
      54             :     {
      55    35561080 :         if ( mnCount == 1 )
      56     3000263 :             mnThreadId = 0;
      57    35561080 :         mnCount--;
      58             :     }
      59    35561080 :     m_mutex.release();
      60    35561079 : }
      61             : 
      62           2 : bool SalYieldMutex::tryToAcquire()
      63             : {
      64           2 :     if ( m_mutex.tryToAcquire() )
      65             :     {
      66           2 :         mnThreadId = osl::Thread::getCurrentIdentifier();
      67           2 :         mnCount++;
      68           2 :         return true;
      69             :     }
      70             :     else
      71           0 :         return false;
      72             : }
      73             : 
      74    32556098 : comphelper::SolarMutex* SalGenericInstance::GetYieldMutex()
      75             : {
      76    32556098 :     return mpSalYieldMutex;
      77             : }
      78             : 
      79     2543422 : sal_uLong SalGenericInstance::ReleaseYieldMutex()
      80             : {
      81     2543422 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
      82     5086844 :     if ( pYieldMutex->GetThreadId() ==
      83     2543422 :          osl::Thread::getCurrentIdentifier() )
      84             :     {
      85     2543422 :         sal_uLong nCount = pYieldMutex->GetAcquireCount();
      86     2543422 :         sal_uLong n = nCount;
      87     7668755 :         while ( n )
      88             :         {
      89     2581911 :             pYieldMutex->release();
      90     2581911 :             n--;
      91             :         }
      92             : 
      93     2543422 :         return nCount;
      94             :     }
      95             :     else
      96           0 :         return 0;
      97             : }
      98             : 
      99     2543428 : void SalGenericInstance::AcquireYieldMutex( sal_uLong nCount )
     100             : {
     101     2543428 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
     102     7668773 :     while ( nCount )
     103             :     {
     104     2581917 :         pYieldMutex->acquire();
     105     2581917 :         nCount--;
     106             :     }
     107     2543428 : }
     108             : 
     109           0 : bool SalGenericInstance::CheckYieldMutex()
     110             : {
     111           0 :     bool bRet = true;
     112             : 
     113           0 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
     114           0 :     if ( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier() )
     115             :     {
     116             :         SAL_WARN_IF( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier(), "vcl", "CheckYieldMutex: " << pYieldMutex->GetThreadId() << "!=" << osl::Thread::getCurrentIdentifier() );
     117           0 :         bRet = false;
     118             :     }
     119             : 
     120           0 :     return bRet;
     121             : }
     122             : 
     123         734 : SalGenericInstance::~SalGenericInstance()
     124             : {
     125         367 :     ::tools::SolarMutex::SetSolarMutex( 0 );
     126         367 :     delete mpSalYieldMutex;
     127        1600 : }
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10