diff options
author | Andreas Schlüns <as@openoffice.org> | 2001-05-02 12:00:52 +0000 |
---|---|---|
committer | Andreas Schlüns <as@openoffice.org> | 2001-05-02 12:00:52 +0000 |
commit | 64a00afb5d8a5bde0b0722cc69a5a2410e2a87b1 (patch) | |
tree | fcef1b1a0c22f85849f1d6e2782b26d6270c1b6a /framework/inc/threadhelp/transactionbase.hxx | |
parent | cf44008bfb2d909742269f5c5fd1cfcfc972f2d5 (diff) |
#85529# new threadsafe mechanism
Diffstat (limited to 'framework/inc/threadhelp/transactionbase.hxx')
-rw-r--r-- | framework/inc/threadhelp/transactionbase.hxx | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/framework/inc/threadhelp/transactionbase.hxx b/framework/inc/threadhelp/transactionbase.hxx new file mode 100644 index 0000000000..faca3bffb1 --- /dev/null +++ b/framework/inc/threadhelp/transactionbase.hxx @@ -0,0 +1,163 @@ +/************************************************************************* + * + * $RCSfile: transactionbase.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: as $ $Date: 2001-05-02 13:00:41 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef __FRAMEWORK_THREADHELP_TRANSACTIONBASE_H_ +#define __FRAMEWORK_THREADHELP_TRANSACTIONBASE_H_ + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ + +#ifndef __FRAMEWORK_THREADHELP_TRANSACTIONMANAGER_HXX_ +#include <threadhelp/transactionmanager.hxx> +#endif + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ + +//_________________________________________________________________________________________________________________ +// other includes +//_________________________________________________________________________________________________________________ + +//_________________________________________________________________________________________________________________ +// namespace +//_________________________________________________________________________________________________________________ + +namespace framework{ + +//_________________________________________________________________________________________________________________ +// const +//_________________________________________________________________________________________________________________ + +//_________________________________________________________________________________________________________________ +// declarations +//_________________________________________________________________________________________________________________ + +/*-************************************************************************************************************//** + @short make it possible to instanciate a transacion manager as first member! + @descr If you use a transaction manager as a member of your class and whish to use it earlier then other ones + you should have a look on this implementation. You must use it as the first base class + of your implementation - because base classes are initialized by his order and before your + member! Thats why ist a good place to declare this member. + + @implements - + @base - + + @devstatus ready to use +*//*-*************************************************************************************************************/ +struct TransactionBase +{ + //------------------------------------------------------------------------------------------------------------- + // public Methods + //------------------------------------------------------------------------------------------------------------- + public: + + /*-****************************************************************************************************//** + @short return a reference to a static manager + @descr Sometimes we need the global member! (e.g. in our own static methods) + We create our own "class global static" member threadsafe. + It will be created at first call only! + All other requests use these created one then directly. + + @seealso - + + @param - + @return A reference to a static member. + + @onerror No error should occure. + *//*-*****************************************************************************************************/ + + static TransactionManager& getGlobalTransactionManager() + { + // Initialize static member only for one time! + static TransactionManager* pManager = NULL; + // If these method first called (member not already exist!) ... + if( pManager == NULL ) + { + // ... we must create a new one. Protect follow code with the global mutex - + // It must be - we create a static variable! + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + // We must check our pointer again - because ... another instance of ouer class could be faster then these one! + if( pManager == NULL ) + { + // Create the new manager and set it for return on static variable. + static TransactionManager aManager; + pManager = &aManager; + } + } + // Return new created or already existing object. + return *pManager; + } + + //------------------------------------------------------------------------------------------------------------- + // public member + //------------------------------------------------------------------------------------------------------------- + public: + + mutable TransactionManager m_aTransactionManager ; /// "your" public manager-member! + /// Make it mutable for using in const functions! + +}; // struct TransactionBase + +} // namespace framework + +#endif // #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONBASE_H_ |