当前位置: 首页>>代码示例>>C++>>正文


C++ MessageQueue::back方法代码示例

本文整理汇总了C++中MessageQueue::back方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageQueue::back方法的具体用法?C++ MessageQueue::back怎么用?C++ MessageQueue::back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessageQueue的用法示例。


在下文中一共展示了MessageQueue::back方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TestMessageQueue3

void TestMessageQueue3()
{
    MessageQueue q;

    Uint32 sum = 0;

    for (Uint32 i = 1; i <= 5; i++)
    {
	q.enqueue(new Alarm(i));
	sum += i;
    }
    assert(sum == 15);

    while (!q.isEmpty())
	q.remove(q.back());

    assert(q.getCount() == 0);
}
开发者ID:ncultra,项目名称:Pegasus-2.5,代码行数:18,代码来源:MessageQueue.cpp

示例2: TestMessageQueue1

void TestMessageQueue1()
{
    MessageQueue q;

    Uint32 sum = 0;

    for (Uint32 i = 1; i <= 5; i++)
    {
	q.enqueue(new Alarm(i));
	sum += i;
    }

    assert(Sum(q) == sum);

    // Test removing from the middle:
    Message* m = q.findByKey(3);
    assert(m != 0);
    q.remove(m);
    assert(Sum(q) == sum - 3);
    assert(q.getCount() == 4);

    // Test removing from the front:
    q.remove(q.front());
    assert(Sum(q) == sum - 3 - 1);
    assert(q.getCount() == 3);

    // Test removing from the front:
    q.remove(q.back());
    assert(Sum(q) == sum - 3 - 1 - 5);
    assert(q.getCount() == 2);

    // Test dequeue:
    m = q.dequeue();
    assert(m->getKey() == 2);
    assert(Sum(q) == sum - 3 - 1 - 5 - 2);
    assert(q.getCount() == 1);

    // Test dequeue:
    m = q.dequeue();
    assert(m->getKey() == 4);
    assert(Sum(q) == sum - 3 - 1 - 5 - 2 - 4);
    assert(q.getCount() == 0);
}
开发者ID:ncultra,项目名称:Pegasus-2.5,代码行数:43,代码来源:MessageQueue.cpp

示例3: AssertLinkThread

void
RPCChannel::OnMessageReceivedFromLink(const Message& msg)
{
    AssertLinkThread();
    mMonitor->AssertCurrentThreadOwns();

    if (MaybeInterceptSpecialIOMessage(msg))
        return;

    // regardless of the RPC stack, if we're awaiting a sync reply, we
    // know that it needs to be immediately handled to unblock us.
    if (AwaitingSyncReply() && msg.is_sync()) {
        // wake up worker thread waiting at SyncChannel::Send
        mRecvd = msg;
        NotifyWorkerThread();
        return;
    }

    MessageQueue *queue = (msg.priority() == IPC::Message::PRIORITY_HIGH)
                          ? &mUrgent
                          : &mPending;

    bool compressMessage = (msg.compress() && !queue->empty() &&
                            queue->back().type() == msg.type() &&
                            queue->back().routing_id() == msg.routing_id());
    if (compressMessage) {
        // This message type has compression enabled, and the back of
        // the queue was the same message type and routed to the same
        // destination.  Replace it with the newer message.
        MOZ_ASSERT(queue->back().compress());
        queue->pop_back();
    }

    queue->push_back(msg);

    // There are three cases we're concerned about, relating to the state of
    // the main thread:
    //
    // (1) We are waiting on a sync reply - main thread is blocked on the IPC monitor.
    //   - If the message is high priority, we wake up the main thread to
    //     deliver the message. Otherwise, we leave it in the mPending queue,
    //     posting a task to the main event loop, where it will be processed
    //     once the synchronous reply has been received.
    //
    // (2) We are waiting on an RPC reply - main thread is blocked on the IPC monitor.
    //   - Always wake up the main thread to deliver the message.
    //
    // (3) We are not waiting on a reply.
    //   - We post a task to the main event loop.
    //
    bool waiting_rpc = (0 != StackDepth());
    bool urgent = (msg.priority() == IPC::Message::PRIORITY_HIGH);

    if (waiting_rpc || (AwaitingSyncReply() && urgent)) {
        // Always wake up our RPC waiter, and wake up sync waiters for urgent
        // messages.
        NotifyWorkerThread();
    } else {
        // Worker thread is either not blocked on a reply, or this is an
        // incoming RPC that raced with outgoing sync and needs to be deferred
        // to a later event-loop iteration.
        if (!compressMessage) {
            // If we compressed away the previous message, we'll reuse
            // its pending task.
            mWorkerLoop->PostTask(FROM_HERE, new DequeueTask(mDequeueOneTask));
        }
    }
}
开发者ID:matyapiro31,项目名称:instantbird-1.5,代码行数:68,代码来源:RPCChannel.cpp


注:本文中的MessageQueue::back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。