Inkscape
Vector Graphics Editor
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
threading.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Author: Liam White
4 * Copyright (C) 2024 Authors
5 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
6 */
7
8#include "threading.h"
9
10#include <atomic>
11#include <mutex>
12
13#include "dispatch-pool.h"
14
15namespace Inkscape {
16
17namespace {
18
19std::mutex g_dispatch_lock;
20
21std::shared_ptr<dispatch_pool> g_dispatch_pool;
22std::atomic<int> g_num_dispatch_threads = 4;
23
24} // namespace
25
26void set_num_dispatch_threads(int num_dispatch_threads)
27{
28 g_num_dispatch_threads.store(num_dispatch_threads, std::memory_order_relaxed);
29}
30
31std::shared_ptr<dispatch_pool> get_global_dispatch_pool()
32{
33 int const num_threads = g_num_dispatch_threads.load(std::memory_order_relaxed);
34
35 std::scoped_lock lk(g_dispatch_lock);
36
37 if (g_dispatch_pool && num_threads == g_dispatch_pool->size()) {
38 return g_dispatch_pool;
39 }
40
41 g_dispatch_pool = std::make_shared<dispatch_pool>(num_threads);
42 return g_dispatch_pool;
43}
44
45} // namespace Inkscape
46
47/*
48 Local Variables:
49 mode:c++
50 c-file-style:"stroustrup"
51 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
52 indent-tabs-mode:nil
53 fill-column:99
54 End:
55*/
56// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Helper class to stream background task notifications as a series of messages.
std::shared_ptr< dispatch_pool > get_global_dispatch_pool()
Definition threading.cpp:31
void set_num_dispatch_threads(int num_dispatch_threads)
Definition threading.cpp:26