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

Side by Side Diff: mojo/system/message_pipe.h

Issue 23621056: Initial in-process implementation of some Mojo primitives. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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_SYSTEM_MESSAGE_PIPE_H_
6 #define MOJO_SYSTEM_MESSAGE_PIPE_H_
7
8 #include <list>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h"
15 #include "mojo/public/system/core.h"
16 #include "mojo/system/waiter_list.h"
17
18 namespace mojo {
19 namespace system {
20
21 class Waiter;
22
23 // |MessagePipe| is the secondary object implementing a message pipe (see the
24 // explanatory comment in core_impl.cc), and is jointly owned by the two
25 // dispatchers passed in to the constructor. This class is thread-safe.
26 class MessagePipe : public base::RefCountedThreadSafe<MessagePipe> {
27 public:
28 MessagePipe();
29
30 // These are called by the dispatcher to implement its methods of
31 // corresponding names. In all cases, the port |port| must be open.
32 void CancelAllWaiters(unsigned port);
33 void Close(unsigned port);
34 MojoResult WriteMessage(unsigned port,
35 const void* bytes, uint32_t num_bytes,
36 const MojoHandle* handles, uint32_t num_handles,
37 MojoWriteMessageFlags flags);
38 MojoResult ReadMessage(unsigned port,
39 void* bytes, uint32_t* num_bytes,
40 MojoHandle* handles, uint32_t* num_handles,
41 MojoReadMessageFlags flags);
42 MojoResult AddWaiter(unsigned port,
43 Waiter* waiter,
44 MojoWaitFlags flags,
45 MojoResult wake_result);
46 void RemoveWaiter(unsigned port, Waiter* waiter);
47
48 private:
49 struct MessageInTransit {
50 MessageInTransit(const void* bytes, uint32_t num_bytes)
51 : data(static_cast<const char*>(bytes), num_bytes) {}
52
53 // TODO(vtl): Replace with something more efficient.
54 std::string data;
55 };
56
57 friend class base::RefCountedThreadSafe<MessagePipe>;
58 virtual ~MessagePipe();
59
60 MojoWaitFlags SatisfiedFlagsNoLock(unsigned port);
61 MojoWaitFlags SatisfiableFlagsNoLock(unsigned port);
62
63 base::Lock lock_; // Protects the following members.
64 bool is_open_[2];
65 // These are *incoming* queues for their corresponding ports. It owns its
66 // contents.
67 // TODO(vtl): When possible (with C++11), convert the plain pointers to
68 // scoped_ptr/unique_ptr. (Then we'll be able to use an |std::queue| instead
69 // of an |std::list|.)
70 std::list<MessageInTransit*> message_queues_[2];
71 WaiterList waiter_lists_[2];
72
73 DISALLOW_COPY_AND_ASSIGN(MessagePipe);
74 };
75
76 } // namespace system
77 } // namespace mojo
78
79 #endif // MOJO_SYSTEM_MESSAGE_PIPE_H_
OLDNEW
« mojo/mojo.gyp ('K') | « mojo/system/memory.cc ('k') | mojo/system/message_pipe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698