Branch data 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 "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 : 8 : OAsyncronousLink::OAsyncronousLink( const Link& _rHandler )
31 : : :m_aHandler(_rHandler)
32 : : ,m_aEventSafety()
33 : : ,m_aDestructionSafety()
34 [ + - ]: 8 : ,m_nEventId(0)
35 : : {
36 : : DBG_CTOR(OAsyncronousLink,NULL);
37 : 8 : }
38 : :
39 : : //------------------------------------------------------------------
40 [ + - ]: 8 : OAsyncronousLink::~OAsyncronousLink()
41 : : {
42 : : {
43 [ + - ]: 8 : ::osl::MutexGuard aEventGuard( m_aEventSafety );
44 [ - + ]: 8 : if ( m_nEventId )
45 [ # # ]: 0 : Application::RemoveUserEvent(m_nEventId);
46 [ + - ]: 8 : m_nEventId = 0;
47 : : }
48 : :
49 : : {
50 [ + - ][ + - ]: 8 : ::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 [ - + ]: 8 : }
58 : :
59 : :
60 : : //------------------------------------------------------------------
61 : 11 : void OAsyncronousLink::Call( void* _pArgument )
62 : : {
63 [ + - ]: 11 : ::osl::MutexGuard aEventGuard( m_aEventSafety );
64 [ - + ]: 11 : if (m_nEventId)
65 [ # # ]: 0 : Application::RemoveUserEvent(m_nEventId);
66 [ + - ][ + - ]: 11 : m_nEventId = Application::PostUserEvent( LINK( this, OAsyncronousLink, OnAsyncCall ), _pArgument );
[ + - ]
67 : 11 : }
68 : :
69 : : //------------------------------------------------------------------
70 : 2 : void OAsyncronousLink::CancelCall()
71 : : {
72 [ + - ]: 2 : ::osl::MutexGuard aEventGuard( m_aEventSafety );
73 [ + - ]: 2 : if ( m_nEventId )
74 [ + - ]: 2 : Application::RemoveUserEvent( m_nEventId );
75 [ + - ]: 2 : m_nEventId = 0;
76 : 2 : }
77 : :
78 : : //------------------------------------------------------------------
79 : 9 : IMPL_LINK(OAsyncronousLink, OnAsyncCall, void*, _pArg)
80 : : {
81 : : {
82 [ + - ]: 9 : ::osl::MutexGuard aDestructionGuard( m_aDestructionSafety );
83 : : {
84 [ + - ]: 9 : ::osl::MutexGuard aEventGuard( m_aEventSafety );
85 [ - + ]: 9 : 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 [ + - ][ + - ]: 9 : m_nEventId = 0;
90 [ + - ][ + - ]: 9 : }
91 : : }
92 [ + - ]: 9 : if (m_aHandler.IsSet())
93 : 9 : return m_aHandler.Call(_pArg);
94 : :
95 : 9 : return 0L;
96 : : }
97 : :
98 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|