Update ooo320-m1
[ooovba.git] / sal / inc / systools / win32 / SyncObjects.hxx
blob4b488f37ad30480f35ea158b5186577f73deb7b7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SyncObjects.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #ifndef _SYNCOBJECTS_HXX_
33 #define _SYNCOBJECTS_HXX_
35 //------------------------------------------------------------------------
36 // includes
37 //------------------------------------------------------------------------
39 #include <windows.h>
41 //------------------------------------------------------------------------
42 // a simple helper template for automatic locking/unlocking
43 //------------------------------------------------------------------------
45 template< class LOCK >
46 class CLockGuard
48 public:
49 CLockGuard( LOCK* aLock ) :
50 m_pLock( aLock )
52 m_pLock->Lock( );
55 ~CLockGuard( )
57 m_pLock->Unlock( );
60 private:
61 LOCK* m_pLock;
64 //------------------------------------------------------------------------
65 // a interface base class for different locking sub classes
66 //------------------------------------------------------------------------
68 class CSyncObject
70 public:
71 virtual ~CSyncObject( ) = 0;
73 virtual int Lock( ) = 0;
74 virtual int Unlock( ) = 0;
77 //------------------------------------------------------------------------
78 // if no synchronization is necessary this class will be used
79 // declaring the functions as inline safes runtime overhead
80 //------------------------------------------------------------------------
82 class CNullLock
84 public:
85 inline virtual ~CNullLock ( ) {};
86 inline virtual int Lock( ) {};
87 inline virtual int Unlock() {};
90 //------------------------------------------------------------------------
91 // a minimal wrapper for a win32 critical section
92 //------------------------------------------------------------------------
94 class CCriticalSection : public CSyncObject
96 public:
97 CCriticalSection( );
98 virtual ~CCriticalSection( );
100 // both functions return always 0
101 // because the win32 critsec functions
102 // don't return any return code
103 virtual int Lock( );
104 virtual int Unlock( );
106 private:
107 CRITICAL_SECTION m_critSec;
111 typedef CLockGuard< CSyncObject > SyncObjLockGuard_t;
113 #endif