LCOV - code coverage report
Current view: top level - libreoffice/vcl/generic/app - geninst.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 55 63.6 %
Date: 2012-12-27 Functions: 6 12 50.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             : #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          32 : SalYieldMutex::SalYieldMutex()
      36             : {
      37          32 :     mnCount     = 0;
      38          32 :     mnThreadId  = 0;
      39          32 :     ::tools::SolarMutex::SetSolarMutex( this );
      40          32 : }
      41             : 
      42           0 : SalYieldMutex::~SalYieldMutex()
      43             : {
      44           0 :     ::tools::SolarMutex::SetSolarMutex( NULL );
      45           0 : }
      46             : 
      47      964956 : void SalYieldMutex::acquire()
      48             : {
      49      964956 :     SolarMutexObject::acquire();
      50      964956 :     mnThreadId = osl::Thread::getCurrentIdentifier();
      51      964956 :     mnCount++;
      52      964956 : }
      53             : 
      54      964924 : void SalYieldMutex::release()
      55             : {
      56             :     OSL_ENSURE(mnCount > 0, "SalYieldMutex::release() called with zero count");
      57      964924 :     if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
      58             :     {
      59      964924 :         if ( mnCount == 1 )
      60         846 :             mnThreadId = 0;
      61      964924 :         mnCount--;
      62             :     }
      63      964924 :     SolarMutexObject::release();
      64      964924 : }
      65             : 
      66           0 : sal_Bool SalYieldMutex::tryToAcquire()
      67             : {
      68           0 :     if ( SolarMutexObject::tryToAcquire() )
      69             :     {
      70           0 :         mnThreadId = osl::Thread::getCurrentIdentifier();
      71           0 :         mnCount++;
      72           0 :         return sal_True;
      73             :     }
      74             :     else
      75           0 :         return sal_False;
      76             : }
      77             : 
      78      534141 : osl::SolarMutex* SalGenericInstance::GetYieldMutex()
      79             : {
      80      534141 :     return mpSalYieldMutex;
      81             : }
      82             : 
      83         846 : sal_uLong SalGenericInstance::ReleaseYieldMutex()
      84             : {
      85         846 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
      86        1692 :     if ( pYieldMutex->GetThreadId() ==
      87         846 :          osl::Thread::getCurrentIdentifier() )
      88             :     {
      89         846 :         sal_uLong nCount = pYieldMutex->GetAcquireCount();
      90         846 :         sal_uLong n = nCount;
      91        4216 :         while ( n )
      92             :         {
      93        2524 :             pYieldMutex->release();
      94        2524 :             n--;
      95             :         }
      96             : 
      97         846 :         return nCount;
      98             :     }
      99             :     else
     100           0 :         return 0;
     101             : }
     102             : 
     103         878 : void SalGenericInstance::AcquireYieldMutex( sal_uLong nCount )
     104             : {
     105         878 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
     106        4312 :     while ( nCount )
     107             :     {
     108        2556 :         pYieldMutex->acquire();
     109        2556 :         nCount--;
     110             :     }
     111         878 : }
     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           0 : SalGenericInstance::~SalGenericInstance()
     125             : {
     126           0 :     ::tools::SolarMutex::SetSolarMutex( 0 );
     127           0 :     delete mpSalYieldMutex;
     128           0 : }

Generated by: LCOV version 1.10