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/source/thread.cxx | |
parent | 5b98bb47139588d2b8ca31060f9d48377a4fbfdc (diff) |
Moved dp_gui::Thread to salhelper::Thread, so that all code can use it
...also improved the code somewhat.
Diffstat (limited to 'salhelper/source/thread.cxx')
-rw-r--r-- | salhelper/source/thread.cxx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/salhelper/source/thread.cxx b/salhelper/source/thread.cxx new file mode 100644 index 000000000000..bf7c1f196aa8 --- /dev/null +++ b/salhelper/source/thread.cxx @@ -0,0 +1,66 @@ +/* -*- 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: */ |