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

ossia / score / 31045564894

05 Aug 2026 08:45PM UTC coverage: 15.264%. Remained the same
31045564894

Pull #1975

github

web-flow
Merge f9afe3ef4 into bc36bcfd2
Pull Request #1975: audio: add a native ASIO backend on Windows

1 of 15 new or added lines in 3 files covered. (6.67%)

3 existing lines in 2 files now uncovered.

30466 of 199594 relevant lines covered (15.26%)

1077.96 hits per line

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

82.93
/src/lib/score/tools/ThreadPool.cpp
1
#include <score/application/ApplicationServices.hpp>
2
#include <score/tools/ThreadPool.hpp>
3

4
#include <thread>
5
#if __has_include(<sys/resource.h>)
6
#include <sys/resource.h>
7
#endif
8
#include <ossia/detail/thread.hpp>
9

10
namespace score
11
{
12
ThreadPool::ThreadPool() { }
1 ✔
13

14
ThreadPool::~ThreadPool()
1 ✔
15
{
16
  if(m_threads)
1 ✔
17
  {
18
    for(int i = 0; i < m_numThreads; i++)
×
19
    {
20
      m_threads[i].quit();
×
21
    }
×
22
    for(int i = 0; i < m_numThreads; i++)
×
23
    {
24
      m_threads[i].wait();
×
25
    }
×
26

27
    m_threads.reset();
×
28
  }
×
29
}
1 ✔
30

31
ThreadPool& ThreadPool::instance()
2 ✔
32
{
33
  static std::once_flag init{};
34
  std::call_once(init, [] { score::AppServices().threadpool.emplace(); });
3 ✔
35
  return *score::AppServices().threadpool;
2 ✔
36
}
37

38
QThread* ThreadPool::acquireThread()
1 ✔
39
{
40
  if(!m_threads)
1 ✔
41
  {
42
    m_numThreads = std::thread::hardware_concurrency();
1 ✔
43
    if(m_numThreads > 2)
1 ✔
44
      m_numThreads = m_numThreads / 2;
1 ✔
45
    if(m_numThreads < 2)
1 ✔
46
      m_numThreads = 2;
×
47
    m_threads = std::make_unique<QThread[]>(m_numThreads);
1 ✔
48

49
    for(int i = 0; i < m_numThreads; i++)
7 ✔
50
    {
51
#if __has_include(<sys/resource.h>)
52
      ::rlimit lim{0, 0};
6 ✔
53
      getrlimit(RLIMIT_STACK, &lim);
6 ✔
54

55
      if(lim.rlim_cur > m_threads[i].stackSize())
6 ✔
56
        m_threads[i].setStackSize(lim.rlim_cur);
6 ✔
57
#endif
58
      m_threads[i].setObjectName(QString("ossia uitask %1").arg(i));
6 ✔
59
      m_threads[i].start();
6 ✔
60
      m_threads[i].setPriority(QThread::Priority::HighPriority);
6 ✔
61
    }
6 ✔
62
    m_currentThread = 0;
1 ✔
63
  }
1 ✔
64

65
  QThread& t = m_threads[m_currentThread];
1 ✔
66
  m_currentThread++;
1 ✔
67
  m_currentThread = m_currentThread % m_numThreads;
1 ✔
68
  m_inFlight++;
1 ✔
69
  return &t;
1 ✔
70
}
×
71

72
void ThreadPool::releaseThread()
1 ✔
73
{
74
  m_inFlight--;
1 ✔
75

76
  if(m_inFlight == 0)
1 ✔
77
  {
78
    for(int i = 0; i < m_numThreads; i++)
7 ✔
79
    {
80
      m_threads[i].quit();
6 ✔
81
    }
6 ✔
82
    for(int i = 0; i < m_numThreads; i++)
7 ✔
83
    {
84
      m_threads[i].wait();
6 ✔
85
    }
6 ✔
86

87
    m_threads.reset();
1 ✔
88
  }
1 ✔
89
}
1 ✔
90

91
TaskPool::TaskPool()
15 ✔
92
{
93
  m_running = true;
15 ✔
94
  int max_n = std::thread::hardware_concurrency();
15 ✔
95
  if(max_n > 8)
15 ✔
96
    max_n = 4;
15 ✔
UNCOV
97
  else if(max_n >= 4)
×
UNCOV
98
    max_n = 2;
×
99
  else
100
    max_n = 1;
×
101

102
  int i = 0;
15 ✔
103
  for(auto& t : m_threads)
60 ✔
104
  {
105
    t = std::thread{[this, i = i++] {
120 ✔
106
      ossia::set_thread_name("ossia task " + std::to_string(i));
60 ✔
107
      task t{};
60 ✔
108
      while(m_running)
174 ✔
109
      {
110
        if(m_queue.wait_dequeue_timed(t, 100000))
114 ✔
111
        {
112
          t();
22 ✔
113
        }
22 ✔
114
      }
115
    }};
60 ✔
116
    if(i >= max_n)
60 ✔
117
      break;
15 ✔
118
  }
119
}
×
120

121
TaskPool::~TaskPool()
15 ✔
122
{
123
  m_running = false;
15 ✔
124
  for(auto& t : m_threads)
75 ✔
125
  {
126
    if(t.joinable())
60 ✔
127
      t.join();
60 ✔
128
  }
129
}
15 ✔
130

131
TaskPool& TaskPool::instance()
26 ✔
132
{
133
  static std::once_flag init{};
134
  std::call_once(init, [] { score::AppServices().taskpool.emplace(); });
41 ✔
135
  return *score::AppServices().taskpool;
26 ✔
136
}
137

138
}
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