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

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

Issue 103533008: Mojo: More data pipe implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: indentation Created 7 years 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
« no previous file with comments | « mojo/system/core_impl.cc ('k') | mojo/system/data_pipe.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_DATA_PIPE_H_
6 #define MOJO_SYSTEM_DATA_PIPE_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/synchronization/lock.h"
12 #include "mojo/public/system/core.h"
13 #include "mojo/system/system_impl_export.h"
14
15 namespace mojo {
16 namespace system {
17
18 class Waiter;
19 class WaiterList;
20
21 // |DataPipe| is a base class for secondary objects implementing data pipes,
22 // similar to |MessagePipe| (see the explanatory comment in core_impl.cc). It is
23 // typically owned by the dispatcher(s) corresponding to the local endpoints.
24 // Its subclasses implement the three cases: local producer and consumer, local
25 // producer and remote consumer, and remote producer and local consumer. This
26 // class is thread-safe.
27 class MOJO_SYSTEM_IMPL_EXPORT DataPipe :
28 public base::RefCountedThreadSafe<DataPipe> {
29 public:
30 // These are called by the producer dispatcher to implement its methods of
31 // corresponding names.
32 void ProducerCancelAllWaiters();
33 void ProducerClose();
34 // This does not validate |elements| or |num_elements| (or |*num_elements|).
35 MojoResult ProducerWriteData(const void* elements,
36 uint32_t* num_elements,
37 MojoWriteDataFlags flags);
38 // This does not validate |buffer| or |buffer_num_elements|.
39 MojoResult ProducerBeginWriteData(void** buffer,
40 uint32_t* buffer_num_elements,
41 MojoWriteDataFlags flags);
42 MojoResult ProducerEndWriteData(uint32_t num_elements_written);
43 MojoResult ProducerAddWaiter(Waiter* waiter,
44 MojoWaitFlags flags,
45 MojoResult wake_result);
46 void ProducerRemoveWaiter(Waiter* waiter);
47
48 /* TODO(vtl)
49 void ConsumerCancelAllWaiters();
50 void ConsumerClose();
51 ...
52 MojoResult ConsumerAddWaiter(Waiter* waiter,
53 MojoWaitFlags flags,
54 MojoResult wake_result);
55 void ConsumerRemoveWaiter(Waiter* waiter);
56 */
57
58 // Thread-safe and fast (doesn't take the lock).
59 size_t element_size() const { return element_size_; }
60
61 protected:
62 DataPipe(bool has_local_producer, bool has_local_consumer);
63
64 void Init(size_t element_size);
65
66 virtual void ProducerCloseImplNoLock() = 0;
67 virtual MojoResult ProducerBeginWriteDataImplNoLock(
68 void** buffer,
69 uint32_t* buffer_num_elements,
70 MojoWriteDataFlags flags) = 0;
71 virtual MojoResult ProducerEndWriteDataImplNoLock(
72 uint32_t num_elements_written) = 0;
73 virtual MojoWaitFlags ProducerSatisfiedFlagsNoLock() = 0;
74 virtual MojoWaitFlags ProducerSatisfiableFlagsNoLock() = 0;
75
76 private:
77 friend class base::RefCountedThreadSafe<DataPipe>;
78 virtual ~DataPipe();
79
80 bool has_local_producer_no_lock() const {
81 return !!producer_waiter_list_.get();
82 }
83 bool has_local_consumer_no_lock() const {
84 return !!consumer_waiter_list_.get();
85 }
86
87 // Set by |Init()| and never changed afterwards.
88 size_t element_size_;
89
90 base::Lock lock_; // Protects the following members.
91 scoped_ptr<WaiterList> producer_waiter_list_;
92 scoped_ptr<WaiterList> consumer_waiter_list_;
93
94 DISALLOW_COPY_AND_ASSIGN(DataPipe);
95 };
96
97 } // namespace system
98 } // namespace mojo
99
100 #endif // MOJO_SYSTEM_DATA_PIPE_H_
OLDNEW
« no previous file with comments | « mojo/system/core_impl.cc ('k') | mojo/system/data_pipe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698