diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-02-23 10:25:39 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-02-23 10:47:35 +0100 |
commit | a342b3e3b0c4c2baa40442ab4580f5091c6231d1 (patch) | |
tree | d2498fe7a445ddabd70ee5a8bf778e719c839116 /salhelper/inc | |
parent | log-areas clean up (diff) | |
download | core-a342b3e3b0c4c2baa40442ab4580f5091c6231d1.tar.gz core-a342b3e3b0c4c2baa40442ab4580f5091c6231d1.zip |
Moved dp_gui::Thread to salhelper::Thread, so that all code can use it
...also improved the code somewhat.
Diffstat (limited to 'salhelper/inc')
-rw-r--r-- | salhelper/inc/salhelper/thread.hxx | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/salhelper/inc/salhelper/thread.hxx b/salhelper/inc/salhelper/thread.hxx new file mode 100644 index 000000000000..619ac449ef17 --- /dev/null +++ b/salhelper/inc/salhelper/thread.hxx @@ -0,0 +1,104 @@ +/* -*- 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: */ |