Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/salhelper/source/thread.cxx
Line
Count
Source
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
15
#include <comphelper/scopeguard.hxx>
16
#include <sal/log.hxx>
17
#include <salhelper/thread.hxx>
18
19
31.1k
salhelper::Thread::Thread(char const * name): name_(name) {}
20
21
31.1k
void salhelper::Thread::launch() {
22
31.1k
    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
31.1k
    acquire();
26
31.1k
    comphelper::ScopeGuard g([this] { release(); });
27
31.1k
    if (!create()) {
28
0
        throw std::runtime_error("osl::Thread::create failed");
29
0
    }
30
31.1k
    g.dismiss();
31
31.1k
}
32
33
31.1k
salhelper::Thread::~Thread() {}
34
35
31.1k
void salhelper::Thread::run() {
36
    // Work around the problem that onTerminated is not called if run throws an exception:
37
31.1k
    comphelper::ScopeGuard g([this] { onTerminated(); });
38
31.1k
    setName(name_);
39
31.1k
    execute();
40
31.1k
    g.dismiss();
41
31.1k
}
42
43
31.0k
void salhelper::Thread::onTerminated() { release(); }
44
45
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */