Skip to content

Commit 940577b

Browse files
sam-githubtargos
authored andcommitted
src: move ThreadPoolWork inlines into a -inl.h
The presence of the inline definitions in node_internals.h can cause all files that include node_internals.h to depend on util-inl.h, even if they never use ThreadPoolWork. Whether this happens depends on the toolchain, gcc will strip unused definitions, clang won't. PR-URL: #27755 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8040d8b commit 940577b

File tree

5 files changed

+60
-21
lines changed

5 files changed

+60
-21
lines changed

src/node_api.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "node_binding.h"
77
#include "node_errors.h"
88
#include "node_internals.h"
9+
#include "threadpoolwork-inl.h"
910
#include "util-inl.h"
1011

1112
#include <memory>

src/node_crypto.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "base_object-inl.h"
3434
#include "env-inl.h"
3535
#include "string_bytes.h"
36+
#include "threadpoolwork-inl.h"
3637
#include "util-inl.h"
3738
#include "v8.h"
3839

src/node_internals.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -255,27 +255,6 @@ class ThreadPoolWork {
255255
uv_work_t work_req_;
256256
};
257257

258-
void ThreadPoolWork::ScheduleWork() {
259-
env_->IncreaseWaitingRequestCounter();
260-
int status = uv_queue_work(
261-
env_->event_loop(),
262-
&work_req_,
263-
[](uv_work_t* req) {
264-
ThreadPoolWork* self = ContainerOf(&ThreadPoolWork::work_req_, req);
265-
self->DoThreadPoolWork();
266-
},
267-
[](uv_work_t* req, int status) {
268-
ThreadPoolWork* self = ContainerOf(&ThreadPoolWork::work_req_, req);
269-
self->env_->DecreaseWaitingRequestCounter();
270-
self->AfterThreadPoolWork(status);
271-
});
272-
CHECK_EQ(status, 0);
273-
}
274-
275-
int ThreadPoolWork::CancelWork() {
276-
return uv_cancel(reinterpret_cast<uv_req_t*>(&work_req_));
277-
}
278-
279258
#define TRACING_CATEGORY_NODE "node"
280259
#define TRACING_CATEGORY_NODE1(one) \
281260
TRACING_CATEGORY_NODE "," \

src/node_zlib.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "async_wrap-inl.h"
2626
#include "env-inl.h"
27+
#include "threadpoolwork-inl.h"
2728
#include "util-inl.h"
2829

2930
#include "v8.h"

src/threadpoolwork-inl.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
#ifndef SRC_THREADPOOLWORK_INL_H_
23+
#define SRC_THREADPOOLWORK_INL_H_
24+
25+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26+
27+
#include "util-inl.h"
28+
#include "node_internals.h"
29+
30+
namespace node {
31+
32+
void ThreadPoolWork::ScheduleWork() {
33+
env_->IncreaseWaitingRequestCounter();
34+
int status = uv_queue_work(
35+
env_->event_loop(),
36+
&work_req_,
37+
[](uv_work_t* req) {
38+
ThreadPoolWork* self = ContainerOf(&ThreadPoolWork::work_req_, req);
39+
self->DoThreadPoolWork();
40+
},
41+
[](uv_work_t* req, int status) {
42+
ThreadPoolWork* self = ContainerOf(&ThreadPoolWork::work_req_, req);
43+
self->env_->DecreaseWaitingRequestCounter();
44+
self->AfterThreadPoolWork(status);
45+
});
46+
CHECK_EQ(status, 0);
47+
}
48+
49+
int ThreadPoolWork::CancelWork() {
50+
return uv_cancel(reinterpret_cast<uv_req_t*>(&work_req_));
51+
}
52+
53+
} // namespace node
54+
55+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
56+
57+
#endif // SRC_THREADPOOLWORK_INL_H_

0 commit comments

Comments
 (0)