MCPcopy Create free account
hub / github.com/Tencent/mars / FasterMessage

Function FasterMessage

mars/comm/messagequeue/message_queue.cc:442–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

440}
441
442MessagePost_t FasterMessage(const MessageHandler_t& _handlerid, const Message& _message, const MessageTiming& _timing) {
443 ScopedLock lock(sg_messagequeue_map_mutex);
444 const MessageQueue_t& id = _handlerid.queue;
445
446 std::map<MessageQueue_t, MessageQueueContent>::iterator pos = sg_messagequeue_map.find(id);
447 if (sg_messagequeue_map.end() == pos) return KNullPost;
448
449 MessageQueueContent& content = pos->second;
450
451 MessageWrapper* messagewrapper = new MessageWrapper(_handlerid, _message, _timing, __MakeSeq());
452
453 for (std::list<MessageWrapper*>::iterator it = content.lst_message.begin(); it != content.lst_message.end(); ++it) {
454 if ((*it)->postid.reg == _handlerid && (*it)->message == _message) {
455 if (__ComputerWaitTime(**it) < __ComputerWaitTime(*messagewrapper)) {
456 delete messagewrapper;
457 return (*it)->postid;
458 }
459
460 messagewrapper->postid = (*it)->postid;
461 delete(*it);
462 content.lst_message.erase(it);
463 break;
464 }
465 }
466
467 if(content.lst_message.size() >= MAX_MQ_SIZE) {
468 xwarn2(TSF"%_", DumpMessage(content.lst_message));
469 ASSERT2(false, "Over MAX_MQ_SIZE");
470 delete messagewrapper;
471 return KNullPost;
472 }
473 content.lst_message.push_back(messagewrapper);
474 content.breaker->Notify(lock);
475 return messagewrapper->postid;
476}
477
478bool WaitMessage(const MessagePost_t& _message, long _timeoutInMs) {
479 bool is_in_mq = Handler2Queue(Post2Handler(_message)) == CurrentThreadMessageQueue();

Callers 2

__RunLoopMethod · 0.85
__RunLoopMethod · 0.85

Calls 10

__MakeSeqFunction · 0.85
__ComputerWaitTimeFunction · 0.85
DumpMessageFunction · 0.85
findMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
eraseMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
NotifyMethod · 0.45

Tested by

no test coverage detected