| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_SYSTEM_DISPATCHER_H_ | 5 #ifndef MOJO_SYSTEM_DISPATCHER_H_ |
| 6 #define MOJO_SYSTEM_DISPATCHER_H_ | 6 #define MOJO_SYSTEM_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "mojo/public/system/core.h" | 11 #include "mojo/public/system/core.h" |
| 12 #include "mojo/public/system/system_export.h" |
| 12 | 13 |
| 13 namespace mojo { | 14 namespace mojo { |
| 14 namespace system { | 15 namespace system { |
| 15 | 16 |
| 16 class Waiter; | 17 class Waiter; |
| 17 | 18 |
| 18 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular | 19 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular |
| 19 // handle. This includes most (all?) primitives except for |MojoWait...()|. This | 20 // handle. This includes most (all?) primitives except for |MojoWait...()|. This |
| 20 // object is thread-safe, with its state being protected by a single lock | 21 // object is thread-safe, with its state being protected by a single lock |
| 21 // |lock_|, which is also made available to implementation subclasses (via the | 22 // |lock_|, which is also made available to implementation subclasses (via the |
| 22 // |lock()| method). | 23 // |lock()| method). |
| 23 class Dispatcher : public base::RefCountedThreadSafe<Dispatcher> { | 24 class MOJO_SYSTEM_EXPORT Dispatcher : |
| 25 public base::RefCountedThreadSafe<Dispatcher> { |
| 24 public: | 26 public: |
| 25 // These methods implement the various primitives named |Mojo...()|. These | 27 // These methods implement the various primitives named |Mojo...()|. These |
| 26 // take |lock_| and handle races with |Close()|. Then they call out to | 28 // take |lock_| and handle races with |Close()|. Then they call out to |
| 27 // subclasses' |...ImplNoLock()| methods (still under |lock_|), which actually | 29 // subclasses' |...ImplNoLock()| methods (still under |lock_|), which actually |
| 28 // implement the primitives. | 30 // implement the primitives. |
| 29 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and | 31 // NOTE(vtl): This puts a big lock around each dispatcher (i.e., handle), and |
| 30 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as | 32 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as |
| 31 // possible. If this becomes an issue, we can rethink this. | 33 // possible. If this becomes an issue, we can rethink this. |
| 32 MojoResult Close(); | 34 MojoResult Close(); |
| 33 MojoResult WriteMessage(const void* bytes, | 35 MojoResult WriteMessage(const void* bytes, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 mutable base::Lock lock_; | 99 mutable base::Lock lock_; |
| 98 bool is_closed_; | 100 bool is_closed_; |
| 99 | 101 |
| 100 DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 102 DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
| 101 }; | 103 }; |
| 102 | 104 |
| 103 } // namespace system | 105 } // namespace system |
| 104 } // namespace mojo | 106 } // namespace mojo |
| 105 | 107 |
| 106 #endif // MOJO_SYSTEM_DISPATCHER_H_ | 108 #endif // MOJO_SYSTEM_DISPATCHER_H_ |
| OLD | NEW |