Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
fe6b328a
Commit
fe6b328a
authored
8 years ago
by
Michael Lumish
Browse files
Options
Downloads
Patches
Plain Diff
Node: refactor non-uv completion queue wrapping code
parent
2b3e12ce
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/node/ext/completion_queue_threadpool.cc
+15
-29
15 additions, 29 deletions
src/node/ext/completion_queue_threadpool.cc
with
15 additions
and
29 deletions
src/node/ext/completion_queue_threadpool.cc
+
15
−
29
View file @
fe6b328a
...
@@ -78,6 +78,8 @@ class CompletionQueueAsyncWorker : public Nan::AsyncWorker {
...
@@ -78,6 +78,8 @@ class CompletionQueueAsyncWorker : public Nan::AsyncWorker {
void
HandleErrorCallback
();
void
HandleErrorCallback
();
private:
private:
static
void
TryAddWorker
();
grpc_event
result
;
grpc_event
result
;
static
grpc_completion_queue
*
queue
;
static
grpc_completion_queue
*
queue
;
...
@@ -118,20 +120,21 @@ void CompletionQueueAsyncWorker::Execute() {
...
@@ -118,20 +120,21 @@ void CompletionQueueAsyncWorker::Execute() {
grpc_completion_queue
*
CompletionQueueAsyncWorker
::
GetQueue
()
{
return
queue
;
}
grpc_completion_queue
*
CompletionQueueAsyncWorker
::
GetQueue
()
{
return
queue
;
}
void
CompletionQueueAsyncWorker
::
Next
()
{
void
CompletionQueueAsyncWorker
::
TryAddWorker
()
{
#ifndef GRPC_UV
if
(
current_threads
<
max_queue_threads
&&
waiting_next_calls
>
0
)
{
Nan
::
HandleScope
scope
;
if
(
current_threads
<
max_queue_threads
)
{
current_threads
+=
1
;
current_threads
+=
1
;
waiting_next_calls
-=
1
;
CompletionQueueAsyncWorker
*
worker
=
new
CompletionQueueAsyncWorker
();
CompletionQueueAsyncWorker
*
worker
=
new
CompletionQueueAsyncWorker
();
Nan
::
AsyncQueueWorker
(
worker
);
Nan
::
AsyncQueueWorker
(
worker
);
}
else
{
waiting_next_calls
+=
1
;
}
}
GPR_ASSERT
(
current_threads
<=
max_queue_threads
);
GPR_ASSERT
(
current_threads
<=
max_queue_threads
);
GPR_ASSERT
((
current_threads
==
max_queue_threads
)
||
GPR_ASSERT
((
current_threads
==
max_queue_threads
)
||
(
waiting_next_calls
==
0
));
(
waiting_next_calls
==
0
));
#endif
}
void
CompletionQueueAsyncWorker
::
Next
()
{
waiting_next_calls
+=
1
;
TryAddWorker
();
}
}
void
CompletionQueueAsyncWorker
::
Init
(
Local
<
Object
>
exports
)
{
void
CompletionQueueAsyncWorker
::
Init
(
Local
<
Object
>
exports
)
{
...
@@ -143,17 +146,8 @@ void CompletionQueueAsyncWorker::Init(Local<Object> exports) {
...
@@ -143,17 +146,8 @@ void CompletionQueueAsyncWorker::Init(Local<Object> exports) {
void
CompletionQueueAsyncWorker
::
HandleOKCallback
()
{
void
CompletionQueueAsyncWorker
::
HandleOKCallback
()
{
Nan
::
HandleScope
scope
;
Nan
::
HandleScope
scope
;
if
(
waiting_next_calls
>
0
)
{
current_threads
-=
1
;
waiting_next_calls
-=
1
;
TryAddWorker
();
// Old worker removed, new worker added. current_threads += 0
CompletionQueueAsyncWorker
*
worker
=
new
CompletionQueueAsyncWorker
();
Nan
::
AsyncQueueWorker
(
worker
);
}
else
{
current_threads
-=
1
;
}
GPR_ASSERT
(
current_threads
<=
max_queue_threads
);
GPR_ASSERT
((
current_threads
==
max_queue_threads
)
||
(
waiting_next_calls
==
0
));
Nan
::
Callback
*
callback
=
GetTagCallback
(
result
.
tag
);
Nan
::
Callback
*
callback
=
GetTagCallback
(
result
.
tag
);
Local
<
Value
>
argv
[]
=
{
Nan
::
Null
(),
GetTagNodeValue
(
result
.
tag
)};
Local
<
Value
>
argv
[]
=
{
Nan
::
Null
(),
GetTagNodeValue
(
result
.
tag
)};
callback
->
Call
(
2
,
argv
);
callback
->
Call
(
2
,
argv
);
...
@@ -162,18 +156,9 @@ void CompletionQueueAsyncWorker::HandleOKCallback() {
...
@@ -162,18 +156,9 @@ void CompletionQueueAsyncWorker::HandleOKCallback() {
}
}
void
CompletionQueueAsyncWorker
::
HandleErrorCallback
()
{
void
CompletionQueueAsyncWorker
::
HandleErrorCallback
()
{
if
(
waiting_next_calls
>
0
)
{
waiting_next_calls
-=
1
;
// Old worker removed, new worker added. current_threads += 0
CompletionQueueAsyncWorker
*
worker
=
new
CompletionQueueAsyncWorker
();
Nan
::
AsyncQueueWorker
(
worker
);
}
else
{
current_threads
-=
1
;
}
GPR_ASSERT
(
current_threads
<=
max_queue_threads
);
GPR_ASSERT
((
current_threads
==
max_queue_threads
)
||
(
waiting_next_calls
==
0
));
Nan
::
HandleScope
scope
;
Nan
::
HandleScope
scope
;
current_threads
-=
1
;
TryAddWorker
();
Nan
::
Callback
*
callback
=
GetTagCallback
(
result
.
tag
);
Nan
::
Callback
*
callback
=
GetTagCallback
(
result
.
tag
);
Local
<
Value
>
argv
[]
=
{
Nan
::
Error
(
ErrorMessage
())};
Local
<
Value
>
argv
[]
=
{
Nan
::
Error
(
ErrorMessage
())};
...
@@ -189,6 +174,7 @@ grpc_completion_queue *GetCompletionQueue() {
...
@@ -189,6 +174,7 @@ grpc_completion_queue *GetCompletionQueue() {
}
}
void
CompletionQueueNext
()
{
void
CompletionQueueNext
()
{
gpr_log
(
GPR_DEBUG
,
"Called CompletionQueueNext"
);
CompletionQueueAsyncWorker
::
Next
();
CompletionQueueAsyncWorker
::
Next
();
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment