| 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/edk/system/wait_set_dispatcher.h" | 5 #include "mojo/edk/system/wait_set_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/edk/system/configuration.h" | 10 #include "mojo/edk/system/configuration.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 UserPointer<uint32_t> max_results) { | 254 UserPointer<uint32_t> max_results) { |
| 255 MutexLocker locker(&mutex()); | 255 MutexLocker locker(&mutex()); |
| 256 if (is_closed_no_lock()) | 256 if (is_closed_no_lock()) |
| 257 return MOJO_RESULT_INVALID_ARGUMENT; | 257 return MOJO_RESULT_INVALID_ARGUMENT; |
| 258 | 258 |
| 259 // TODO(vtl) | 259 // TODO(vtl) |
| 260 NOTIMPLEMENTED(); | 260 NOTIMPLEMENTED(); |
| 261 return MOJO_RESULT_UNIMPLEMENTED; | 261 return MOJO_RESULT_UNIMPLEMENTED; |
| 262 } | 262 } |
| 263 | 263 |
| 264 bool WaitSetDispatcher::Awake(MojoResult result, uint64_t context) { | 264 bool WaitSetDispatcher::Awake(uint64_t context, |
| 265 AwakeReason reason, |
| 266 const HandleSignalsState& signals_state) { |
| 265 MutexLocker locker(&mutex()); | 267 MutexLocker locker(&mutex()); |
| 266 | 268 |
| 267 if (is_closed_no_lock()) { | 269 if (is_closed_no_lock()) { |
| 268 // See |CloseImplNoLock()|: This case may occur while we're unlocked in | 270 // See |CloseImplNoLock()|: This case may occur while we're unlocked in |
| 269 // |CloseImplNoLock()| (after that, we will have been removed from all the | 271 // |CloseImplNoLock()| (after that, we will have been removed from all the |
| 270 // awakable lists, so |Awake()| should no longer be called). We may as well | 272 // awakable lists, so |Awake()| should no longer be called). We may as well |
| 271 // return false here, which will automatically remove ourselves from the | 273 // return false here, which will automatically remove ourselves from the |
| 272 // awakable list (|CloseImplNoLock()| will call | 274 // awakable list (|CloseImplNoLock()| will call |
| 273 // |RemoveAwakableWithContext()| anyway, but that's OK). | 275 // |RemoveAwakableWithContext()| anyway, but that's OK). |
| 274 return false; | 276 return false; |
| 275 } | 277 } |
| 276 | 278 |
| 277 auto it = entries_.find(context); | 279 auto it = entries_.find(context); |
| 278 DCHECK(it != entries_.end()); | 280 DCHECK(it != entries_.end()); |
| 279 const auto& entry = it->second; | 281 const auto& entry = it->second; |
| 280 switch (result) { | 282 switch (reason) { |
| 281 case MOJO_RESULT_OK: | 283 case AwakeReason::SATISFIED: |
| 282 if (entry->trigger_state == Entry::TriggerState::NOT_TRIGGERED) { | 284 if (entry->trigger_state == Entry::TriggerState::NOT_TRIGGERED) { |
| 283 AddPossiblyTriggeredNoLock(entry.get(), | 285 AddPossiblyTriggeredNoLock(entry.get(), |
| 284 Entry::TriggerState::POSSIBLY_SATISFIED); | 286 Entry::TriggerState::POSSIBLY_SATISFIED); |
| 285 } | 287 } |
| 286 return true; | 288 return true; |
| 287 case MOJO_RESULT_CANCELLED: | 289 case AwakeReason::UNSATISFIABLE: |
| 288 if (entry->trigger_state == Entry::TriggerState::NOT_TRIGGERED) { | |
| 289 AddPossiblyTriggeredNoLock(entry.get(), Entry::TriggerState::CLOSED); | |
| 290 } else { | |
| 291 // We should only ever get at most one "closed". | |
| 292 DCHECK_NE(static_cast<int>(entry->trigger_state), | |
| 293 static_cast<int>(Entry::TriggerState::CLOSED)); | |
| 294 entry->trigger_state = Entry::TriggerState::CLOSED; | |
| 295 } | |
| 296 entry->dispatcher = nullptr; | |
| 297 return false; | |
| 298 case MOJO_RESULT_FAILED_PRECONDITION: | |
| 299 // Never satisfiable. | 290 // Never satisfiable. |
| 300 if (entry->trigger_state == Entry::TriggerState::NOT_TRIGGERED) { | 291 if (entry->trigger_state == Entry::TriggerState::NOT_TRIGGERED) { |
| 301 AddPossiblyTriggeredNoLock(entry.get(), | 292 AddPossiblyTriggeredNoLock(entry.get(), |
| 302 Entry::TriggerState::NEVER_SATISFIABLE); | 293 Entry::TriggerState::NEVER_SATISFIABLE); |
| 303 } else { | 294 } else { |
| 304 if (entry->trigger_state == Entry::TriggerState::POSSIBLY_SATISFIED) { | 295 if (entry->trigger_state == Entry::TriggerState::POSSIBLY_SATISFIED) { |
| 305 entry->trigger_state = Entry::TriggerState::NEVER_SATISFIABLE; | 296 entry->trigger_state = Entry::TriggerState::NEVER_SATISFIABLE; |
| 306 } else { | 297 } else { |
| 307 // It's possible to get repeated "never satisfiable" triggers, but we | 298 // It's possible to get repeated "never satisfiable" triggers, but we |
| 308 // shouldn't get anything after "closed". | 299 // shouldn't get anything after "closed". |
| 309 DCHECK_NE(static_cast<int>(entry->trigger_state), | 300 DCHECK_NE(static_cast<int>(entry->trigger_state), |
| 310 static_cast<int>(Entry::TriggerState::CLOSED)); | 301 static_cast<int>(Entry::TriggerState::CLOSED)); |
| 311 } | 302 } |
| 312 } | 303 } |
| 313 // Due to some action on some other thread, it may become satisfiable | 304 // Due to some action on some other thread, it may become satisfiable |
| 314 // again, so continue to be awoken. | 305 // again, so continue to be awoken. |
| 315 return true; | 306 return true; |
| 316 default: | 307 case AwakeReason::CANCELLED: |
| 317 NOTREACHED(); | 308 if (entry->trigger_state == Entry::TriggerState::NOT_TRIGGERED) { |
| 318 break; | 309 AddPossiblyTriggeredNoLock(entry.get(), Entry::TriggerState::CLOSED); |
| 310 } else { |
| 311 // We should only ever get at most one "closed". |
| 312 DCHECK_NE(static_cast<int>(entry->trigger_state), |
| 313 static_cast<int>(Entry::TriggerState::CLOSED)); |
| 314 entry->trigger_state = Entry::TriggerState::CLOSED; |
| 315 } |
| 316 entry->dispatcher = nullptr; |
| 317 return false; |
| 319 } | 318 } |
| 320 return false; | 319 return false; |
| 321 } | 320 } |
| 322 | 321 |
| 323 void WaitSetDispatcher::AddPossiblyTriggeredNoLock( | 322 void WaitSetDispatcher::AddPossiblyTriggeredNoLock( |
| 324 Entry* entry, | 323 Entry* entry, |
| 325 Entry::TriggerState new_trigger_state) { | 324 Entry::TriggerState new_trigger_state) { |
| 326 DCHECK_EQ(static_cast<int>(entry->trigger_state), | 325 DCHECK_EQ(static_cast<int>(entry->trigger_state), |
| 327 static_cast<int>(Entry::TriggerState::NOT_TRIGGERED)); | 326 static_cast<int>(Entry::TriggerState::NOT_TRIGGERED)); |
| 328 DCHECK(!entry->possibly_triggered_previous); | 327 DCHECK(!entry->possibly_triggered_previous); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 entry->possibly_triggered_next->possibly_triggered_previous = | 367 entry->possibly_triggered_next->possibly_triggered_previous = |
| 369 entry->possibly_triggered_previous; | 368 entry->possibly_triggered_previous; |
| 370 } | 369 } |
| 371 | 370 |
| 372 entry->possibly_triggered_previous = nullptr; | 371 entry->possibly_triggered_previous = nullptr; |
| 373 entry->possibly_triggered_next = nullptr; | 372 entry->possibly_triggered_next = nullptr; |
| 374 } | 373 } |
| 375 | 374 |
| 376 } // namespace system | 375 } // namespace system |
| 377 } // namespace mojo | 376 } // namespace mojo |
| OLD | NEW |