OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/threading/sequenced_worker_pool.h" | 5 #include "base/threading/sequenced_worker_pool.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 int max_new_blocking_tasks_after_shutdown) { | 917 int max_new_blocking_tasks_after_shutdown) { |
918 DCHECK_GE(max_new_blocking_tasks_after_shutdown, 0); | 918 DCHECK_GE(max_new_blocking_tasks_after_shutdown, 0); |
919 { | 919 { |
920 AutoLock lock(lock_); | 920 AutoLock lock(lock_); |
921 // Cleanup and Shutdown should not be called concurrently. | 921 // Cleanup and Shutdown should not be called concurrently. |
922 CHECK_EQ(CLEANUP_DONE, cleanup_state_); | 922 CHECK_EQ(CLEANUP_DONE, cleanup_state_); |
923 if (shutdown_called_) | 923 if (shutdown_called_) |
924 return; | 924 return; |
925 shutdown_called_ = true; | 925 shutdown_called_ = true; |
926 | 926 |
927 max_blocking_tasks_after_shutdown_ = max_new_blocking_tasks_after_shutdown; | |
928 | |
927 if (subtle::NoBarrier_Load(&g_all_pools_state) != | 929 if (subtle::NoBarrier_Load(&g_all_pools_state) != |
928 AllPoolsState::WORKER_CREATED) | 930 AllPoolsState::WORKER_CREATED) { |
929 return; | 931 return; |
930 | 932 } |
931 max_blocking_tasks_after_shutdown_ = max_new_blocking_tasks_after_shutdown; | |
932 | 933 |
933 // Tickle the threads. This will wake up a waiting one so it will know that | 934 // Tickle the threads. This will wake up a waiting one so it will know that |
934 // it can exit, which in turn will wake up any other waiting ones. | 935 // it can exit, which in turn will wake up any other waiting ones. |
935 SignalHasWork(); | 936 SignalHasWork(); |
936 | 937 |
937 // There are no pending or running tasks blocking shutdown, we're done. | 938 // There are no pending or running tasks blocking shutdown, we're done. |
938 if (CanShutdown()) | 939 if (CanShutdown()) |
939 return; | 940 return; |
940 } | 941 } |
941 | 942 |
942 // If we're here, then something is blocking shutdown. So wait for | 943 // If we're here, then something is blocking shutdown. So wait for |
943 // CanShutdown() to go to true. | 944 // CanShutdown() to go to true. |
944 | 945 |
945 if (testing_observer_) | 946 if (testing_observer_) |
946 testing_observer_->WillWaitForShutdown(); | 947 testing_observer_->WillWaitForShutdown(); |
947 | 948 |
948 #if !defined(OS_NACL) | 949 #if !defined(OS_NACL) |
949 TimeTicks shutdown_wait_begin = TimeTicks::Now(); | 950 TimeTicks shutdown_wait_begin = TimeTicks::Now(); |
950 #endif | 951 #endif |
951 | 952 |
952 { | 953 { |
953 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 954 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
954 AutoLock lock(lock_); | 955 AutoLock lock(lock_); |
955 while (!CanShutdown()) | 956 while (!CanShutdown()) |
956 can_shutdown_cv_.Wait(); | 957 can_shutdown_cv_.Wait(); |
957 } | 958 } |
958 #if !defined(OS_NACL) | 959 #if !defined(OS_NACL) |
959 UMA_HISTOGRAM_TIMES("SequencedWorkerPool.ShutdownDelayTime", | 960 UMA_HISTOGRAM_TIMES("SequencedWorkerPool.ShutdownDelayTime", |
robliao
2016/10/03 19:58:35
Not required for this CL: Do we care that this his
fdoray
2016/10/03 20:13:41
If we care about this, we should have a similar hi
gab
2016/10/03 20:16:43
I think it makes more sense that it doesn't make i
gab
2016/10/03 20:17:16
That I think we indeed should.
| |
960 TimeTicks::Now() - shutdown_wait_begin); | 961 TimeTicks::Now() - shutdown_wait_begin); |
961 #endif | 962 #endif |
962 } | 963 } |
963 | 964 |
964 bool SequencedWorkerPool::Inner::IsShutdownInProgress() { | 965 bool SequencedWorkerPool::Inner::IsShutdownInProgress() { |
965 AutoLock lock(lock_); | 966 AutoLock lock(lock_); |
966 return shutdown_called_; | 967 return shutdown_called_; |
967 } | 968 } |
968 | 969 |
969 void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { | 970 void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) { |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1620 bool SequencedWorkerPool::IsShutdownInProgress() { | 1621 bool SequencedWorkerPool::IsShutdownInProgress() { |
1621 return inner_->IsShutdownInProgress(); | 1622 return inner_->IsShutdownInProgress(); |
1622 } | 1623 } |
1623 | 1624 |
1624 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( | 1625 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( |
1625 SequenceToken sequence_token) const { | 1626 SequenceToken sequence_token) const { |
1626 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); | 1627 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); |
1627 } | 1628 } |
1628 | 1629 |
1629 } // namespace base | 1630 } // namespace base |
OLD | NEW |