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 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" | 5 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 | 10 |
11 SyncHandleWatcher::SyncHandleWatcher( | 11 SyncHandleWatcher::SyncHandleWatcher( |
12 const Handle& handle, | 12 const Handle& handle, |
13 MojoHandleSignals handle_signals, | 13 MojoHandleSignals handle_signals, |
14 const SyncHandleRegistry::HandleCallback& callback) | 14 const SyncHandleRegistry::HandleCallback& callback) |
15 : handle_(handle), | 15 : handle_(handle), |
16 handle_signals_(handle_signals), | 16 handle_signals_(handle_signals), |
17 callback_(callback), | 17 callback_(callback), |
18 registered_(false), | 18 registered_(false), |
19 register_request_count_(0), | 19 register_request_count_(0), |
20 registry_(SyncHandleRegistry::current()), | 20 registry_(SyncHandleRegistry::current()), |
21 destroyed_(new base::RefCountedData<bool>(false)) {} | 21 destroyed_(new base::RefCountedData<bool>(false)) {} |
22 | 22 |
23 SyncHandleWatcher::~SyncHandleWatcher() { | 23 SyncHandleWatcher::~SyncHandleWatcher() { |
24 DCHECK(thread_checker_.CalledOnValidThread()); | 24 DCHECK(sequence_checker_.CalledOnValidSequence()); |
25 if (registered_) | 25 if (registered_) |
26 registry_->UnregisterHandle(handle_); | 26 registry_->UnregisterHandle(handle_); |
27 | 27 |
28 destroyed_->data = true; | 28 destroyed_->data = true; |
29 } | 29 } |
30 | 30 |
31 void SyncHandleWatcher::AllowWokenUpBySyncWatchOnSameThread() { | 31 void SyncHandleWatcher::AllowWokenUpBySyncWatchOnSameThread() { |
32 DCHECK(thread_checker_.CalledOnValidThread()); | 32 DCHECK(sequence_checker_.CalledOnValidSequence()); |
33 IncrementRegisterCount(); | 33 IncrementRegisterCount(); |
34 } | 34 } |
35 | 35 |
36 bool SyncHandleWatcher::SyncWatch(const bool* should_stop) { | 36 bool SyncHandleWatcher::SyncWatch(const bool* should_stop) { |
37 DCHECK(thread_checker_.CalledOnValidThread()); | 37 DCHECK(sequence_checker_.CalledOnValidSequence()); |
38 IncrementRegisterCount(); | 38 IncrementRegisterCount(); |
39 if (!registered_) { | 39 if (!registered_) { |
40 DecrementRegisterCount(); | 40 DecrementRegisterCount(); |
41 return false; | 41 return false; |
42 } | 42 } |
43 | 43 |
44 // This object may be destroyed during the WatchAllHandles() call. So we have | 44 // This object may be destroyed during the WatchAllHandles() call. So we have |
45 // to preserve the boolean that WatchAllHandles uses. | 45 // to preserve the boolean that WatchAllHandles uses. |
46 auto destroyed = destroyed_; | 46 auto destroyed = destroyed_; |
47 const bool* should_stop_array[] = {should_stop, &destroyed->data}; | 47 const bool* should_stop_array[] = {should_stop, &destroyed->data}; |
(...skipping 19 matching lines...) Expand all Loading... |
67 DCHECK_GT(register_request_count_, 0u); | 67 DCHECK_GT(register_request_count_, 0u); |
68 | 68 |
69 register_request_count_--; | 69 register_request_count_--; |
70 if (register_request_count_ == 0 && registered_) { | 70 if (register_request_count_ == 0 && registered_) { |
71 registry_->UnregisterHandle(handle_); | 71 registry_->UnregisterHandle(handle_); |
72 registered_ = false; | 72 registered_ = false; |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 } // namespace mojo | 76 } // namespace mojo |
OLD | NEW |