1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
24 #include "osl/module.hxx"
25 #include "tools/solarmutex.hxx"
27 #include "generic/geninst.h"
29 // -------------------------------------------------------------------------
33 // -------------------------------------------------------------------------
35 SalYieldMutex::SalYieldMutex()
39 ::tools::SolarMutex::SetSolarMutex( this );
42 SalYieldMutex::~SalYieldMutex()
44 ::tools::SolarMutex::SetSolarMutex( NULL
);
47 void SalYieldMutex::acquire()
49 SolarMutexObject::acquire();
50 mnThreadId
= osl::Thread::getCurrentIdentifier();
54 void SalYieldMutex::release()
56 OSL_ENSURE(mnCount
> 0, "SalYieldMutex::release() called with zero count");
57 if ( mnThreadId
== osl::Thread::getCurrentIdentifier() )
63 SolarMutexObject::release();
66 bool SalYieldMutex::tryToAcquire()
68 if ( SolarMutexObject::tryToAcquire() )
70 mnThreadId
= osl::Thread::getCurrentIdentifier();
78 comphelper::SolarMutex
* SalGenericInstance::GetYieldMutex()
80 return mpSalYieldMutex
;
83 sal_uLong
SalGenericInstance::ReleaseYieldMutex()
85 SalYieldMutex
* pYieldMutex
= mpSalYieldMutex
;
86 if ( pYieldMutex
->GetThreadId() ==
87 osl::Thread::getCurrentIdentifier() )
89 sal_uLong nCount
= pYieldMutex
->GetAcquireCount();
93 pYieldMutex
->release();
103 void SalGenericInstance::AcquireYieldMutex( sal_uLong nCount
)
105 SalYieldMutex
* pYieldMutex
= mpSalYieldMutex
;
108 pYieldMutex
->acquire();
113 bool SalGenericInstance::CheckYieldMutex()
117 SalYieldMutex
* pYieldMutex
= mpSalYieldMutex
;
118 if ( pYieldMutex
->GetThreadId() != osl::Thread::getCurrentIdentifier() )
124 SalGenericInstance::~SalGenericInstance()
126 ::tools::SolarMutex::SetSolarMutex( 0 );
127 delete mpSalYieldMutex
;