• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

graphia-app / graphia / 42417955599

07 Nov 2026 08:33PM UTC coverage: 71.51% (+0.07%) from 71.441%
42417955599

push

github

timangus
CLAUDE: Suppress cppcheck's duplInheritedMember check and drop NodePositions' second mutex

11809 of 18066 branches covered (65.37%)

Branch coverage included in aggregate %.

29972 of 40361 relevant lines covered (74.26%)

591425.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.55
/source/shared/utils/threadpool.cpp
1
/* Copyright © 2013-2025 Tim Angus
2
 * Copyright © 2013-2025 Tom Freeman
3
 *
4
 * This file is part of Graphia.
5
 *
6
 * Graphia is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Graphia is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with Graphia.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#include "threadpool.h"
21

22
#include "shared/utils/thread.h"
23

24
using namespace Qt::Literals::StringLiterals;
25

26
ThreadPool::ThreadPool(const QString& threadNamePrefix, unsigned int numThreads)
27
{
1,534 ✔
28
#ifdef Q_OS_WASM
29
    // On Emscripten thread support is implemented by providing a fixed pthread pool
30
    // which we size relative to hardware concurrency (via navigator.hardwareConcurrency)
31
    // Exhausting this pool potentially results in deadlock, so for /our/ thread pool,
32
    // we only occupy half of them, hopefully reducing the chance of this occuring
33
    numThreads = std::min(numThreads, std::thread::hardware_concurrency() / 2);
34
#endif
35

36
    for(unsigned int i = 0U; i < numThreads; i++)
7,662 ✔
37
    {
6,128 ✔
38
        auto threadName = u"%1%2"_s.arg(threadNamePrefix).arg(i + 1);
6,128 ✔
39

40
        _threads.emplace_back([threadName, this]
6,128 ✔
41
        {
6,128 ✔
42
            std::unique_lock<std::mutex> lock(_mutex);
6,126 ✔
43

44
            while(!_stop)
766,106 ✔
45
            {
765,133 ✔
46
                // cppcheck-suppress knownConditionTrueFalse
47
                while(_tasks.empty() && !_stop)
1,491,886 ✔
48
                {
726,753 ✔
49
                    u::setCurrentThreadName(u"%1 (idle)"_s.arg(threadName));
726,753 ✔
50

51
                    // Block until a new task is queued
52
                    _waitForNewTask.wait(lock);
726,753 ✔
53
                }
726,753 ✔
54

55
                // cppcheck-suppress knownConditionTrueFalse
56
                if(_stop)
765,133 ✔
57
                    break;
5,153 ✔
58

59
                auto task = std::move(_tasks.front());
759,980 ✔
60
                _tasks.pop();
759,980 ✔
61
                lock.unlock();
759,980 ✔
62

63
                u::setCurrentThreadName(u"%1 (busy)"_s.arg(threadName));
759,980 ✔
64
                task();
759,980 ✔
65

66
                lock.lock();
759,980 ✔
67
            }
759,980 ✔
68
        });
6,126 ✔
69
    }
6,128 ✔
70
}
1,534 ✔
71

72
ThreadPool::~ThreadPool()
73
{
1,534 ✔
74
    // Cancel all pending tasks
75
    std::unique_lock<std::mutex> lock(_mutex);
1,534 ✔
76
    _stop = true;
1,534 ✔
77
    while(!_tasks.empty())
1,534 !
78
        _tasks.pop();
×
79
    lock.unlock();
1,534 ✔
80

81
    // Tell all idle threads to unblock
82
    _waitForNewTask.notify_all();
1,534 ✔
83

84
    // Wait for all threads to finish
85
    for(auto& thread : _threads)
1,534 ✔
86
    {
6,128 ✔
87
        if(thread.joinable())
6,128 !
88
            thread.join();
6,128 ✔
89
    }
6,128 ✔
90
}
1,534 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc