LCOV - code coverage report
Current view: top level - vcl/generic/app - geninst.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 48 56 85.7 %
Date: 2015-06-13 12:38:46 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 <stdlib.h>
      22             : 
      23             : #include <osl/module.hxx>
      24             : #include <tools/solarmutex.hxx>
      25             : #include <vcl/opengl/OpenGLContext.hxx>
      26             : 
      27             : #include "generic/geninst.h"
      28             : 
      29             : // SalYieldMutex
      30             : 
      31         245 : SalYieldMutex::SalYieldMutex()
      32             : {
      33         245 :     mnCount     = 0;
      34         245 :     mnThreadId  = 0;
      35         245 :     ::tools::SolarMutex::SetSolarMutex( this );
      36         245 : }
      37             : 
      38         725 : SalYieldMutex::~SalYieldMutex()
      39             : {
      40         242 :     ::tools::SolarMutex::SetSolarMutex( NULL );
      41         483 : }
      42             : 
      43    48797312 : void SalYieldMutex::acquire()
      44             : {
      45    48797312 :     m_mutex.acquire();
      46    48797320 :     mnThreadId = osl::Thread::getCurrentIdentifier();
      47    48797320 :     mnCount++;
      48    48797320 : }
      49             : 
      50    48797318 : void SalYieldMutex::release()
      51             : {
      52             :     OSL_ENSURE(mnCount > 0, "SalYieldMutex::release() called with zero count");
      53    48797318 :     if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
      54             :     {
      55    48797318 :         if ( mnCount == 1 )
      56             :         {
      57    13794207 :             OpenGLContext::clearCurrent();
      58    13794207 :             mnThreadId = 0;
      59             :         }
      60    48797318 :         mnCount--;
      61             :     }
      62    48797318 :     m_mutex.release();
      63    48797318 : }
      64             : 
      65           1 : bool SalYieldMutex::tryToAcquire()
      66             : {
      67           1 :     if ( m_mutex.tryToAcquire() )
      68             :     {
      69           1 :         mnThreadId = osl::Thread::getCurrentIdentifier();
      70           1 :         mnCount++;
      71           1 :         return true;
      72             :     }
      73             :     else
      74           0 :         return false;
      75             : }
      76             : 
      77    21610697 : comphelper::SolarMutex* SalGenericInstance::GetYieldMutex()
      78             : {
      79    21610697 :     return mpSalYieldMutex;
      80             : }
      81             : 
      82    13558633 : sal_uLong SalGenericInstance::ReleaseYieldMutex()
      83             : {
      84    13558633 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
      85    27117266 :     if ( pYieldMutex->GetThreadId() ==
      86    13558633 :          osl::Thread::getCurrentIdentifier() )
      87             :     {
      88    13558633 :         sal_uLong nCount = pYieldMutex->GetAcquireCount();
      89    13558633 :         sal_uLong n = nCount;
      90    40696665 :         while ( n )
      91             :         {
      92    13579399 :             pYieldMutex->release();
      93    13579399 :             n--;
      94             :         }
      95             : 
      96    13558633 :         return nCount;
      97             :     }
      98             :     else
      99           0 :         return 0;
     100             : }
     101             : 
     102    13558636 : void SalGenericInstance::AcquireYieldMutex( sal_uLong nCount )
     103             : {
     104    13558636 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
     105    40696674 :     while ( nCount )
     106             :     {
     107    13579402 :         pYieldMutex->acquire();
     108    13579402 :         nCount--;
     109             :     }
     110    13558636 : }
     111             : 
     112           0 : bool SalGenericInstance::CheckYieldMutex()
     113             : {
     114           0 :     bool bRet = true;
     115             : 
     116           0 :     SalYieldMutex* pYieldMutex = mpSalYieldMutex;
     117           0 :     if ( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier() )
     118             :     {
     119             :         SAL_WARN("vcl", "CheckYieldMutex: " << pYieldMutex->GetThreadId() << "!=" << osl::Thread::getCurrentIdentifier() );
     120           0 :         bRet = false;
     121             :     }
     122             : 
     123           0 :     return bRet;
     124             : }
     125             : 
     126         484 : SalGenericInstance::~SalGenericInstance()
     127             : {
     128         242 :     ::tools::SolarMutex::SetSolarMutex( 0 );
     129         242 :     delete mpSalYieldMutex;
     130        1043 : }
     131             : 
     132             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11