1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SyncObjects.hxx,v $
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 //------------------------------------------------------------------------
37 //------------------------------------------------------------------------
41 //------------------------------------------------------------------------
42 // a simple helper template for automatic locking/unlocking
43 //------------------------------------------------------------------------
45 template< class LOCK
>
49 CLockGuard( LOCK
* aLock
) :
64 //------------------------------------------------------------------------
65 // a interface base class for different locking sub classes
66 //------------------------------------------------------------------------
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 //------------------------------------------------------------------------
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
98 virtual ~CCriticalSection( );
100 // both functions return always 0
101 // because the win32 critsec functions
102 // don't return any return code
104 virtual int Unlock( );
107 CRITICAL_SECTION m_critSec
;
111 typedef CLockGuard
< CSyncObject
> SyncObjLockGuard_t
;