Debian Codegraph @

src/librssguard/miscellaneous/thread.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/miscellaneous/thread.cpp`/
2
3 #include "miscellaneous/thread.h"cxx . . $ `<file>/src/librssguard/miscellaneous/thread.h`/
4
5 #include "definitions/definitions.h"cxx . . $ `<file>/src/librssguard/definitions/definitions.h`/
6
7 #include <QThread>
8
9 #if defined(Q_OS_LINUXcxx . . $ `/usr/include/x86_64-linux-gnu/qt6/QtCore/qsystemdetection.h:100:11`!)
10 #include <sched.h>
11 #include <sys/resource.h>
12 #include <unistd.h>
13 #endif
14
15 // Returns the thread ID of the caller.
16 qlonglongcxx . . $ qlonglong# getThreadIDcxx . . $ getThreadID(a5d9f2bf8849668d).() {
17 #if defined(Q_OS_LINUXcxx . . $ `/usr/include/x86_64-linux-gnu/qt6/QtCore/qsystemdetection.h:100:11`!)
18 return qlonglongcxx . . $ qlonglong#(gettid());
19 #else
20 return qlonglong(QThread::currentThreadId());
21 #endif
22 }
23
24 #if defined(Q_OS_LINUXcxx . . $ `/usr/include/x86_64-linux-gnu/qt6/QtCore/qsystemdetection.h:100:11`!)
25 // On Linux QThread priorities do nothing with the default scheduler SCHED_OTHER.
26 //
27 // Set the nice value manually in this case until Qt supports nice values.
28 void setThreadPrioritycxx . . $ setThreadPriority(ec92b42880e59c63).(Prioritycxx . . $ Priority# prio) {
29 int current_policy = sched_getscheduler(0);
30
31 if (current_policy != -1) {
32 // If the current scheduling policy is neither of these the QThread priority should be working.
33 if (current_policy != SCHED_BATCHcxx . . $ `<external>/4872883757279652994/sched.h:33:10`! && current_policy != SCHED_OTHERcxx . . $ `<external>/4872883757279652994/sched.h:28:9`!) {
34 return;
35 }
36
37 // Set the scheduler to SCHED_BATCH if needed, indicating that this process is non-interactive.
38 if (current_policy == SCHED_OTHERcxx . . $ `<external>/4872883757279652994/sched.h:28:9`!) {
39 struct sched_paramcxx . . $ sched_param# p = {0};
40
41 if (sched_setscheduler(0, SCHED_BATCHcxx . . $ `<external>/4872883757279652994/sched.h:33:10`!, &p) != 0) {
42 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Setting the scheduler to SCHED_BATCH for thread" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(getThreadID())
43 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "failed with error" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
44 // We can still try to set the nice value.
45 }
46 }
47
48 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; // Clear errno since -1 is a legitimate return value.
49
50 int current_priority = getpriority(PRIO_PROCESScxx . . $ `<external>/1890803886155400780/resource.h:190:9`!, 0);
51
52 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != 0) {
53 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Getting the priority for thread" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(getThreadID()) <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "failed with error"
54 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
55 }
56 else {
57 if (current_priority != prio) {
58 setpriority(PRIO_PROCESScxx . . $ `<external>/1890803886155400780/resource.h:190:9`!, 0, prio);
59
60 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != 0) {
61 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Setting the priority for thread" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(getThreadID()) <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "failed with error"
62 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
63 }
64 }
65 }
66 }
67 else {
68 qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Getting the priority for thread" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACEcxx . . $ `src/librssguard/definitions/definitions.h:432:9`!(getThreadID()) <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "failed with error"
69 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
70 }
71 }
72 #endif