OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_PUBLIC_CPP_BINDINGS_SYNC_HANDLE_WATCHER_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_SYNC_HANDLE_WATCHER_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_SYNC_HANDLE_WATCHER_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_SYNC_HANDLE_WATCHER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
| 11 #include "mojo/public/cpp/bindings/bindings_export.h" |
11 #include "mojo/public/cpp/bindings/sync_handle_registry.h" | 12 #include "mojo/public/cpp/bindings/sync_handle_registry.h" |
12 #include "mojo/public/cpp/system/core.h" | 13 #include "mojo/public/cpp/system/core.h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 | 16 |
16 // SyncHandleWatcher supports watching a handle synchronously. It also supports | 17 // SyncHandleWatcher supports watching a handle synchronously. It also supports |
17 // registering the handle with a thread-local storage (SyncHandleRegistry), so | 18 // registering the handle with a thread-local storage (SyncHandleRegistry), so |
18 // that when other SyncHandleWatcher instances on the same thread perform sync | 19 // that when other SyncHandleWatcher instances on the same thread perform sync |
19 // handle watching, this handle will be watched together. | 20 // handle watching, this handle will be watched together. |
20 // | 21 // |
21 // SyncHandleWatcher is used for sync methods. While a sync call is waiting for | 22 // SyncHandleWatcher is used for sync methods. While a sync call is waiting for |
22 // response, we would like to block the thread. On the other hand, we need | 23 // response, we would like to block the thread. On the other hand, we need |
23 // incoming sync method requests on the same thread to be able to reenter. We | 24 // incoming sync method requests on the same thread to be able to reenter. We |
24 // also need master interface endpoints to continue dispatching messages for | 25 // also need master interface endpoints to continue dispatching messages for |
25 // associated endpoints on different threads. | 26 // associated endpoints on different threads. |
26 // | 27 // |
27 // This class is not thread safe. | 28 // This class is not thread safe. |
28 class SyncHandleWatcher { | 29 class MOJO_CPP_BINDINGS_EXPORT SyncHandleWatcher { |
29 public: | 30 public: |
30 // Note: |handle| must outlive this object. | 31 // Note: |handle| must outlive this object. |
31 SyncHandleWatcher(const Handle& handle, | 32 SyncHandleWatcher(const Handle& handle, |
32 MojoHandleSignals handle_signals, | 33 MojoHandleSignals handle_signals, |
33 const SyncHandleRegistry::HandleCallback& callback); | 34 const SyncHandleRegistry::HandleCallback& callback); |
34 | 35 |
35 ~SyncHandleWatcher(); | 36 ~SyncHandleWatcher(); |
36 | 37 |
37 // Registers |handle_| with SyncHandleRegistry, so that when others perform | 38 // Registers |handle_| with SyncHandleRegistry, so that when others perform |
38 // sync handle watching on the same thread, |handle_| will be watched | 39 // sync handle watching on the same thread, |handle_| will be watched |
(...skipping 26 matching lines...) Expand all Loading... |
65 scoped_refptr<base::RefCountedData<bool>> destroyed_; | 66 scoped_refptr<base::RefCountedData<bool>> destroyed_; |
66 | 67 |
67 base::ThreadChecker thread_checker_; | 68 base::ThreadChecker thread_checker_; |
68 | 69 |
69 DISALLOW_COPY_AND_ASSIGN(SyncHandleWatcher); | 70 DISALLOW_COPY_AND_ASSIGN(SyncHandleWatcher); |
70 }; | 71 }; |
71 | 72 |
72 } // namespace mojo | 73 } // namespace mojo |
73 | 74 |
74 #endif // MOJO_PUBLIC_CPP_BINDINGS_SYNC_HANDLE_WATCHER_H_ | 75 #endif // MOJO_PUBLIC_CPP_BINDINGS_SYNC_HANDLE_WATCHER_H_ |
OLD | NEW |