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

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

Issue 23621056: Initial in-process implementation of some Mojo primitives. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wip18.1 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_CORE_IMPL_H_
6 #define MOJO_SYSTEM_CORE_IMPL_H_
7
8 #include "base/basictypes.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/synchronization/lock.h"
12 #include "mojo/public/system/core.h"
13
14 namespace mojo {
15 namespace system {
16
17 class CoreImpl;
18 class Dispatcher;
19
20 namespace test {
21 class CoreTestBase;
22 }
23
24 // |CoreImpl| is a singleton object that implements the Mojo system calls. With
25 // the (obvious) exception of |Init()|, which must be called first (and the call
26 // completed) before making any other calls, all the public methods are
27 // thread-safe.
28 class CoreImpl {
29 public:
30 static void Init();
31
32 static CoreImpl* Get() {
33 return mojo_system_singleton_;
34 }
35
36 MojoResult Close(MojoHandle handle);
37
38 MojoResult Wait(MojoHandle handle,
39 MojoWaitFlags flags,
40 MojoDeadline deadline);
41
42 MojoResult WaitMany(const MojoHandle* handles,
43 const MojoWaitFlags* flags,
44 uint32_t num_handles,
45 MojoDeadline deadline);
46
47 MojoResult CreateMessagePipe(MojoHandle* handle_0, MojoHandle* handle_1);
48
49 MojoResult WriteMessage(MojoHandle handle,
50 const void* bytes, uint32_t num_bytes,
51 const MojoHandle* handles, uint32_t num_handles,
52 MojoWriteMessageFlags flags);
53
54 MojoResult ReadMessage(MojoHandle handle,
55 void* bytes, uint32_t* num_bytes,
56 MojoHandle* handles, uint32_t* num_handles,
57 MojoReadMessageFlags flags);
58
59 private:
60 friend class test::CoreTestBase;
darin (slow to review) 2013/09/25 06:06:07 note: Are you sure you want to use all of the nest
viettrungluu 2013/09/25 18:22:16 That's a good question. The advantage of putting t
61
62 typedef base::hash_map<MojoHandle, scoped_refptr<Dispatcher> >
63 HandleTableMap;
64
65 CoreImpl();
66 ~CoreImpl();
67
68 // Looks up the dispatcher for the given handle. Returns null if the handle is
69 // invalid.
70 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle);
71
72 // Assigns a new handle for the given dispatcher (which must be valid);
73 // returns |MOJO_HANDLE_INVALID| on failure (due to hitting resource limits).
74 // Must be called under |handle_table_lock_|.
75 MojoHandle AddDispatcherNoLock(scoped_refptr<Dispatcher> dispatcher);
76
77 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic
78 // validation of arguments.
79 MojoResult WaitManyInternal(const MojoHandle* handles,
80 const MojoWaitFlags* flags,
81 uint32_t num_handles,
82 MojoDeadline deadline);
83
84 // ---------------------------------------------------------------------------
85
86 static CoreImpl* mojo_system_singleton_;
darin (slow to review) 2013/09/25 06:06:07 nit: maybe just call it singleton_ since "mojo" an
viettrungluu 2013/09/26 17:59:15 Done.
87
88 // ---------------------------------------------------------------------------
89
90 // TODO(vtl): |handle_table_lock_| should be a reader-writer lock (if only we
91 // had them).
92 base::Lock handle_table_lock_; // Protects the immediately-following members.
93 HandleTableMap handle_table_;
94 MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|.
darin (slow to review) 2013/09/25 06:06:07 nit: next_handle_ -> next_unused_handle_? I had to
95
96 // ---------------------------------------------------------------------------
97
98 DISALLOW_COPY_AND_ASSIGN(CoreImpl);
99 };
100
101 } // namespace system
102 } // namespace mojo
103
104 #endif // MOJO_SYSTEM_CORE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698