Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
30091dc2
Commit
30091dc2
authored
Mar 27, 2019
by
antirez
Browse files
Threaded IO: use main thread if num of threads is 1.
parent
9bf7f302
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
30091dc2
...
...
@@ -2525,11 +2525,16 @@ void *IOThreadMain(void *myid) {
/* Initialize the data structures needed for threaded I/O. */
void
initThreadedIO
(
void
)
{
pthread_t
tid
;
server
.
io_threads_num
=
8
;
io_threads_active
=
0
;
/* We start with threads not active. */
/* Don't spawn any thread if the user selected a single thread:
* we'll handle I/O directly from the main thread. */
if
(
server
.
io_threads_num
==
1
)
return
;
/* Spawn the I/O threads. */
for
(
int
i
=
0
;
i
<
server
.
io_threads_num
;
i
++
)
{
pthread_t
tid
;
pthread_mutex_init
(
&
io_threads_mutex
[
i
],
NULL
);
io_threads_pending
[
i
]
=
0
;
io_threads_list
[
i
]
=
listCreate
();
...
...
@@ -2569,6 +2574,10 @@ void stopThreadedIO(void) {
* could be possibly stopped (if already active) as a side effect. */
int
stopThreadedIOIfNeeded
(
void
)
{
int
pending
=
listLength
(
server
.
clients_pending_write
);
/* Return ASAP if IO threads are disabled (single threaded mode). */
if
(
server
.
io_threads_num
==
1
)
return
0
;
if
(
pending
<
(
server
.
io_threads_num
*
2
))
{
if
(
io_threads_active
)
stopThreadedIO
();
return
1
;
...
...
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