update credits
[LibreOffice.git] / framework / inc / threadhelp / lockhelper.hxx
blob72f2d2271ae08d52d89a845f51f7cd717fe93f55
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 #ifndef __FRAMEWORK_THREADHELP_LOCKHELPER_HXX_
21 #define __FRAMEWORK_THREADHELP_LOCKHELPER_HXX_
23 #include <threadhelp/inoncopyable.h>
24 #include <framework/imutex.hxx>
25 #include <threadhelp/irwlock.h>
26 #include <threadhelp/fairrwlock.hxx>
28 #include <comphelper/solarmutex.hxx>
29 #include <fwidllapi.h>
31 namespace framework{
33 /*-************************************************************************************************************//**
34 @short helper to set right lock in right situation
35 @descr This helper support different types of locking:
36 a) no locks - transparent for user!
37 This could be useful for simluation or single threaded environments!
38 b) own mutex
39 An object use his own osl-mutex to be threadsafe. Useful for easy and exclusiv locking.
40 c) solar mutex
41 An object use our solar mutex and will be a part of a greater safed "threadsafe code block".
42 Could be useful for simulation and testing of higher modules!
43 d) fair rw-lock
44 An object use an implementation of a fair rw-lock. This increase granularity of t hreadsafe mechanism
45 and should be used for high performance threadsafe code!
47 @attention We support two interfaces - "IMutex" and "IRWLock". Don't mix using of it!
48 A guard implementation should use one interface only!
50 @implements IMutex
51 @implements IRWLock
53 @base INonCopyable
54 IMutex
55 IRWLock
57 @devstatus draft
58 *//*-*************************************************************************************************************/
59 class FWI_DLLPUBLIC LockHelper : public IMutex
60 , public IRWLock
61 , private INonCopyable
63 //-------------------------------------------------------------------------------------------------------------
64 // public methods
65 //-------------------------------------------------------------------------------------------------------------
66 public:
68 //-------------------------------------------------------------------------------------------------------------
69 // ctor/dtor
70 //-------------------------------------------------------------------------------------------------------------
71 LockHelper( comphelper::SolarMutex* pSolarMutex = NULL );
72 virtual ~LockHelper( );
74 //-------------------------------------------------------------------------------------------------------------
75 // interface ::framework::IMutex
76 //-------------------------------------------------------------------------------------------------------------
77 virtual void acquire();
78 virtual void release();
80 //-------------------------------------------------------------------------------------------------------------
81 // interface ::framework::IRWLock
82 //-------------------------------------------------------------------------------------------------------------
83 virtual void acquireReadAccess ();
84 virtual void releaseReadAccess ();
85 virtual void acquireWriteAccess ();
86 virtual void releaseWriteAccess ();
87 virtual void downgradeWriteAccess();
89 //-------------------------------------------------------------------------------------------------------------
90 // something else
91 //-------------------------------------------------------------------------------------------------------------
92 static LockHelper& getGlobalLock();
93 //TODO: this presumable should return the SolarMutex, though it
94 // actually returns some independent mutex
96 ::osl::Mutex& getShareableOslMutex( );
98 //-------------------------------------------------------------------------------------------------------------
99 // private member
100 // Make some member mutable for using in const functions!
101 //-------------------------------------------------------------------------------------------------------------
102 private:
104 mutable comphelper::SolarMutex* m_pSolarMutex ;
105 mutable ::osl::Mutex* m_pShareableOslMutex ;
106 mutable sal_Bool m_bDummySolarMutex ;
109 } // namespace framework
111 #endif // #ifndef __FRAMEWORK_THREADHELP_LOCKHELPER_HXX_
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */