2010-10-27 13:11:31 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2001-06-11 09:12:01 +00:00
|
|
|
|
2013-11-05 02:25:45 +01:00
|
|
|
#ifndef INCLUDED_FRAMEWORK_INC_THREADHELP_LOCKHELPER_HXX
|
|
|
|
#define INCLUDED_FRAMEWORK_INC_THREADHELP_LOCKHELPER_HXX
|
2001-06-11 09:12:01 +00:00
|
|
|
|
2014-03-17 14:29:13 +01:00
|
|
|
#include <boost/noncopyable.hpp>
|
2014-03-20 15:49:27 +01:00
|
|
|
#include <osl/mutex.hxx>
|
|
|
|
#include <rtl/instance.hxx>
|
2001-06-11 09:12:01 +00:00
|
|
|
|
2013-05-14 13:15:38 +02:00
|
|
|
#include <comphelper/solarmutex.hxx>
|
2010-04-16 23:01:28 +02:00
|
|
|
#include <fwidllapi.h>
|
2001-06-11 09:12:01 +00:00
|
|
|
|
|
|
|
namespace framework{
|
|
|
|
|
2014-03-20 15:49:27 +01:00
|
|
|
//TODO: This presumable should return the SolarMutex, though it actually returns
|
|
|
|
// some independent mutex:
|
|
|
|
struct GlobalLock: public rtl::Static<osl::Mutex, GlobalLock> {};
|
|
|
|
|
2014-02-25 18:54:02 +01:00
|
|
|
/*-************************************************************************************************************
|
2001-06-11 09:12:01 +00:00
|
|
|
@short helper to set right lock in right situation
|
|
|
|
@descr This helper support different types of locking:
|
|
|
|
a) no locks - transparent for user!
|
2013-02-22 11:12:12 +01:00
|
|
|
This could be useful for simluation or single threaded environments!
|
2001-06-11 09:12:01 +00:00
|
|
|
b) own mutex
|
2013-02-22 11:12:12 +01:00
|
|
|
An object use his own osl-mutex to be threadsafe. Useful for easy and exclusiv locking.
|
2001-06-11 09:12:01 +00:00
|
|
|
c) solar mutex
|
|
|
|
An object use our solar mutex and will be a part of a greater safed "threadsafe code block".
|
2013-02-22 11:12:12 +01:00
|
|
|
Could be useful for simulation and testing of higher modules!
|
2001-06-11 09:12:01 +00:00
|
|
|
d) fair rw-lock
|
|
|
|
An object use an implementation of a fair rw-lock. This increase granularity of t hreadsafe mechanism
|
|
|
|
and should be used for high performance threadsafe code!
|
|
|
|
|
|
|
|
@devstatus draft
|
|
|
|
*//*-*************************************************************************************************************/
|
2014-03-17 17:41:23 +01:00
|
|
|
class FWI_DLLPUBLIC LockHelper : private boost::noncopyable
|
2001-06-11 09:12:01 +00:00
|
|
|
{
|
2014-02-25 18:54:02 +01:00
|
|
|
|
2001-06-11 09:12:01 +00:00
|
|
|
// public methods
|
2014-02-25 18:54:02 +01:00
|
|
|
|
2001-06-11 09:12:01 +00:00
|
|
|
public:
|
|
|
|
|
2014-02-25 18:54:02 +01:00
|
|
|
|
2001-06-11 09:12:01 +00:00
|
|
|
// ctor/dtor
|
2014-02-25 18:54:02 +01:00
|
|
|
|
2013-05-14 13:15:38 +02:00
|
|
|
LockHelper( comphelper::SolarMutex* pSolarMutex = NULL );
|
2014-03-17 17:41:23 +01:00
|
|
|
~LockHelper( );
|
2014-02-25 18:54:02 +01:00
|
|
|
|
2014-03-17 17:41:23 +01:00
|
|
|
void acquire();
|
|
|
|
void release();
|
2001-06-11 09:12:01 +00:00
|
|
|
|
|
|
|
// something else
|
2014-02-25 18:54:02 +01:00
|
|
|
|
2001-06-11 09:12:01 +00:00
|
|
|
::osl::Mutex& getShareableOslMutex( );
|
|
|
|
|
2014-02-25 18:54:02 +01:00
|
|
|
|
2001-06-11 09:12:01 +00:00
|
|
|
// private member
|
2013-05-14 14:01:01 +02:00
|
|
|
// Make some member mutable for using in const functions!
|
2014-02-25 18:54:02 +01:00
|
|
|
|
2001-06-11 09:12:01 +00:00
|
|
|
private:
|
|
|
|
|
2013-05-14 13:15:38 +02:00
|
|
|
mutable comphelper::SolarMutex* m_pSolarMutex ;
|
2001-06-11 09:12:01 +00:00
|
|
|
mutable ::osl::Mutex* m_pShareableOslMutex ;
|
2004-02-20 07:46:23 +00:00
|
|
|
mutable sal_Bool m_bDummySolarMutex ;
|
2001-06-11 09:12:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace framework
|
|
|
|
|
2013-11-05 02:25:45 +01:00
|
|
|
#endif // INCLUDED_FRAMEWORK_INC_THREADHELP_LOCKHELPER_HXX
|
2010-10-27 13:11:31 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|