1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef COMPHELPER_SHAREDMUTEX_HXX
25 #define COMPHELPER_SHAREDMUTEX_HXX
26 
27 #include "comphelper/comphelperdllapi.h"
28 
29 #include <osl/mutex.hxx>
30 
31 #include <boost/shared_ptr.hpp>
32 
33 //........................................................................
34 namespace comphelper
35 {
36 //........................................................................
37 
38     //============================================================
39     //= SharedMutex
40     //============================================================
41     class COMPHELPER_DLLPUBLIC SharedMutex
42     {
43     public:
44         SharedMutex();
45         SharedMutex( const SharedMutex& );
46         SharedMutex& operator=( const SharedMutex& );
~SharedMutex()47         ~SharedMutex()
48         {
49         }
50 
getMutex()51         inline ::osl::Mutex& getMutex() { return *m_pMutexImpl; }
operator ::osl::Mutex&()52         inline operator ::osl::Mutex& () { return *m_pMutexImpl; }
53 
54     private:
55         ::boost::shared_ptr< ::osl::Mutex >  m_pMutexImpl;
56     };
57 
58     //============================================================
59     //= SharedMutexBase
60     //============================================================
61     /** sometimes, it's necessary to have an initialized ::osl::Mutex to pass
62         to some ctor call of your base class. In this case, you can't hold the
63         SharedMutex as member, but you need to move it into another base class,
64         which is initialized before the mutex-requiring class is.
65     */
66     class COMPHELPER_DLLPUBLIC SharedMutexBase
67     {
68     protected:
SharedMutexBase()69         SharedMutexBase()
70         {
71         }
~SharedMutexBase()72         ~SharedMutexBase()
73         {
74         }
75 
76     protected:
getMutex() const77         ::osl::Mutex&   getMutex() const { return m_aMutex; }
getSharedMutex() const78         SharedMutex&    getSharedMutex() const { return m_aMutex; }
79 
80     private:
81         mutable SharedMutex m_aMutex;
82     };
83 
84 //........................................................................
85 } // namespace comphelper
86 //........................................................................
87 
88 #endif // COMPHELPER_SHAREDMUTEX_HXX
89