-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display: move thread operations to new file
- Loading branch information
Showing
11 changed files
with
110 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Author: Liam White | ||
* Copyright (C) 2024 Authors | ||
* Released under GNU GPL v2+, read the file 'COPYING' for more information. | ||
*/ | ||
|
||
#include "threading.h" | ||
|
||
#include <atomic> | ||
#include <mutex> | ||
|
||
#include "dispatch-pool.h" | ||
|
||
namespace Inkscape { | ||
|
||
namespace { | ||
|
||
std::mutex g_dispatch_lock; | ||
|
||
std::shared_ptr<dispatch_pool> g_dispatch_pool; | ||
std::atomic<int> g_num_dispatch_threads = 4; | ||
|
||
} // namespace | ||
|
||
void set_num_dispatch_threads(int num_dispatch_threads) | ||
{ | ||
g_num_dispatch_threads.store(num_dispatch_threads, std::memory_order_relaxed); | ||
} | ||
|
||
std::shared_ptr<dispatch_pool> get_global_dispatch_pool() | ||
{ | ||
int const num_threads = g_num_dispatch_threads.load(std::memory_order_relaxed); | ||
|
||
std::scoped_lock lk(g_dispatch_lock); | ||
|
||
if (g_dispatch_pool && num_threads == g_dispatch_pool->size()) { | ||
return g_dispatch_pool; | ||
} | ||
|
||
g_dispatch_pool = std::make_shared<dispatch_pool>(num_threads); | ||
return g_dispatch_pool; | ||
} | ||
|
||
} // namespace Inkscape | ||
|
||
/* | ||
Local Variables: | ||
mode:c++ | ||
c-file-style:"stroustrup" | ||
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) | ||
indent-tabs-mode:nil | ||
fill-column:99 | ||
End: | ||
*/ | ||
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Author: Liam White | ||
* Copyright (C) 2024 Authors | ||
* Released under GNU GPL v2+, read the file 'COPYING' for more information. | ||
*/ | ||
|
||
#ifndef INKSCAPE_DISPLAY_THREADING_H | ||
#define INKSCAPE_DISPLAY_THREADING_H | ||
|
||
#include <memory> | ||
|
||
namespace Inkscape { | ||
|
||
class dispatch_pool; | ||
|
||
// Atomic accessor to global variable governing number of dispatch_pool threads. | ||
void set_num_dispatch_threads(int num_dispatch_threads); | ||
|
||
std::shared_ptr<dispatch_pool> get_global_dispatch_pool(); | ||
|
||
} // namespace Inkscape | ||
|
||
#endif // INKSCAPE_DISPLAY_THREADING_H | ||
|
||
/* | ||
Local Variables: | ||
mode:c++ | ||
c-file-style:"stroustrup" | ||
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) | ||
indent-tabs-mode:nil | ||
fill-column:99 | ||
End: | ||
*/ | ||
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |