Kaydet (Commit) 7a67d7a7 authored tarafından Jochen Nitschke's avatar Jochen Nitschke Kaydeden (comit) Noel Grandin

use more thread safe static initializer in postgresql driver

Change-Id: Idb210207112994e1247c35e0dce1c6cd2f80f371
Reviewed-on: https://gerrit.libreoffice.org/53365Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst b4ba8dc9
...@@ -84,17 +84,11 @@ namespace pq_sdbc_driver ...@@ -84,17 +84,11 @@ namespace pq_sdbc_driver
{ {
static ::cppu::IPropertyArrayHelper & getResultSetPropertyArrayHelper() static ::cppu::IPropertyArrayHelper & getResultSetPropertyArrayHelper()
{ {
static ::cppu::IPropertyArrayHelper *pArrayHelper;
if( ! pArrayHelper )
{
MutexGuard guard( Mutex::getGlobalMutex() );
if( ! pArrayHelper )
{
static Property aTable[] =
{
// LEM TODO: this needs to be kept in sync with other, e.g. pq_statics.css:508 // LEM TODO: this needs to be kept in sync with other, e.g. pq_statics.css:508
// Should really share! // Should really share!
// At least use for the handles the #define'd values in .hxx file... // At least use for the handles the #define'd values in .hxx file...
static ::cppu::OPropertyArrayHelper arrayHelper(
Sequence<Property>{
Property( Property(
"CursorName", 0, "CursorName", 0,
::cppu::UnoType<OUString>::get() , 0 ), ::cppu::UnoType<OUString>::get() , 0 ),
...@@ -115,13 +109,9 @@ static ::cppu::IPropertyArrayHelper & getResultSetPropertyArrayHelper() ...@@ -115,13 +109,9 @@ static ::cppu::IPropertyArrayHelper & getResultSetPropertyArrayHelper()
::cppu::UnoType<sal_Int32>::get() , 0 ), ::cppu::UnoType<sal_Int32>::get() , 0 ),
Property( Property(
"ResultSetType", 6, "ResultSetType", 6,
::cppu::UnoType<sal_Int32>::get() , 0 ) ::cppu::UnoType<sal_Int32>::get() , 0 )},
}; true );
static_assert( SAL_N_ELEMENTS(aTable) == BASERESULTSET_SIZE, "wrong number of elements" ); static ::cppu::IPropertyArrayHelper *pArrayHelper = &arrayHelper;
static ::cppu::OPropertyArrayHelper arrayHelper( aTable, BASERESULTSET_SIZE, true );
pArrayHelper = &arrayHelper;
}
}
return *pArrayHelper; return *pArrayHelper;
} }
...@@ -176,20 +166,11 @@ Any BaseResultSet::queryInterface( const Type & rType ) ...@@ -176,20 +166,11 @@ Any BaseResultSet::queryInterface( const Type & rType )
Sequence<Type > BaseResultSet::getTypes() Sequence<Type > BaseResultSet::getTypes()
{ {
static Sequence< Type > *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static Sequence< Type > collection( static Sequence< Type > collection(
::comphelper::concatSequences( ::comphelper::concatSequences(
OPropertySetHelper::getTypes(), OPropertySetHelper::getTypes(),
BaseResultSet_BASE::getTypes())); BaseResultSet_BASE::getTypes()));
pCollection = &collection; return collection;
}
}
return *pCollection;
} }
Sequence< sal_Int8> BaseResultSet::getImplementationId() Sequence< sal_Int8> BaseResultSet::getImplementationId()
......
...@@ -39,8 +39,6 @@ ...@@ -39,8 +39,6 @@
#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/typeprovider.hxx>
#include <cppuhelper/queryinterface.hxx> #include <cppuhelper/queryinterface.hxx>
using osl::MutexGuard;
using com::sun::star::uno::Sequence; using com::sun::star::uno::Sequence;
using com::sun::star::uno::Any; using com::sun::star::uno::Any;
...@@ -82,20 +80,12 @@ css::uno::Any FakedUpdateableResultSet::queryInterface( ...@@ -82,20 +80,12 @@ css::uno::Any FakedUpdateableResultSet::queryInterface(
css::uno::Sequence< css::uno::Type > FakedUpdateableResultSet::getTypes() css::uno::Sequence< css::uno::Type > FakedUpdateableResultSet::getTypes()
{ {
static cppu::OTypeCollection *pCollection; static cppu::OTypeCollection s_collection(
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection(
cppu::UnoType<XResultSetUpdate>::get(), cppu::UnoType<XResultSetUpdate>::get(),
cppu::UnoType<XRowUpdate>::get(), cppu::UnoType<XRowUpdate>::get(),
ResultSet::getTypes()); ResultSet::getTypes());
pCollection = &collection;
} return s_collection.getTypes();
}
return pCollection->getTypes();
} }
......
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
#include <connectivity/dbconversion.hxx> #include <connectivity/dbconversion.hxx>
using osl::Mutex;
using osl::MutexGuard; using osl::MutexGuard;
...@@ -90,14 +89,8 @@ namespace pq_sdbc_driver ...@@ -90,14 +89,8 @@ namespace pq_sdbc_driver
{ {
static ::cppu::IPropertyArrayHelper & getPreparedStatementPropertyArrayHelper() static ::cppu::IPropertyArrayHelper & getPreparedStatementPropertyArrayHelper()
{ {
static ::cppu::IPropertyArrayHelper *pArrayHelper; static ::cppu::OPropertyArrayHelper arrayHelper(
if( ! pArrayHelper ) Sequence<Property>{
{
MutexGuard guard( Mutex::getGlobalMutex() );
if( ! pArrayHelper )
{
static Property aTable[] =
{
Property( Property(
"CursorName", 0, "CursorName", 0,
::cppu::UnoType<OUString>::get() , 0 ), ::cppu::UnoType<OUString>::get() , 0 ),
...@@ -124,13 +117,10 @@ static ::cppu::IPropertyArrayHelper & getPreparedStatementPropertyArrayHelper() ...@@ -124,13 +117,10 @@ static ::cppu::IPropertyArrayHelper & getPreparedStatementPropertyArrayHelper()
::cppu::UnoType<sal_Int32>::get() , 0 ), ::cppu::UnoType<sal_Int32>::get() , 0 ),
Property( Property(
"ResultSetType", 8, "ResultSetType", 8,
::cppu::UnoType<sal_Int32>::get() , 0 ) ::cppu::UnoType<sal_Int32>::get() , 0 )},
}; true );
static_assert( SAL_N_ELEMENTS(aTable) == PREPARED_STATEMENT_SIZE, "wrong number of elements" ); static ::cppu::IPropertyArrayHelper *pArrayHelper = &arrayHelper;
static ::cppu::OPropertyArrayHelper arrayHelper( aTable, PREPARED_STATEMENT_SIZE, true );
pArrayHelper = &arrayHelper;
}
}
return *pArrayHelper; return *pArrayHelper;
} }
...@@ -239,20 +229,12 @@ Any PreparedStatement::queryInterface( const Type & rType ) ...@@ -239,20 +229,12 @@ Any PreparedStatement::queryInterface( const Type & rType )
Sequence< Type > PreparedStatement::getTypes() Sequence< Type > PreparedStatement::getTypes()
{ {
static Sequence< Type > *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static Sequence< Type > collection( static Sequence< Type > collection(
::comphelper::concatSequences( ::comphelper::concatSequences(
OPropertySetHelper::getTypes(), OPropertySetHelper::getTypes(),
PreparedStatement_BASE::getTypes())); PreparedStatement_BASE::getTypes()));
pCollection = &collection;
} return collection;
}
return *pCollection;
} }
Sequence< sal_Int8> PreparedStatement::getImplementationId() Sequence< sal_Int8> PreparedStatement::getImplementationId()
......
...@@ -67,7 +67,6 @@ ...@@ -67,7 +67,6 @@
#include <string.h> #include <string.h>
using osl::Mutex;
using osl::MutexGuard; using osl::MutexGuard;
...@@ -108,14 +107,8 @@ namespace pq_sdbc_driver ...@@ -108,14 +107,8 @@ namespace pq_sdbc_driver
{ {
static ::cppu::IPropertyArrayHelper & getStatementPropertyArrayHelper() static ::cppu::IPropertyArrayHelper & getStatementPropertyArrayHelper()
{ {
static ::cppu::IPropertyArrayHelper *pArrayHelper; static ::cppu::OPropertyArrayHelper arrayHelper(
if( ! pArrayHelper ) Sequence<Property>{
{
MutexGuard guard( Mutex::getGlobalMutex() );
if( ! pArrayHelper )
{
static Property aTable[] =
{
Property( Property(
"CursorName", 0, "CursorName", 0,
::cppu::UnoType<OUString>::get() , 0 ), ::cppu::UnoType<OUString>::get() , 0 ),
...@@ -142,13 +135,11 @@ static ::cppu::IPropertyArrayHelper & getStatementPropertyArrayHelper() ...@@ -142,13 +135,11 @@ static ::cppu::IPropertyArrayHelper & getStatementPropertyArrayHelper()
::cppu::UnoType<sal_Int32>::get() , 0 ), ::cppu::UnoType<sal_Int32>::get() , 0 ),
Property( Property(
"ResultSetType", 8, "ResultSetType", 8,
::cppu::UnoType<sal_Int32>::get() , 0 ) ::cppu::UnoType<sal_Int32>::get() , 0 )},
}; true );
static_assert( SAL_N_ELEMENTS(aTable) == STATEMENT_SIZE, "wrong number of elements" );
static ::cppu::OPropertyArrayHelper arrayHelper( aTable, STATEMENT_SIZE, true ); static ::cppu::IPropertyArrayHelper *pArrayHelper = &arrayHelper;
pArrayHelper = &arrayHelper;
}
}
return *pArrayHelper; return *pArrayHelper;
} }
...@@ -194,20 +185,12 @@ Any Statement::queryInterface( const Type & rType ) ...@@ -194,20 +185,12 @@ Any Statement::queryInterface( const Type & rType )
Sequence< Type > Statement::getTypes() Sequence< Type > Statement::getTypes()
{ {
static Sequence< Type > *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static Sequence< Type > collection( static Sequence< Type > collection(
::comphelper::concatSequences( ::comphelper::concatSequences(
OPropertySetHelper::getTypes(), OPropertySetHelper::getTypes(),
Statement_BASE::getTypes())); Statement_BASE::getTypes()));
pCollection = &collection;
} return collection;
}
return *pCollection;
} }
Sequence< sal_Int8> Statement::getImplementationId() Sequence< sal_Int8> Statement::getImplementationId()
......
...@@ -147,20 +147,12 @@ css::uno::Any UpdateableResultSet::queryInterface( ...@@ -147,20 +147,12 @@ css::uno::Any UpdateableResultSet::queryInterface(
css::uno::Sequence< css::uno::Type > UpdateableResultSet::getTypes() css::uno::Sequence< css::uno::Type > UpdateableResultSet::getTypes()
{ {
static cppu::OTypeCollection *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection( static cppu::OTypeCollection collection(
cppu::UnoType<XResultSetUpdate>::get(), cppu::UnoType<XResultSetUpdate>::get(),
cppu::UnoType<XRowUpdate>::get(), cppu::UnoType<XRowUpdate>::get(),
SequenceResultSet::getTypes()); SequenceResultSet::getTypes());
pCollection = &collection;
} return collection.getTypes();
}
return pCollection->getTypes();
} }
......
...@@ -46,9 +46,6 @@ ...@@ -46,9 +46,6 @@
#include "pq_tools.hxx" #include "pq_tools.hxx"
#include "pq_statics.hxx" #include "pq_statics.hxx"
using osl::MutexGuard;
using osl::Mutex;
using com::sun::star::container::XNameAccess; using com::sun::star::container::XNameAccess;
using com::sun::star::uno::Reference; using com::sun::star::uno::Reference;
...@@ -103,19 +100,11 @@ Reference< XNameAccess > Index::getColumns( ) ...@@ -103,19 +100,11 @@ Reference< XNameAccess > Index::getColumns( )
Sequence<Type > Index::getTypes() Sequence<Type > Index::getTypes()
{ {
static cppu::OTypeCollection *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection( static cppu::OTypeCollection collection(
cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(), cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(),
ReflectionBase::getTypes()); ReflectionBase::getTypes());
pCollection = &collection;
} return collection.getTypes();
}
return pCollection->getTypes();
} }
Sequence< sal_Int8> Index::getImplementationId() Sequence< sal_Int8> Index::getImplementationId()
...@@ -175,19 +164,11 @@ Reference< XNameAccess > IndexDescriptor::getColumns( ) ...@@ -175,19 +164,11 @@ Reference< XNameAccess > IndexDescriptor::getColumns( )
Sequence<Type > IndexDescriptor::getTypes() Sequence<Type > IndexDescriptor::getTypes()
{ {
static cppu::OTypeCollection *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection( static cppu::OTypeCollection collection(
cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(), cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(),
ReflectionBase::getTypes()); ReflectionBase::getTypes());
pCollection = &collection;
} return collection.getTypes();
}
return pCollection->getTypes();
} }
Sequence< sal_Int8> IndexDescriptor::getImplementationId() Sequence< sal_Int8> IndexDescriptor::getImplementationId()
......
...@@ -46,9 +46,6 @@ ...@@ -46,9 +46,6 @@
#include "pq_tools.hxx" #include "pq_tools.hxx"
#include "pq_statics.hxx" #include "pq_statics.hxx"
using osl::MutexGuard;
using osl::Mutex;
using com::sun::star::container::XNameAccess; using com::sun::star::container::XNameAccess;
using com::sun::star::uno::Reference; using com::sun::star::uno::Reference;
...@@ -105,19 +102,11 @@ Reference< XNameAccess > Key::getColumns( ) ...@@ -105,19 +102,11 @@ Reference< XNameAccess > Key::getColumns( )
Sequence<Type > Key::getTypes() Sequence<Type > Key::getTypes()
{ {
static cppu::OTypeCollection *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection( static cppu::OTypeCollection collection(
cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(), cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(),
ReflectionBase::getTypes()); ReflectionBase::getTypes());
pCollection = &collection;
} return collection.getTypes();
}
return pCollection->getTypes();
} }
Sequence< sal_Int8> Key::getImplementationId() Sequence< sal_Int8> Key::getImplementationId()
...@@ -172,19 +161,11 @@ Reference< XNameAccess > KeyDescriptor::getColumns( ) ...@@ -172,19 +161,11 @@ Reference< XNameAccess > KeyDescriptor::getColumns( )
Sequence<Type > KeyDescriptor::getTypes() Sequence<Type > KeyDescriptor::getTypes()
{ {
static cppu::OTypeCollection *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection( static cppu::OTypeCollection collection(
cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(), cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(),
ReflectionBase::getTypes()); ReflectionBase::getTypes());
pCollection = &collection;
} return collection.getTypes();
}
return pCollection->getTypes();
} }
Sequence< sal_Int8> KeyDescriptor::getImplementationId() Sequence< sal_Int8> KeyDescriptor::getImplementationId()
......
...@@ -263,12 +263,6 @@ void Table::alterColumnByIndex( ...@@ -263,12 +263,6 @@ void Table::alterColumnByIndex(
Sequence<Type > Table::getTypes() Sequence<Type > Table::getTypes()
{ {
static cppu::OTypeCollection *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection( static cppu::OTypeCollection collection(
cppu::UnoType<css::sdbcx::XIndexesSupplier>::get(), cppu::UnoType<css::sdbcx::XIndexesSupplier>::get(),
cppu::UnoType<css::sdbcx::XKeysSupplier>::get(), cppu::UnoType<css::sdbcx::XKeysSupplier>::get(),
...@@ -276,10 +270,8 @@ Sequence<Type > Table::getTypes() ...@@ -276,10 +270,8 @@ Sequence<Type > Table::getTypes()
cppu::UnoType<css::sdbcx::XRename>::get(), cppu::UnoType<css::sdbcx::XRename>::get(),
cppu::UnoType<css::sdbcx::XAlterTable>::get(), cppu::UnoType<css::sdbcx::XAlterTable>::get(),
ReflectionBase::getTypes()); ReflectionBase::getTypes());
pCollection = &collection;
} return collection.getTypes();
}
return pCollection->getTypes();
} }
Sequence< sal_Int8> Table::getImplementationId() Sequence< sal_Int8> Table::getImplementationId()
...@@ -368,21 +360,13 @@ Reference< XIndexAccess > TableDescriptor::getKeys( ) ...@@ -368,21 +360,13 @@ Reference< XIndexAccess > TableDescriptor::getKeys( )
Sequence<Type > TableDescriptor::getTypes() Sequence<Type > TableDescriptor::getTypes()
{ {
static cppu::OTypeCollection *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection( static cppu::OTypeCollection collection(
cppu::UnoType<css::sdbcx::XIndexesSupplier>::get(), cppu::UnoType<css::sdbcx::XIndexesSupplier>::get(),
cppu::UnoType<css::sdbcx::XKeysSupplier>::get(), cppu::UnoType<css::sdbcx::XKeysSupplier>::get(),
cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(), cppu::UnoType<css::sdbcx::XColumnsSupplier>::get(),
ReflectionBase::getTypes()); ReflectionBase::getTypes());
pCollection = &collection;
} return collection.getTypes();
}
return pCollection->getTypes();
} }
Sequence< sal_Int8> TableDescriptor::getImplementationId() Sequence< sal_Int8> TableDescriptor::getImplementationId()
......
...@@ -46,9 +46,6 @@ ...@@ -46,9 +46,6 @@
#include "pq_tools.hxx" #include "pq_tools.hxx"
#include "pq_statics.hxx" #include "pq_statics.hxx"
using osl::MutexGuard;
using osl::Mutex;
using com::sun::star::uno::Reference; using com::sun::star::uno::Reference;
using com::sun::star::uno::Sequence; using com::sun::star::uno::Sequence;
using com::sun::star::uno::Any; using com::sun::star::uno::Any;
...@@ -86,19 +83,11 @@ Reference< XPropertySet > User::createDataDescriptor( ) ...@@ -86,19 +83,11 @@ Reference< XPropertySet > User::createDataDescriptor( )
Sequence<Type > User::getTypes() Sequence<Type > User::getTypes()
{ {
static cppu::OTypeCollection *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection( static cppu::OTypeCollection collection(
cppu::UnoType<css::sdbcx::XUser>::get(), cppu::UnoType<css::sdbcx::XUser>::get(),
ReflectionBase::getTypes()); ReflectionBase::getTypes());
pCollection = &collection;
} return collection.getTypes();
}
return pCollection->getTypes();
} }
Sequence< sal_Int8> User::getImplementationId() Sequence< sal_Int8> User::getImplementationId()
......
...@@ -48,7 +48,6 @@ ...@@ -48,7 +48,6 @@
#include "pq_tools.hxx" #include "pq_tools.hxx"
using osl::MutexGuard; using osl::MutexGuard;
using osl::Mutex;
using com::sun::star::uno::Reference; using com::sun::star::uno::Reference;
using com::sun::star::uno::Sequence; using com::sun::star::uno::Sequence;
...@@ -156,19 +155,11 @@ void View::rename( const OUString& newName ) ...@@ -156,19 +155,11 @@ void View::rename( const OUString& newName )
Sequence<Type > View::getTypes() Sequence<Type > View::getTypes()
{ {
static cppu::OTypeCollection *pCollection;
if( ! pCollection )
{
MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pCollection )
{
static cppu::OTypeCollection collection( static cppu::OTypeCollection collection(
cppu::UnoType<css::sdbcx::XRename>::get(), cppu::UnoType<css::sdbcx::XRename>::get(),
ReflectionBase::getTypes()); ReflectionBase::getTypes());
pCollection = &collection;
} return collection.getTypes();
}
return pCollection->getTypes();
} }
Sequence< sal_Int8> View::getImplementationId() Sequence< sal_Int8> View::getImplementationId()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment