This commit is contained in:
aozhiwei 2024-12-22 21:32:01 +08:00
parent 6c39a6480d
commit e1ab21d022
4 changed files with 14 additions and 6 deletions

View File

@ -36,3 +36,8 @@ void App::DispatchSocketMsg(f8::MsgHdr* hdr)
{
}
bool App::PreprocessSocketMsg(f8::MsgHdr* hdr)
{
return false;
}

View File

@ -13,5 +13,6 @@ public:
virtual void Update(int delta_time) override;
virtual bool HasTask() override;
virtual void DispatchSocketMsg(f8::MsgHdr* hdr) override;
virtual bool PreprocessSocketMsg(f8::MsgHdr* hdr) override;
};

View File

@ -51,7 +51,8 @@ namespace f8
int instance_id_ = 0;
std::set<int> flags_;
a8::Queue queue_;
a8::Queue net_data_queue_;
a8::Queue net_msg_queue_;
std::atomic<long long> msgnode_size_ = {0};
std::atomic<long long> working_msgnode_size_ = {0};
@ -169,8 +170,8 @@ namespace f8
std::unique_lock<std::mutex> lk(*loop_mutex_);
bool has_task = false;
{
queue_.Fetch();
if (!list_empty(queue_.GetWorkList())) {
net_msg_queue_.Fetch();
if (!list_empty(net_msg_queue_.GetWorkList())) {
has_task = true;
}
}
@ -188,8 +189,8 @@ namespace f8
void DispatchNetMsg()
{
queue_.Fetch();
list_head* work_list = queue_.GetWorkList();
net_msg_queue_.Fetch();
list_head* work_list = net_msg_queue_.GetWorkList();
while (!list_empty(work_list)){
MsgHdr* hdr = list_first_entry(work_list, MsgHdr, entry);
list_del_init(&hdr->entry);
@ -223,7 +224,7 @@ namespace f8
memmove((void*)hdr->buf, msgbody, bodylen);
}
++msgnode_size_;
queue_.Push(&hdr->entry);
net_data_queue_.Push(&hdr->entry);
NotifyLoopCond();
}

View File

@ -13,6 +13,7 @@ namespace f8
virtual void Update(int delta_time) = 0;
virtual bool HasTask() = 0;
virtual void DispatchSocketMsg(f8::MsgHdr* hdr) = 0;
virtual bool PreprocessSocketMsg(f8::MsgHdr* hdr) = 0;
};
}