Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
6a545456
Unverified
Commit
6a545456
authored
Apr 19, 2019
by
Zhangyi Chen
Committed by
GitHub
Apr 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #667 from mikeyang2015/master
support custom executor in execution_queue
parents
a12514ba
8c1d5228
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
10 deletions
+30
-10
execution_queue.cpp
src/bthread/execution_queue.cpp
+16
-9
execution_queue.h
src/bthread/execution_queue.h
+13
-0
execution_queue_inl.h
src/bthread/execution_queue_inl.h
+1
-1
No files found.
src/bthread/execution_queue.cpp
View file @
6a545456
...
...
@@ -101,15 +101,22 @@ void ExecutionQueueBase::start_execute(TaskNode* node) {
}
}
bthread_t
tid
;
// We start the execution thread in background instead of foreground as
// we can't determine whether the code after execute() is urgent (like
// unlock a pthread_mutex_t) in which case implicit context switch may
// cause undefined behavior (e.g. deadlock)
if
(
bthread_start_background
(
&
tid
,
&
_options
.
bthread_attr
,
_execute_tasks
,
node
)
!=
0
)
{
PLOG
(
FATAL
)
<<
"Fail to start bthread"
;
_execute_tasks
(
node
);
if
(
nullptr
==
_options
.
executor
)
{
bthread_t
tid
;
// We start the execution thread in background instead of foreground as
// we can't determine whether the code after execute() is urgent (like
// unlock a pthread_mutex_t) in which case implicit context switch may
// cause undefined behavior (e.g. deadlock)
if
(
bthread_start_background
(
&
tid
,
&
_options
.
bthread_attr
,
_execute_tasks
,
node
)
!=
0
)
{
PLOG
(
FATAL
)
<<
"Fail to start bthread"
;
_execute_tasks
(
node
);
}
}
else
{
if
(
_options
.
executor
->
submit
(
_execute_tasks
,
node
)
!=
0
)
{
PLOG
(
FATAL
)
<<
"Fail to submit task"
;
_execute_tasks
(
node
);
}
}
}
...
...
src/bthread/execution_queue.h
View file @
6a545456
...
...
@@ -128,11 +128,24 @@ const static TaskOptions TASK_OPTIONS_NORMAL = TaskOptions(false, false);
const
static
TaskOptions
TASK_OPTIONS_URGENT
=
TaskOptions
(
true
,
false
);
const
static
TaskOptions
TASK_OPTIONS_INPLACE
=
TaskOptions
(
false
,
true
);
class
Executor
{
public
:
virtual
~
Executor
()
{}
// Return 0 on success.
virtual
int
submit
(
void
*
(
*
fn
)(
void
*
),
void
*
args
)
=
0
;
};
struct
ExecutionQueueOptions
{
ExecutionQueueOptions
();
// Attribute of the bthread which execute runs on
// default: BTHREAD_ATTR_NORMAL
bthread_attr_t
bthread_attr
;
// Executor that tasks run on. bthread will be used when executor = NULL.
// Note that TaskOptions.in_place_if_possible = false will not work, if implementation of
// Executor is in-place(synchronous).
Executor
*
executor
;
};
// Start a ExecutionQueue. If |options| is NULL, the queue will be created with
...
...
src/bthread/execution_queue_inl.h
View file @
6a545456
...
...
@@ -317,7 +317,7 @@ public:
};
inline
ExecutionQueueOptions
::
ExecutionQueueOptions
()
:
bthread_attr
(
BTHREAD_ATTR_NORMAL
)
:
bthread_attr
(
BTHREAD_ATTR_NORMAL
)
,
executor
(
NULL
)
{}
template
<
typename
T
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment