Skip to content

Commit

Permalink
优化调用队列锁操作。
Browse files Browse the repository at this point in the history
  • Loading branch information
wlgq2 committed Oct 17, 2020
1 parent 71c3b54 commit dfff205
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions uv/Async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ void Async::runInThisLoop(DefaultCallback callback)

void uv::Async::process()
{
std::lock_guard<std::mutex> lock(mutex_);
while (!callbacks_.empty())
std::queue<DefaultCallback> callbacks;
{
auto func = callbacks_.front();
std::lock_guard<std::mutex> lock(mutex_);
callbacks_.swap(callbacks);
}
while (!callbacks.empty())
{
auto func = callbacks.front();
func();
callbacks_.pop();
callbacks.pop();
}
}

Expand Down
2 changes: 1 addition & 1 deletion uv/include/uv11.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifndef UV_UV11_H
#define UV_UV11_H

#define UV_CPP_VERSION "1.5.2"
#define UV_CPP_VERSION "1.5.3"

#include "Async.h"
#include "Signal.h"
Expand Down

0 comments on commit dfff205

Please sign in to comment.