Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/edk/system/watcher_set.h" | |
| 6 | |
| 7 #include "mojo/public/c/system/types.h" | |
| 8 | |
| 9 namespace mojo { | |
| 10 namespace edk { | |
| 11 | |
| 12 WatcherSet::WatcherSet() {} | |
| 13 | |
| 14 WatcherSet::~WatcherSet() {} | |
| 15 | |
| 16 void WatcherSet::NotifyForStateChange(const HandleSignalsState& state) { | |
| 17 for (const auto& entry : watchers_) { | |
| 18 entry.second->NotifyForStateChange( | |
| 19 static_cast<MojoHandleSignalsState>(state)); | |
| 20 } | |
| 21 } | |
| 22 | |
| 23 void WatcherSet::NotifyClosed() { | |
| 24 for (const auto& entry : watchers_) | |
| 25 entry.second->NotifyClosed(); | |
| 26 } | |
| 27 | |
| 28 MojoResult WatcherSet::Add(MojoHandleSignals signals, | |
| 29 const Watcher::WatchCallback& callback, | |
| 30 uintptr_t context, | |
| 31 const HandleSignalsState& current_state) { | |
| 32 auto it = watchers_.find(context); | |
| 33 if (it != watchers_.end()) | |
| 34 return MOJO_RESULT_ALREADY_EXISTS; | |
| 35 | |
| 36 if (!current_state.can_satisfy(signals)) | |
| 37 return MOJO_RESULT_FAILED_PRECONDITION; | |
| 38 | |
| 39 scoped_refptr<Watcher> watcher(new Watcher(signals, callback)); | |
| 40 watchers_.insert(std::make_pair(context, watcher)); | |
| 41 | |
| 42 watcher->NotifyForStateChange(current_state); | |
| 43 | |
| 44 return MOJO_RESULT_OK; | |
| 45 } | |
| 46 | |
| 47 MojoResult WatcherSet::Remove(uintptr_t context) { | |
| 48 auto it = watchers_.find(context); | |
| 49 if (it == watchers_.end()) | |
| 50 return MOJO_RESULT_INVALID_ARGUMENT; | |
| 51 | |
| 52 it->second->Cancel(); | |
|
Anand Mistry (off Chromium)
2016/03/01 07:30:40
Hmm. There's a potential deadlock here. If on thre
Ken Rockot(use gerrit already)
2016/03/01 08:17:44
Good catch. I've changed this so that cancellation
| |
| 53 watchers_.erase(it); | |
| 54 return MOJO_RESULT_OK; | |
| 55 } | |
| 56 | |
| 57 } // namespace edk | |
| 58 } // namespace mojo | |
| OLD | NEW |