Send various state changes to LOK
[LibreOffice.git] / salhelper / source / thread.cxx
blob1a06bf3b235a443b26684e953354ef1b55fa8fdb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <sal/config.h>
12 #include <stdexcept>
13 #include <string>
15 #include <sal/log.hxx>
16 #include <salhelper/thread.hxx>
18 salhelper::Thread::Thread(char const * name): name_(name) {}
20 void salhelper::Thread::launch() {
21 SAL_INFO("salhelper.thread", "launch " << name_);
22 // Assumption is that osl::Thread::create returns normally with a true
23 // return value iff it causes osl::Thread::run to start executing:
24 acquire();
25 try {
26 if (!create()) {
27 throw std::runtime_error("osl::Thread::create failed");
29 } catch (...) {
30 release();
31 throw;
35 salhelper::Thread::~Thread() {}
37 void salhelper::Thread::run() {
38 try {
39 setName(name_);
40 execute();
41 } catch (...) {
42 // Work around the problem that onTerminated is not called if run throws
43 // an exception:
44 onTerminated();
45 throw;
49 void salhelper::Thread::onTerminated() { release(); }
51 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */