LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/browser - AsyncronousLink.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 29 33 87.9 %
Date: 2013-07-09 Functions: 8 9 88.9 %
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 <dbaccess/AsyncronousLink.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include <tools/debug.hxx>
      23             : 
      24             : //==================================================================
      25             : //= OAsyncronousLink
      26             : //==================================================================
      27             : using namespace dbaui;
      28             : DBG_NAME(OAsyncronousLink)
      29             : //------------------------------------------------------------------
      30           4 : OAsyncronousLink::OAsyncronousLink( const Link& _rHandler )
      31             :     :m_aHandler(_rHandler)
      32             :     ,m_aEventSafety()
      33             :     ,m_aDestructionSafety()
      34           4 :     ,m_nEventId(0)
      35             : {
      36             :     DBG_CTOR(OAsyncronousLink,NULL);
      37           4 : }
      38             : 
      39             : //------------------------------------------------------------------
      40           8 : OAsyncronousLink::~OAsyncronousLink()
      41             : {
      42             :     {
      43           4 :         ::osl::MutexGuard aEventGuard( m_aEventSafety );
      44           4 :         if ( m_nEventId )
      45           0 :             Application::RemoveUserEvent(m_nEventId);
      46           4 :         m_nEventId = 0;
      47             :     }
      48             : 
      49             :     {
      50           4 :         ::osl::MutexGuard aDestructionGuard( m_aDestructionSafety );
      51             :         // this is just for the case we're deleted while another thread just handled the event :
      52             :         // if this other thread called our link while we were deleting the event here, the
      53             :         // link handler blocked. With leaving the above block it continued, but now we are prevented
      54             :         // to leave this destructor 'til the link handler recognizes that nEvent == 0 and leaves.
      55             :     }
      56             :     DBG_DTOR(OAsyncronousLink,NULL);
      57           4 : }
      58             : 
      59             : 
      60             : //------------------------------------------------------------------
      61           8 : void OAsyncronousLink::Call( void* _pArgument )
      62             : {
      63           8 :     ::osl::MutexGuard aEventGuard( m_aEventSafety );
      64           8 :     if (m_nEventId)
      65           0 :         Application::RemoveUserEvent(m_nEventId);
      66           8 :     m_nEventId = Application::PostUserEvent( LINK( this, OAsyncronousLink, OnAsyncCall ), _pArgument );
      67           8 : }
      68             : 
      69             : //------------------------------------------------------------------
      70           1 : void OAsyncronousLink::CancelCall()
      71             : {
      72           1 :     ::osl::MutexGuard aEventGuard( m_aEventSafety );
      73           1 :     if ( m_nEventId )
      74           1 :         Application::RemoveUserEvent( m_nEventId );
      75           1 :     m_nEventId = 0;
      76           1 : }
      77             : 
      78             : //------------------------------------------------------------------
      79          14 : IMPL_LINK(OAsyncronousLink, OnAsyncCall, void*, _pArg)
      80             : {
      81             :     {
      82           7 :         ::osl::MutexGuard aDestructionGuard( m_aDestructionSafety );
      83             :         {
      84           7 :             ::osl::MutexGuard aEventGuard( m_aEventSafety );
      85           7 :             if (!m_nEventId)
      86             :                 // our destructor deleted the event just while we we're waiting for m_aEventSafety
      87             :                 // -> get outta here
      88           0 :                 return 0;
      89           7 :             m_nEventId = 0;
      90           7 :         }
      91             :     }
      92           7 :     if (m_aHandler.IsSet())
      93           7 :         return m_aHandler.Call(_pArg);
      94             : 
      95           0 :     return 0L;
      96          12 : }
      97             : 
      98             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10