FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppcheck/cli/threadexecutor.cpp at 2.9.x · cppcheck-opensource/cppcheck · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
cppcheck-opensource
/
cppcheck
Public
Notifications
You must be signed in to change notification settings
Fork
1.6k
Star
6.7k
Code
Pull requests
200
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
cppcheck
/
cli
/
threadexecutor.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
197 lines (161 loc) · 6.58 KB
Breadcrumbs
cppcheck
/
cli
/
threadexecutor.cpp
Copy path
File metadata and controls
197 lines (161 loc) · 6.58 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2022 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#
include
"
threadexecutor.h
"
#
include
"
color.h
"
#
include
"
cppcheck.h
"
#
include
"
cppcheckexecutor.h
"
#
include
"
errorlogger.h
"
#
include
"
importproject.h
"
#
include
"
settings.h
"
#
include
"
suppressions.h
"
#
include
<
algorithm
>
#
include
<
cstdlib
>
#
include
<
functional
>
#
include
<
future
>
#
include
<
iostream
>
#
include
<
list
>
#
include
<
numeric
>
#
include
<
mutex
>
#
include
<
system_error
>
#
include
<
utility
>
#
include
<
vector
>
ThreadExecutor::ThreadExecutor
(
const
std::map<std::string, std::
size_t
> &files, Settings &settings, ErrorLogger &errorLogger)
: Executor(files, settings, errorLogger)
{}
ThreadExecutor::~ThreadExecutor
()
{}
class
ThreadExecutor
::SyncLogForwarder : public ErrorLogger
{
public:
explicit
SyncLogForwarder
(ThreadExecutor &threadExecutor)
: mThreadExecutor(threadExecutor), mProcessedFiles(
0
), mTotalFiles(
0
), mProcessedSize(
0
), mTotalFileSize(
0
) {
mItNextFile
=
mThreadExecutor
.
mFiles
.
begin
();
mItNextFileSettings
=
mThreadExecutor
.
mSettings
.
project
.
fileSettings
.
begin
();
mTotalFiles
=
mThreadExecutor
.
mFiles
.
size
() +
mThreadExecutor
.
mSettings
.
project
.
fileSettings
.
size
();
for
(std::map<std::string, std::
size_t
>::const_iterator i =
mThreadExecutor
.
mFiles
.
begin
(); i !=
mThreadExecutor
.
mFiles
.
end
(); ++i) {
mTotalFileSize
+= i->
second
;
}
}
void
reportOut
(
const
std::string &outmsg, Color c)
override
{
std::lock_guard<std::mutex>
lg
(
mReportSync
);
mThreadExecutor
.
mErrorLogger
.
reportOut
(outmsg, c);
}
void
reportErr
(
const
ErrorMessage &msg)
override
{
report
(msg, MessageType::
REPORT_ERROR
);
}
void
reportInfo
(
const
ErrorMessage &msg)
override
{
report
(msg, MessageType::
REPORT_INFO
);
}
ThreadExecutor &
mThreadExecutor
;
std::map<std::string, std::
size_t
>::const_iterator
mItNextFile
;
std::list<ImportProject::FileSettings>::const_iterator
mItNextFileSettings
;
std::
size_t
mProcessedFiles
;
std::
size_t
mTotalFiles
;
std::
size_t
mProcessedSize
;
std::
size_t
mTotalFileSize
;
std::mutex
mFileSync
;
std::mutex
mErrorSync
;
std::mutex
mReportSync
;
private:
enum
class
MessageType
{
REPORT_ERROR
,
REPORT_INFO
};
void
report
(
const
ErrorMessage &msg, MessageType msgType)
{
if
(
mThreadExecutor
.
mSettings
.
nomsg
.
isSuppressed
(msg.
toSuppressionsErrorMessage
()))
return
;
//
Alert only about unique errors
bool
reportError =
false
;
const
std::string errmsg = msg.
toString
(
mThreadExecutor
.
mSettings
.
verbose
);
{
std::lock_guard<std::mutex>
lg
(
mErrorSync
);
if
(
std::find
(
mThreadExecutor
.
mErrorList
.
begin
(),
mThreadExecutor
.
mErrorList
.
end
(), errmsg) ==
mThreadExecutor
.
mErrorList
.
end
()) {
mThreadExecutor
.
mErrorList
.
emplace_back
(errmsg);
reportError =
true
;
}
}
if
(reportError) {
std::lock_guard<std::mutex>
lg
(
mReportSync
);
switch
(msgType) {
case
MessageType::
REPORT_ERROR
:
mThreadExecutor
.
mErrorLogger
.
reportErr
(msg);
break
;
case
MessageType::
REPORT_INFO
:
mThreadExecutor
.
mErrorLogger
.
reportInfo
(msg);
break
;
}
}
}
};
unsigned
int
ThreadExecutor::check
()
{
std::vector<std::future<
unsigned
int
>> threadFutures;
threadFutures.
reserve
(
mSettings
.
jobs
);
SyncLogForwarder
logforwarder
(*
this
);
for
(
unsigned
int
i =
0
; i <
mSettings
.
jobs
; ++i) {
try
{
threadFutures.
emplace_back
(
std::async
(std::launch::async, threadProc, &logforwarder));
}
catch
(
const
std::system_error &e) {
std::cerr <<
"
#### ThreadExecutor::check exception :
"
<< e.
what
() << std::endl;
exit
(
EXIT_FAILURE
);
}
}
return
std::accumulate
(threadFutures.
begin
(), threadFutures.
end
(),
0U
, [](
unsigned
int
v, std::future<
unsigned
int
>& f) {
return
v + f.
get
();
});
}
unsigned
int
STDCALL
ThreadExecutor::threadProc
(SyncLogForwarder* logForwarder)
{
unsigned
int
result =
0
;
std::map<std::string, std::
size_t
>::const_iterator &itFile = logForwarder->
mItNextFile
;
std::list<ImportProject::FileSettings>::const_iterator &itFileSettings = logForwarder->
mItNextFileSettings
;
//
guard static members of CppCheck against concurrent access
logForwarder->
mFileSync
.
lock
();
for
(;;) {
if
(itFile == logForwarder->
mThreadExecutor
.
mFiles
.
end
() && itFileSettings == logForwarder->
mThreadExecutor
.
mSettings
.
project
.
fileSettings
.
end
()) {
logForwarder->
mFileSync
.
unlock
();
break
;
}
CppCheck
fileChecker
(*logForwarder,
false
, CppCheckExecutor::executeCommand);
fileChecker.
settings
() = logForwarder->
mThreadExecutor
.
mSettings
;
std::
size_t
fileSize =
0
;
if
(itFile != logForwarder->
mThreadExecutor
.
mFiles
.
end
()) {
const
std::string &file = itFile->
first
;
fileSize = itFile->
second
;
++itFile;
logForwarder->
mFileSync
.
unlock
();
//
Read file from a file
result += fileChecker.
check
(file);
}
else
{
//
file settings..
const
ImportProject::FileSettings &fs = *itFileSettings;
++itFileSettings;
logForwarder->
mFileSync
.
unlock
();
result += fileChecker.
check
(fs);
if
(logForwarder->
mThreadExecutor
.
mSettings
.
clangTidy
)
fileChecker.
analyseClangTidy
(fs);
}
logForwarder->
mFileSync
.
lock
();
logForwarder->
mProcessedSize
+= fileSize;
logForwarder->
mProcessedFiles
++;
if
(!logForwarder->
mThreadExecutor
.
mSettings
.
quiet
) {
std::lock_guard<std::mutex>
lg
(logForwarder->
mReportSync
);
CppCheckExecutor::reportStatus
(logForwarder->
mProcessedFiles
, logForwarder->
mTotalFiles
, logForwarder->
mProcessedSize
, logForwarder->
mTotalFileSize
);
}
}
return
result;
}
Back
|
FazBrowse Home
|
New Git URL