Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <string.h>
31 : : #include <stdio.h>
32 : : #include <stdlib.h>
33 : :
34 : : #include "osl/module.hxx"
35 : : #include "tools/solarmutex.hxx"
36 : :
37 : : #include "generic/geninst.h"
38 : :
39 : : // -------------------------------------------------------------------------
40 : : //
41 : : // SalYieldMutex
42 : : //
43 : : // -------------------------------------------------------------------------
44 : :
45 : 266 : SalYieldMutex::SalYieldMutex()
46 : : {
47 : 266 : mnCount = 0;
48 : 266 : mnThreadId = 0;
49 [ + - ]: 266 : ::tools::SolarMutex::SetSolarMutex( this );
50 : 266 : }
51 : :
52 : 158 : SalYieldMutex::~SalYieldMutex()
53 : : {
54 [ + - ]: 158 : ::tools::SolarMutex::SetSolarMutex( NULL );
55 [ - + ]: 316 : }
56 : :
57 : 13818998 : void SalYieldMutex::acquire()
58 : : {
59 : 13818998 : SolarMutexObject::acquire();
60 : 13819001 : mnThreadId = osl::Thread::getCurrentIdentifier();
61 : 13819001 : mnCount++;
62 : 13819001 : }
63 : :
64 : 13818893 : void SalYieldMutex::release()
65 : : {
66 : : OSL_ENSURE(mnCount > 0, "SalYieldMutex::release() called with zero count");
67 [ + - ]: 13818893 : if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
68 : : {
69 [ + + ]: 13818893 : if ( mnCount == 1 )
70 : 834049 : mnThreadId = 0;
71 : 13818893 : mnCount--;
72 : : }
73 : 13818893 : SolarMutexObject::release();
74 : 13818890 : }
75 : :
76 : 0 : sal_Bool SalYieldMutex::tryToAcquire()
77 : : {
78 [ # # ]: 0 : if ( SolarMutexObject::tryToAcquire() )
79 : : {
80 : 0 : mnThreadId = osl::Thread::getCurrentIdentifier();
81 : 0 : mnCount++;
82 : 0 : return sal_True;
83 : : }
84 : : else
85 : 0 : return sal_False;
86 : : }
87 : :
88 : 8112975 : osl::SolarMutex* SalGenericInstance::GetYieldMutex()
89 : : {
90 : 8112975 : return mpSalYieldMutex;
91 : : }
92 : :
93 : 392126 : sal_uLong SalGenericInstance::ReleaseYieldMutex()
94 : : {
95 : 392126 : SalYieldMutex* pYieldMutex = mpSalYieldMutex;
96 [ + - ]: 784252 : if ( pYieldMutex->GetThreadId() ==
97 : 392126 : osl::Thread::getCurrentIdentifier() )
98 : : {
99 : 392126 : sal_uLong nCount = pYieldMutex->GetAcquireCount();
100 : 392126 : sal_uLong n = nCount;
101 [ + + ]: 792706 : while ( n )
102 : : {
103 : 400580 : pYieldMutex->release();
104 : 400580 : n--;
105 : : }
106 : :
107 : 392126 : return nCount;
108 : : }
109 : : else
110 : 392126 : return 0;
111 : : }
112 : :
113 : 392234 : void SalGenericInstance::AcquireYieldMutex( sal_uLong nCount )
114 : : {
115 : 392234 : SalYieldMutex* pYieldMutex = mpSalYieldMutex;
116 [ + + ]: 792922 : while ( nCount )
117 : : {
118 : 400688 : pYieldMutex->acquire();
119 : 400688 : nCount--;
120 : : }
121 : 392234 : }
122 : :
123 : 0 : bool SalGenericInstance::CheckYieldMutex()
124 : : {
125 : 0 : bool bRet = true;
126 : :
127 : 0 : SalYieldMutex* pYieldMutex = mpSalYieldMutex;
128 [ # # ]: 0 : if ( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier() )
129 : 0 : bRet = false;
130 : :
131 : 0 : return bRet;
132 : : }
133 : :
134 : 158 : SalGenericInstance::~SalGenericInstance()
135 : : {
136 [ + - ]: 158 : ::tools::SolarMutex::SetSolarMutex( 0 );
137 [ + - ][ + - ]: 158 : delete mpSalYieldMutex;
138 [ - + ]: 158 : }
|