LibreOffice Module salhelper (master) 1
thread.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#include <sal/config.h>
11
12#include <stdexcept>
13#include <string>
14
16#include <sal/log.hxx>
17#include <salhelper/thread.hxx>
18
19salhelper::Thread::Thread(char const * name): name_(name) {}
20
22 SAL_INFO("salhelper.thread", "launch " << name_);
23 // Assumption is that osl::Thread::create returns normally with a true
24 // return value iff it causes osl::Thread::run to start executing:
25 acquire();
26 comphelper::ScopeGuard g([this] { release(); });
27 if (!create()) {
28 throw std::runtime_error("osl::Thread::create failed");
29 }
30 g.dismiss();
31}
32
34
36 // Work around the problem that onTerminated is not called if run throws an exception:
37 comphelper::ScopeGuard g([this] { onTerminated(); });
38 setName(name_);
39 execute();
40 g.dismiss();
41}
42
44
45/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Thread(char const *name)
Definition: thread.cxx:19
virtual void SAL_CALL run() SAL_OVERRIDE
Definition: thread.cxx:35
virtual void SAL_CALL onTerminated() SAL_OVERRIDE
Definition: thread.cxx:43
void launch()
Launch the thread.
Definition: thread.cxx:21
virtual ~Thread() SAL_OVERRIDE
Definition: thread.cxx:33
const char * name
#define SAL_INFO(area, stream)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
OUString name_