fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / vcl / generic / app / geninst.cxx
blob22a3975ab3a6c80251042017ae0c1d8418b76190
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <string.h>
21 #include <stdio.h>
22 #include <stdlib.h>
24 #include "osl/module.hxx"
25 #include "tools/solarmutex.hxx"
27 #include "generic/geninst.h"
29 // -------------------------------------------------------------------------
31 // SalYieldMutex
33 // -------------------------------------------------------------------------
35 SalYieldMutex::SalYieldMutex()
37 mnCount = 0;
38 mnThreadId = 0;
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();
51 mnCount++;
54 void SalYieldMutex::release()
56 OSL_ENSURE(mnCount > 0, "SalYieldMutex::release() called with zero count");
57 if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
59 if ( mnCount == 1 )
60 mnThreadId = 0;
61 mnCount--;
63 SolarMutexObject::release();
66 bool SalYieldMutex::tryToAcquire()
68 if ( SolarMutexObject::tryToAcquire() )
70 mnThreadId = osl::Thread::getCurrentIdentifier();
71 mnCount++;
72 return true;
74 else
75 return false;
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();
90 sal_uLong n = nCount;
91 while ( n )
93 pYieldMutex->release();
94 n--;
97 return nCount;
99 else
100 return 0;
103 void SalGenericInstance::AcquireYieldMutex( sal_uLong nCount )
105 SalYieldMutex* pYieldMutex = mpSalYieldMutex;
106 while ( nCount )
108 pYieldMutex->acquire();
109 nCount--;
113 bool SalGenericInstance::CheckYieldMutex()
115 bool bRet = true;
117 SalYieldMutex* pYieldMutex = mpSalYieldMutex;
118 if ( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier() )
119 bRet = false;
121 return bRet;
124 SalGenericInstance::~SalGenericInstance()
126 ::tools::SolarMutex::SetSolarMutex( 0 );
127 delete mpSalYieldMutex;