Files
libreoffice/framework/inc/threadhelp/lockhelper.hxx

151 lines
8.1 KiB
C++
Raw Normal View History

2010-10-27 13:11:31 +01:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by: Armin Le Grand. #118558# Correcting OLE attributes of LO3.4 at load time by loading as OOo3.3, details see task. http://svn.apache.org/viewvc?view=revision&revision=1195906 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118898# Adapted ImpGraphic::ImplGetBitmap to correctly convert metafiles http://svn.apache.org/viewvc?view=revision&revision=1293316 #119337# Solves the wrong get/setPropertyValue calls in SvxShapeText (and thus in SvxOle2Shape) http://svn.apache.org/viewvc?view=revision&revision=1344156 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117717#: remove wrong assertion http://svn.apache.org/viewvc?view=revision&revision=1172349 Patch contributed by Herbert Duerr goodbye Registration and License dialogs, don't let the door hit you http://svn.apache.org/viewvc?view=revision&revision=1172613 help gcc 4.6.0 on 32bit ubuntu 11.10" http://svn.apache.org/viewvc?view=revision&revision=1245357 Do not add targets for junit tests when junit is disabled. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1241508 Revert "sb140: #i117082# avoid unncessary static class data members commit 21d97438e2944861e26e4984195f959a0cce1e41. remove obsolete FreeBSD visibility special case. retain consolidated BSD bridge code, remove OS/2 pieces.
2012-11-12 17:21:24 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2001-06-11 09:12:01 +00:00
#ifndef __FRAMEWORK_THREADHELP_LOCKHELPER_HXX_
#define __FRAMEWORK_THREADHELP_LOCKHELPER_HXX_
#include <threadhelp/inoncopyable.h>
#include <framework/imutex.hxx>
2001-06-11 09:12:01 +00:00
#include <threadhelp/irwlock.h>
#include <threadhelp/fairrwlock.hxx>
#include <comphelper/solarmutex.hxx>
#include <fwidllapi.h>
2001-06-11 09:12:01 +00:00
namespace framework{
/*-************************************************************************************************************//**
@descr If you use a lock or mutex as a member of your class and whish to use it earlier then other ones
you should have a look on this implementation. You must use it as the first base class
of your implementation - because base classes are initialized by his order and before your
member! Thats why ist a good place to declare your thread help member so.
*//*-*************************************************************************************************************/
enum ELockType
{
E_NOTHING = 0 ,
E_OWNMUTEX = 1 ,
E_SOLARMUTEX = 2 ,
E_FAIRRWLOCK = 3
};
#define ENVVAR_LOCKTYPE DECLARE_ASCII("LOCKTYPE_FRAMEWORK")
2001-06-26 04:28:51 +00:00
#define FALLBACK_LOCKTYPE E_SOLARMUTEX
2001-06-11 09:12:01 +00:00
/*-************************************************************************************************************//**
@short helper to set right lock in right situation
@descr This helper support different types of locking:
a) no locks - transparent for user!
This could be useful for simluation or single threaded environments!
2001-06-11 09:12:01 +00:00
b) own mutex
An object use his own osl-mutex to be threadsafe. Useful for easy and exclusiv locking.
2001-06-11 09:12:01 +00:00
c) solar mutex
An object use our solar mutex and will be a part of a greater safed "threadsafe code block".
Could be useful for simulation and testing of higher modules!
2001-06-11 09:12:01 +00:00
d) fair rw-lock
An object use an implementation of a fair rw-lock. This increase granularity of t hreadsafe mechanism
and should be used for high performance threadsafe code!
@attention We support two interfaces - "IMutex" and "IRWLock". Don't mix using of it!
A guard implementation should use one interface only!
@implements IMutex
@implements IRWLock
@base INonCopyable
IMutex
IRWLock
@devstatus draft
*//*-*************************************************************************************************************/
class FWI_DLLPUBLIC LockHelper : public IMutex
2001-06-11 09:12:01 +00:00
, public IRWLock
, private INonCopyable
{
//-------------------------------------------------------------------------------------------------------------
// public methods
//-------------------------------------------------------------------------------------------------------------
public:
//-------------------------------------------------------------------------------------------------------------
// ctor/dtor
//-------------------------------------------------------------------------------------------------------------
LockHelper( comphelper::SolarMutex* pSolarMutex = NULL );
2001-06-11 09:12:01 +00:00
virtual ~LockHelper( );
//-------------------------------------------------------------------------------------------------------------
// interface ::framework::IMutex
//-------------------------------------------------------------------------------------------------------------
virtual void acquire();
virtual void release();
//-------------------------------------------------------------------------------------------------------------
// interface ::framework::IRWLock
//-------------------------------------------------------------------------------------------------------------
virtual void acquireReadAccess ();
virtual void releaseReadAccess ();
virtual void acquireWriteAccess ();
virtual void releaseWriteAccess ();
virtual void downgradeWriteAccess();
//-------------------------------------------------------------------------------------------------------------
// something else
//-------------------------------------------------------------------------------------------------------------
static LockHelper& getGlobalLock ( comphelper::SolarMutex* pSolarMutex = NULL );
2001-06-11 09:12:01 +00:00
::osl::Mutex& getShareableOslMutex( );
//-------------------------------------------------------------------------------------------------------------
// private methods
//-------------------------------------------------------------------------------------------------------------
private:
static ELockType& implts_getLockType();
//-------------------------------------------------------------------------------------------------------------
// private member
// a) Make some member mutable for using in const functions!
// b) "m_eLockType" define, which of follow members is used!
// You can use "m_pFairRWLock" as a fair rw-lock (multiple reader / one writer / looks for incoming order of threads too) ...
// or you can use a normal osl mutex ("m_pOwnMutex") ...
// ... or the solarmuex as "m_pSolarMutex" (must be set from outside! because some components must be vcl-free!)
// ... but sometimes you need a shareable osl mutex!
// In this case you has some problems: i ) If your lock type is set to E_OWNMUTEX => it's easy; you can use your member "m_pOwnMutex" - it's a osl mutex.
// Creation and using of "m_pShareableOslMutex" isn't necessary!
2001-06-11 09:12:01 +00:00
// ii ) Otherwise you have no osl mutex ... so you must create "m_pShareableOslMutex" and use it twice!
// In this case you must lock two member everytime - "m_pShareableMutex" AND "m_pFairRWLock" or "m_pSolarMutex" or ...
// It isn't realy fine - but the only possible way.
// iii) There exist another special case - E_NOTHING is set! Then we should create this shareable mutex ...
// nad you can use it ... but this implmentation ignore it.
//-------------------------------------------------------------------------------------------------------------
private:
ELockType m_eLockType ;
mutable FairRWLock* m_pFairRWLock ;
mutable ::osl::Mutex* m_pOwnMutex ;
mutable comphelper::SolarMutex* m_pSolarMutex ;
2001-06-11 09:12:01 +00:00
mutable ::osl::Mutex* m_pShareableOslMutex ;
mutable sal_Bool m_bDummySolarMutex ;
2001-06-11 09:12:01 +00:00
};
} // namespace framework
#endif // #ifndef __FRAMEWORK_THREADHELP_LOCKHELPER_HXX_
2010-10-27 13:11:31 +01:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */