Kaydet (Commit) a342b3e3 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Moved dp_gui::Thread to salhelper::Thread, so that all code can use it

...also improved the code somewhat.
üst 5b98bb47
......@@ -79,7 +79,6 @@ $(eval $(call gb_Library_add_exception_objects,deploymentgui,\
desktop/source/deployment/gui/dp_gui_extlistbox \
desktop/source/deployment/gui/dp_gui_service \
desktop/source/deployment/gui/dp_gui_theextmgr \
desktop/source/deployment/gui/dp_gui_thread \
desktop/source/deployment/gui/dp_gui_updatedialog \
desktop/source/deployment/gui/dp_gui_updateinstalldialog \
desktop/source/deployment/gui/license_dialog \
......
......@@ -71,6 +71,7 @@
#include "rtl/ustring.h"
#include "rtl/ustring.hxx"
#include "sal/types.h"
#include "salhelper/thread.hxx"
#include "ucbhelper/content.hxx"
#include "cppuhelper/exc_hlp.hxx"
#include "cppuhelper/implbase3.hxx"
......@@ -79,7 +80,6 @@
#include "toolkit/helper/vclunohelper.hxx"
#include "dp_gui.h"
#include "dp_gui_thread.hxx"
#include "dp_gui_extensioncmdqueue.hxx"
#include "dp_gui_dependencydialog.hxx"
#include "dp_gui_dialog2.hxx"
......@@ -230,7 +230,7 @@ struct ExtensionCmd
typedef ::boost::shared_ptr< ExtensionCmd > TExtensionCmd;
//------------------------------------------------------------------------------
class ExtensionCmdQueue::Thread: public dp_gui::Thread
class ExtensionCmdQueue::Thread: public salhelper::Thread
{
public:
Thread( DialogHelper *pDialogHelper,
......@@ -249,13 +249,9 @@ public:
bool isBusy();
private:
Thread( Thread & ); // not defined
void operator =( Thread & ); // not defined
virtual ~Thread();
virtual void execute();
virtual void SAL_CALL onTerminated();
void _insert(const TExtensionCmd& rExtCmd);
......@@ -290,7 +286,6 @@ private:
osl::Condition m_wakeup;
osl::Mutex m_mutex;
Input m_eInput;
bool m_bTerminated;
bool m_bStopped;
bool m_bWorking;
};
......@@ -624,6 +619,7 @@ void ProgressCmdEnv::pop()
ExtensionCmdQueue::Thread::Thread( DialogHelper *pDialogHelper,
TheExtensionManager *pManager,
const uno::Reference< uno::XComponentContext > & rContext ) :
salhelper::Thread( "dp_gui_extensioncmdqueue" ),
m_xContext( rContext ),
m_pDialogHelper( pDialogHelper ),
m_pManager( pManager ),
......@@ -634,7 +630,6 @@ ExtensionCmdQueue::Thread::Thread( DialogHelper *pDialogHelper,
m_sDefaultCmd( DialogHelper::getResourceString( RID_STR_ADD_PACKAGES ) ),
m_sAcceptLicense( DialogHelper::getResourceString( RID_STR_ACCEPT_LICENSE ) ),
m_eInput( NONE ),
m_bTerminated( false ),
m_bStopped( false ),
m_bWorking( false )
{
......@@ -1078,13 +1073,6 @@ void ExtensionCmdQueue::Thread::_acceptLicense( ::rtl::Reference< ProgressCmdEnv
{}
}
//------------------------------------------------------------------------------
void ExtensionCmdQueue::Thread::onTerminated()
{
::osl::MutexGuard g(m_mutex);
m_bTerminated = true;
}
void ExtensionCmdQueue::Thread::_insert(const TExtensionCmd& rExtCmd)
{
::osl::MutexGuard aGuard( m_mutex );
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "sal/config.h"
#include <cstddef>
#include <new>
#include "osl/thread.hxx"
#include "salhelper/simplereferenceobject.hxx"
#include "dp_gui_thread.hxx"
using dp_gui::Thread;
Thread::Thread() {}
void Thread::launch() {
// Assumption is that osl::Thread::create returns normally iff it causes
// osl::Thread::run to start executing:
acquire();
try {
create();
} catch (...) {
release();
throw;
}
}
void * Thread::operator new(std::size_t size)
throw (std::bad_alloc)
{
return SimpleReferenceObject::operator new(size);
}
void Thread::operator delete(void * p) throw () {
SimpleReferenceObject::operator delete(p);
}
Thread::~Thread() {}
void Thread::run() {
try {
execute();
} catch (...) {
// Work around the problem that onTerminated is not called if run throws
// an exception:
onTerminated();
throw;
}
}
void Thread::onTerminated() {
release();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_THREAD_HXX
#define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_THREAD_HXX
#include "sal/config.h"
#include <cstddef>
#include <new>
#include "osl/thread.hxx"
#include "sal/types.h"
#include "salhelper/simplereferenceobject.hxx"
/// @HTML
namespace dp_gui {
/**
A safe encapsulation of <code>osl::Thread</code>.
*/
class Thread: public salhelper::SimpleReferenceObject, private osl::Thread {
public:
Thread();
/**
Launch the thread.
<p>This function must be called at most once.</p>
*/
void launch();
using osl::Thread::join;
static void * operator new(std::size_t size) throw (std::bad_alloc);
static void operator delete(void * p) throw ();
protected:
virtual ~Thread();
/**
The main function executed by the thread.
<p>Any exceptions terminate the thread and are effectively ignored.</p>
*/
virtual void execute() = 0;
private:
Thread(Thread &); // not defined
void operator =(Thread &); // not defined
virtual void SAL_CALL run();
virtual void SAL_CALL onTerminated();
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -89,6 +89,7 @@
#include "rtl/ustring.h"
#include "rtl/ustring.hxx"
#include "sal/types.h"
#include "salhelper/thread.hxx"
#include "svtools/svlbitm.hxx"
#include "svtools/svlbox.hxx"
#include <svtools/controldims.hrc>
......@@ -117,7 +118,6 @@
#include "dp_gui.h"
#include "dp_gui.hrc"
#include "dp_gui_thread.hxx"
#include "dp_gui_updatedata.hxx"
#include "dp_gui_updatedialog.hxx"
#include "dp_gui_shared.hxx"
......@@ -210,7 +210,7 @@ UpdateDialog::Index::Index( Kind theKind, sal_uInt16 nID, sal_uInt16 nIndex, con
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
class UpdateDialog::Thread: public dp_gui::Thread {
class UpdateDialog::Thread: public salhelper::Thread {
public:
Thread(
uno::Reference< uno::XComponentContext > const & context,
......@@ -220,9 +220,6 @@ public:
void stop();
private:
Thread(UpdateDialog::Thread &); // not defined
void operator =(UpdateDialog::Thread &); // not defined
virtual ~Thread();
virtual void execute();
......@@ -264,6 +261,7 @@ UpdateDialog::Thread::Thread(
uno::Reference< uno::XComponentContext > const & context,
UpdateDialog & dialog,
const std::vector< uno::Reference< deployment::XPackage > > &vExtensionList):
salhelper::Thread("dp_gui_updatedialog"),
m_context(context),
m_dialog(dialog),
m_vExtensionList(vExtensionList),
......
......@@ -73,12 +73,12 @@
#include "dp_ucb.h"
#include "dp_misc.h"
#include "dp_version.hxx"
#include "dp_gui_thread.hxx"
#include "dp_gui_extensioncmdqueue.hxx"
#include "ucbhelper/content.hxx"
#include "osl/mutex.hxx"
#include "osl/mutex.hxx"
#include "rtl/ref.hxx"
#include "salhelper/thread.hxx"
#include "com/sun/star/uno/Sequence.h"
#include "comphelper/anytostring.hxx"
#include "toolkit/helper/vclunohelper.hxx"
......@@ -95,7 +95,7 @@ using ::rtl::OUString;
namespace dp_gui {
class UpdateInstallDialog::Thread: public dp_gui::Thread {
class UpdateInstallDialog::Thread: public salhelper::Thread {
friend class UpdateCommandEnv;
public:
Thread(cssu::Reference< cssu::XComponentContext > ctx,
......@@ -106,9 +106,6 @@ public:
private:
Thread(Thread &); // not defined
void operator =(Thread &); // not defined
virtual ~Thread();
virtual void execute();
......@@ -175,6 +172,7 @@ UpdateInstallDialog::Thread::Thread(
cssu::Reference< cssu::XComponentContext> xCtx,
UpdateInstallDialog & dialog,
std::vector< dp_gui::UpdateData > & aVecUpdateData):
salhelper::Thread("dp_gui_updateinstalldialog"),
m_dialog(dialog),
m_xComponentContext(xCtx),
m_aVecUpdateData(aVecUpdateData),
......
......@@ -49,6 +49,13 @@ namespace osl
*/
extern "C" inline void SAL_CALL threadFunc( void* param);
/**
A thread abstraction.
@deprecated use ::salhelper::Thread instead. Only the static member
functions ::osl::Thread::getCurrentIdentifier, ::osl::Thread::wait, and
::osl::Thread::yield are not deprecated.
*/
class Thread
{
Thread( const Thread& );
......
......@@ -35,6 +35,7 @@ certain functionality.
@section URE
@li @c rtl.string - ::rtl::OString, ::rtl::OUString, and related functionality
@li @c salhelper.thread - ::salhelper::Thread class
@section VCL
......
......@@ -42,6 +42,7 @@ $(eval $(call gb_Library_add_exception_objects,salhelper,\
salhelper/source/condition \
salhelper/source/dynload \
salhelper/source/simplereferenceobject \
salhelper/source/thread \
salhelper/source/timer \
))
......
......@@ -38,6 +38,7 @@ $(eval $(call gb_Package_add_file,salhelper_inc,inc/salhelper/queue.hxx,queue.hx
$(eval $(call gb_Package_add_file,salhelper_inc,inc/salhelper/refobj.hxx,refobj.hxx))
$(eval $(call gb_Package_add_file,salhelper_inc,inc/salhelper/simplereferenceobject.hxx,simplereferenceobject.hxx))
$(eval $(call gb_Package_add_file,salhelper_inc,inc/salhelper/singletonref.hxx,singletonref.hxx))
$(eval $(call gb_Package_add_file,salhelper_inc,inc/salhelper/thread.hxx,thread.hxx))
$(eval $(call gb_Package_add_file,salhelper_inc,inc/salhelper/timer.hxx,timer.hxx))
# vim: set noet sw=4 ts=4:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
* (initial developer) ]
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#ifndef INCLUDED_SALHELPER_THREAD_HXX
#define INCLUDED_SALHELPER_THREAD_HXX
#include "sal/config.h"
#include <cstddef>
#include "osl/thread.hxx"
#include "sal/types.h"
#include "salhelper/salhelperdllapi.h"
#include "salhelper/simplereferenceobject.hxx"
namespace salhelper {
/**
A safe encapsulation of ::osl::Thread.
@since LibreOffice 3.6
*/
class SALHELPER_DLLPUBLIC Thread:
public salhelper::SimpleReferenceObject, private osl::Thread
{
public:
/**
@param name the thread name, see ::osl_setThreadName; must be a non-null
null terminated string
*/
Thread(char const * name);
/**
Launch the thread.
This function must be called at most once.
Each call of this function should eventually be followed by a call to
::osl::Thread::join before exit(3), to ensure the thread is no longer
relying on any infrastructure while that infrastructure is being shut
down in atexit handlers.
*/
void launch();
using osl::Thread::getIdentifier;
using osl::Thread::join;
using osl::Thread::schedule;
using osl::Thread::terminate;
static inline void * operator new(std::size_t size)
{ return SimpleReferenceObject::operator new(size); }
static inline void operator delete(void * pointer)
{ SimpleReferenceObject::operator delete(pointer); }
protected:
virtual ~Thread();
/**
The main function executed by the thread.
Any uncaught exceptions lead to std::terminate.
*/
virtual void execute() = 0;
private:
virtual void SAL_CALL run();
virtual void SAL_CALL onTerminated();
char const * name_;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -96,6 +96,24 @@ UDK_3.1 {
} UDK_3_0_0;
LIBO_UDK_3.6 { # symbols available in >= LibO 3.6
global:
_ZN9salhelper6Thread12onTerminatedEv;
# salhelper::Thread::onTerminated()
_ZN9salhelper6Thread3runEv; # salhelper::Thread::run()
_ZN9salhelper6Thread6launchEv; # salhelper::Thread::launch()
_ZN9salhelper6ThreadC1EPKc; # salhelper::Thread::Thread(char const*)
_ZN9salhelper6ThreadC2EPKc; # salhelper::Thread::Thread(char const*)
_ZN9salhelper6ThreadD0Ev; # salhelper::Thread::~Thread()
_ZN9salhelper6ThreadD1Ev; # salhelper::Thread::~Thread()
_ZN9salhelper6ThreadD2Ev; # salhelper::Thread::~Thread()
_ZTVN9salhelper6ThreadE; # vtable for salhelper::Thread
_ZThn16_N9salhelper6Thread12onTerminatedEv;
# non-virtual thunk to salhelper::Thread::onTerminated()
_ZThn16_N9salhelper6Thread3runEv;
# non-virtual thunk to salhelper::Thread::run()
} UDK_3.1;
# Unique libstdc++ symbols:
GLIBCXX_3.4 {
global:
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
* (initial developer) ]
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#include "sal/config.h"
#include "sal/log.hxx"
#include "salhelper/thread.hxx"
salhelper::Thread::Thread(char const * name): name_(name) {}
void salhelper::Thread::launch() {
SAL_INFO("salhelper.thread", "launch " << name_);
// Assumption is that osl::Thread::create returns normally iff it causes
// osl::Thread::run to start executing:
acquire();
try {
create();
} catch (...) {
release();
throw;
}
}
salhelper::Thread::~Thread() {}
void salhelper::Thread::run() {
try {
setName(name_);
execute();
} catch (...) {
// Work around the problem that onTerminated is not called if run throws
// an exception:
onTerminated();
throw;
}
}
void salhelper::Thread::onTerminated() { release(); }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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