1*50e6b072SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*50e6b072SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*50e6b072SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*50e6b072SAndrew Rist  * distributed with this work for additional information
6*50e6b072SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*50e6b072SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*50e6b072SAndrew Rist  * "License"); you may not use this file except in compliance
9*50e6b072SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*50e6b072SAndrew Rist  *
11*50e6b072SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*50e6b072SAndrew Rist  *
13*50e6b072SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*50e6b072SAndrew Rist  * software distributed under the License is distributed on an
15*50e6b072SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*50e6b072SAndrew Rist  * KIND, either express or implied.  See the License for the
17*50e6b072SAndrew Rist  * specific language governing permissions and limitations
18*50e6b072SAndrew Rist  * under the License.
19*50e6b072SAndrew Rist  *
20*50e6b072SAndrew Rist  *************************************************************/
21*50e6b072SAndrew Rist 
22*50e6b072SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef TOOLKIT_INC_TOOLKIT_HELPER_SOLARRELEASE_HXX
25cdf0e10cSrcweir #define TOOLKIT_INC_TOOLKIT_HELPER_SOLARRELEASE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vcl/svapp.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //........................................................................
30cdf0e10cSrcweir namespace toolkit
31cdf0e10cSrcweir {
32cdf0e10cSrcweir //........................................................................
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 	//====================================================================
35cdf0e10cSrcweir 	//= ReleaseSolarMutex
36cdf0e10cSrcweir 	//====================================================================
37cdf0e10cSrcweir 	class ReleaseSolarMutex
38cdf0e10cSrcweir 	{
39cdf0e10cSrcweir         sal_uInt32  mnLockCount;
40cdf0e10cSrcweir         const bool  mbRescheduleDuringAcquire;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     public:
43cdf0e10cSrcweir         enum
44cdf0e10cSrcweir         {
45cdf0e10cSrcweir             RescheduleDuringAcquire = true
46cdf0e10cSrcweir         };
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     public:
ReleaseSolarMutex(const bool i_rescheduleDuringAcquire=false)49cdf0e10cSrcweir         ReleaseSolarMutex( const bool i_rescheduleDuringAcquire = false )
50cdf0e10cSrcweir             :mnLockCount( Application::ReleaseSolarMutex() )
51cdf0e10cSrcweir             ,mbRescheduleDuringAcquire( i_rescheduleDuringAcquire )
52cdf0e10cSrcweir         {
53cdf0e10cSrcweir 
54cdf0e10cSrcweir         }
55cdf0e10cSrcweir 
~ReleaseSolarMutex()56cdf0e10cSrcweir         ~ReleaseSolarMutex()
57cdf0e10cSrcweir         {
58cdf0e10cSrcweir             if ( mnLockCount > 0 )
59cdf0e10cSrcweir             {
60cdf0e10cSrcweir                 if ( mbRescheduleDuringAcquire )
61cdf0e10cSrcweir                 {
62cdf0e10cSrcweir                     while ( !Application::GetSolarMutex().tryToAcquire() )
63cdf0e10cSrcweir                     {
64cdf0e10cSrcweir                         Application::Reschedule();
65cdf0e10cSrcweir                     }
66cdf0e10cSrcweir                     --mnLockCount;
67cdf0e10cSrcweir                 }
68cdf0e10cSrcweir                 Application::AcquireSolarMutex( mnLockCount );
69cdf0e10cSrcweir             }
70cdf0e10cSrcweir         }
71cdf0e10cSrcweir 	};
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //........................................................................
74cdf0e10cSrcweir } // namespace toolkit
75cdf0e10cSrcweir //........................................................................
76cdf0e10cSrcweir 
77cdf0e10cSrcweir #endif // TOOLKIT_INC_TOOLKIT_HELPER_SOLARRELEASE_HXX
78cdf0e10cSrcweir 
79