| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/core.h" | 5 #include "mojo/edk/system/core.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 MojoResult Core::AsyncWait(MojoHandle handle, | 140 MojoResult Core::AsyncWait(MojoHandle handle, |
| 141 MojoHandleSignals signals, | 141 MojoHandleSignals signals, |
| 142 const std::function<void(MojoResult)>& callback) { | 142 const std::function<void(MojoResult)>& callback) { |
| 143 RefPtr<Dispatcher> dispatcher; | 143 RefPtr<Dispatcher> dispatcher; |
| 144 MojoResult result = GetDispatcherAndCheckRights( | 144 MojoResult result = GetDispatcherAndCheckRights( |
| 145 handle, MOJO_HANDLE_RIGHT_NONE, EntrypointClass::NONE, &dispatcher); | 145 handle, MOJO_HANDLE_RIGHT_NONE, EntrypointClass::NONE, &dispatcher); |
| 146 if (result != MOJO_RESULT_OK) | 146 if (result != MOJO_RESULT_OK) |
| 147 return result; | 147 return result; |
| 148 | 148 |
| 149 std::unique_ptr<AsyncWaiter> waiter(new AsyncWaiter(callback)); | 149 std::unique_ptr<AsyncWaiter> waiter(new AsyncWaiter(callback)); |
| 150 result = dispatcher->AddAwakable(waiter.get(), signals, 0, nullptr); | 150 result = dispatcher->AddAwakable(waiter.get(), 0, false, signals, nullptr); |
| 151 if (result == MOJO_RESULT_OK) | 151 if (result == MOJO_RESULT_OK) |
| 152 ignore_result(waiter.release()); | 152 ignore_result(waiter.release()); |
| 153 return result; | 153 return result; |
| 154 } | 154 } |
| 155 | 155 |
| 156 MojoTimeTicks Core::GetTimeTicksNow() { | 156 MojoTimeTicks Core::GetTimeTicksNow() { |
| 157 return GetTimeTicks(); | 157 return GetTimeTicks(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 MojoResult Core::Close(MojoHandle handle) { | 160 MojoResult Core::Close(MojoHandle handle) { |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 return MOJO_RESULT_OK; | 745 return MOJO_RESULT_OK; |
| 746 } | 746 } |
| 747 | 747 |
| 748 MojoResult Core::UnmapBuffer(UserPointer<void> buffer) { | 748 MojoResult Core::UnmapBuffer(UserPointer<void> buffer) { |
| 749 MutexLocker locker(&mapping_table_mutex_); | 749 MutexLocker locker(&mapping_table_mutex_); |
| 750 return mapping_table_.RemoveMapping(buffer.GetPointerValue()); | 750 return mapping_table_.RemoveMapping(buffer.GetPointerValue()); |
| 751 } | 751 } |
| 752 | 752 |
| 753 // Note: We allow |handles| to repeat the same handle multiple times, since | 753 // Note: We allow |handles| to repeat the same handle multiple times, since |
| 754 // different flags may be specified. | 754 // different flags may be specified. |
| 755 // TODO(vtl): This incurs a performance cost in |Remove()|. Analyze this | |
| 756 // more carefully and address it if necessary. | |
| 757 MojoResult Core::WaitManyInternal(const MojoHandle* handles, | 755 MojoResult Core::WaitManyInternal(const MojoHandle* handles, |
| 758 const MojoHandleSignals* signals, | 756 const MojoHandleSignals* signals, |
| 759 uint32_t num_handles, | 757 uint32_t num_handles, |
| 760 MojoDeadline deadline, | 758 MojoDeadline deadline, |
| 761 uint64_t* result_index, | 759 uint64_t* result_index, |
| 762 HandleSignalsState* signals_states) { | 760 HandleSignalsState* signals_states) { |
| 763 DCHECK_GT(num_handles, 0u); | 761 DCHECK_GT(num_handles, 0u); |
| 764 DCHECK_EQ(*result_index, static_cast<uint64_t>(-1)); | 762 DCHECK_EQ(*result_index, static_cast<uint64_t>(-1)); |
| 765 | 763 |
| 766 DispatcherVector dispatchers; | 764 DispatcherVector dispatchers; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 785 } | 783 } |
| 786 | 784 |
| 787 // TODO(vtl): Should make the waiter live (permanently) in TLS. | 785 // TODO(vtl): Should make the waiter live (permanently) in TLS. |
| 788 Waiter waiter; | 786 Waiter waiter; |
| 789 waiter.Init(); | 787 waiter.Init(); |
| 790 | 788 |
| 791 uint32_t i; | 789 uint32_t i; |
| 792 MojoResult result = MOJO_RESULT_OK; | 790 MojoResult result = MOJO_RESULT_OK; |
| 793 for (i = 0; i < num_handles; i++) { | 791 for (i = 0; i < num_handles; i++) { |
| 794 result = dispatchers[i]->AddAwakable( | 792 result = dispatchers[i]->AddAwakable( |
| 795 &waiter, signals[i], i, signals_states ? &signals_states[i] : nullptr); | 793 &waiter, i, false, signals[i], |
| 794 signals_states ? &signals_states[i] : nullptr); |
| 796 if (result != MOJO_RESULT_OK) { | 795 if (result != MOJO_RESULT_OK) { |
| 797 *result_index = i; | 796 *result_index = i; |
| 798 break; | 797 break; |
| 799 } | 798 } |
| 800 } | 799 } |
| 801 uint32_t num_added = i; | 800 uint32_t num_added = i; |
| 802 | 801 |
| 803 if (result == MOJO_RESULT_ALREADY_EXISTS) | 802 if (result == MOJO_RESULT_ALREADY_EXISTS) |
| 804 result = MOJO_RESULT_OK; // The i-th one is already "triggered". | 803 result = MOJO_RESULT_OK; // The i-th one is already "triggered". |
| 805 else if (result == MOJO_RESULT_OK) | 804 else if (result == MOJO_RESULT_OK) |
| 806 result = waiter.Wait(deadline, result_index, nullptr); | 805 result = waiter.Wait(deadline, result_index, nullptr); |
| 807 | 806 |
| 808 // Make sure no other dispatchers try to wake |waiter| for the current | 807 // Make sure no other dispatchers try to wake |waiter| for the current |
| 809 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be | 808 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be |
| 810 // destroyed, but this would still be required if the waiter were in TLS.) | 809 // destroyed, but this would still be required if the waiter were in TLS.) |
| 811 for (i = 0; i < num_added; i++) { | 810 for (i = 0; i < num_added; i++) { |
| 812 dispatchers[i]->RemoveAwakable( | 811 dispatchers[i]->RemoveAwakable( |
| 813 &waiter, signals_states ? &signals_states[i] : nullptr); | 812 false, &waiter, 0, signals_states ? &signals_states[i] : nullptr); |
| 814 } | 813 } |
| 815 if (signals_states) { | 814 if (signals_states) { |
| 816 for (; i < num_handles; i++) | 815 for (; i < num_handles; i++) |
| 817 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); | 816 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); |
| 818 } | 817 } |
| 819 | 818 |
| 820 return result; | 819 return result; |
| 821 } | 820 } |
| 822 | 821 |
| 823 } // namespace system | 822 } // namespace system |
| 824 } // namespace mojo | 823 } // namespace mojo |
| OLD | NEW |