bump product version to 4.1.6.2
[LibreOffice.git] / package / inc / mutexholder.hxx
blobc88e229bd593165b6133e06f6a2a5a8600e3f0cc
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 __MUTEXHOLDER_HXX_
21 #define __MUTEXHOLDER_HXX_
23 #include <osl/mutex.hxx>
25 class SotMutexHolder
27 ::osl::Mutex m_aMutex;
28 sal_Int32 m_nRefCount;
30 public:
31 SotMutexHolder() : m_nRefCount( 0 ) {}
33 void AddRef()
35 m_nRefCount++;
38 void ReleaseRef()
40 if ( !--m_nRefCount )
41 delete this;
44 ::osl::Mutex& GetMutex() { return m_aMutex; }
47 class SotMutexHolderRef
49 SotMutexHolder* m_pHolder;
51 public:
52 SotMutexHolderRef()
53 : m_pHolder( NULL )
56 SotMutexHolderRef( SotMutexHolder* pHolder )
57 : m_pHolder( pHolder )
59 if ( m_pHolder )
60 m_pHolder->AddRef();
63 SotMutexHolderRef( const SotMutexHolderRef& rRef )
64 : m_pHolder( rRef.m_pHolder )
66 if ( m_pHolder )
67 m_pHolder->AddRef();
70 ~SotMutexHolderRef()
72 if ( m_pHolder )
73 m_pHolder->ReleaseRef();
76 SotMutexHolderRef& operator =( const SotMutexHolderRef& rRef )
78 if ( m_pHolder )
79 m_pHolder->ReleaseRef();
81 m_pHolder = rRef.m_pHolder;
83 if ( m_pHolder )
84 m_pHolder->AddRef();
86 return *this;
89 SotMutexHolderRef& operator =( SotMutexHolder* pHolder )
91 if ( m_pHolder )
92 m_pHolder->ReleaseRef();
94 m_pHolder = pHolder;
96 if ( m_pHolder )
97 m_pHolder->AddRef();
98 return *this;
101 SotMutexHolder* operator ->() const
103 return m_pHolder;
106 SotMutexHolder& operator *() const
108 return *m_pHolder;
111 operator SotMutexHolder*() const
113 return m_pHolder;
116 sal_Bool Is() const
118 return m_pHolder != NULL;
122 #endif
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */