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>
26 #include <vcl/opengl/OpenGLContext.hxx>
28 #include "generic/geninst.h"
32 SalYieldMutex::SalYieldMutex()
36 ::tools::SolarMutex::SetSolarMutex( this );
39 SalYieldMutex::~SalYieldMutex()
41 ::tools::SolarMutex::SetSolarMutex( NULL
);
44 void SalYieldMutex::acquire()
47 mnThreadId
= osl::Thread::getCurrentIdentifier();
51 void SalYieldMutex::release()
53 OSL_ENSURE(mnCount
> 0, "SalYieldMutex::release() called with zero count");
54 if ( mnThreadId
== osl::Thread::getCurrentIdentifier() )
58 OpenGLContext::prepareForYield();
66 bool SalYieldMutex::tryToAcquire()
68 if ( m_mutex
.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() )
120 SAL_WARN("vcl", "CheckYieldMutex: " << pYieldMutex
->GetThreadId() << "!=" << osl::Thread::getCurrentIdentifier() );
127 SalGenericInstance::~SalGenericInstance()
129 ::tools::SolarMutex::SetSolarMutex( 0 );
130 delete mpSalYieldMutex
;
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */