Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: mojo/edk/system/ports/message_queue.h

Issue 1585493002: [mojo] Ports EDK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MOJO_EDK_SYSTEM_PORTS_MESSAGE_QUEUE_H_
6 #define MOJO_EDK_SYSTEM_PORTS_MESSAGE_QUEUE_H_
7
8 #include <stdint.h>
9
10 #include <deque>
11 #include <functional>
12 #include <vector>
13
14 #include "base/macros.h"
15 #include "mojo/edk/system/ports/message.h"
16
17 namespace mojo {
18 namespace edk {
19 namespace ports {
20
21 const uint64_t kInitialSequenceNum = 1;
22 const uint64_t kInvalidSequenceNum = 0xFFFFFFFF;
23
24 // An incoming message queue for a port. MessageQueue keeps track of the highest
25 // known sequence number and can indicate whether the next sequential message is
26 // available. Thus the queue enforces message ordering for the consumer without
27 // enforcing it for the producer (see AcceptMessage() below.)
28 class MessageQueue {
29 public:
30 explicit MessageQueue();
31 explicit MessageQueue(uint64_t next_sequence_num);
32 ~MessageQueue();
33
34 void set_signalable(bool value) { signalable_ = value; }
35
36 uint64_t next_sequence_num() const { return next_sequence_num_; }
37
38 bool HasNextMessage() const;
39
40 // Gives ownership of the message. The selector may be null.
41 void GetNextMessageIf(std::function<bool(const Message&)> selector,
42 ScopedMessage* message);
43
44 // Takes ownership of the message. Note: Messages are ordered, so while we
45 // have added a message to the queue, we may still be waiting on a message
46 // ahead of this one before we can let any of the messages be returned by
47 // GetNextMessage.
48 //
49 // Furthermore, once has_next_message is set to true, it will remain false
50 // until GetNextMessage is called enough times to return a null message.
51 // In other words, has_next_message acts like an edge trigger.
52 //
53 void AcceptMessage(ScopedMessage message, bool* has_next_message);
54
55 // Returns all of the ports referenced by messages in this message queue.
56 void GetReferencedPorts(std::deque<PortName>* ports);
57
58 private:
59 std::vector<ScopedMessage> heap_;
60 uint64_t next_sequence_num_;
61 bool signalable_ = true;
62
63 DISALLOW_COPY_AND_ASSIGN(MessageQueue);
64 };
65
66 } // namespace ports
67 } // namespace edk
68 } // namespace mojo
69
70 #endif // MOJO_EDK_SYSTEM_PORTS_MESSAGE_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698