-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
slave thread pool #5
Conversation
@@ -85,9 +85,15 @@ class EventLoop { | |||
// for unittest only | |||
void Reset(); | |||
|
|||
std::shared_ptr<EventObject> GetEventObject(int id){ return objects_[id]; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用find方法,找不到返回null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
@@ -85,9 +85,15 @@ class EventLoop { | |||
// for unittest only | |||
void Reset(); | |||
|
|||
std::shared_ptr<EventObject> GetEventObject(int id){ return objects_[id]; } | |||
bool IsSlaveEventLoop(){ return name_.find("slave") != std::string::npos; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待评估吧,把业务逻辑加到eventloop这样的底层类,不是太妥。
@@ -85,9 +85,15 @@ class EventLoop { | |||
// for unittest only | |||
void Reset(); | |||
|
|||
std::shared_ptr<EventObject> GetEventObject(int id){ return objects_[id]; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
objects_[id]
这种方式获取 map内的数据, 如果map中没有这个id
的数据, 会插入一条key 为这个id
的数据, 所以在获取map数据时, 不要使用 objects_[id]
这种方式
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -102,26 +106,29 @@ EventLoop* EventLoop::Self() { return g_this_loop; } | |||
bool EventLoop::Register(std::shared_ptr<EventObject> obj, int events) { | |||
if (!obj) return false; | |||
|
|||
assert(InThisLoop()); | |||
// assert(InThisLoop()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥注释掉了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个在进行TcpConnection从一个loop转移到另一个slave_loop时,会存在跨线程注册,这里对objects_作加锁保护了
} while (id < 0 || objects_.count(id) != 0); | ||
{ | ||
// alloc unique id | ||
std::unique_lock<std::mutex> guard(object_mutex_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这行代码可以挪到 line 127 之下,以缩小 lock scope。毕竟119-125是原子操作。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
125行有对objects_进行访问,不应需要在while循环之前加锁么
The slave thread pool has resubmitted a new pr that fixes some of the previous irregularities |
add lock