MCPcopy Create free account
hub / github.com/NVIDIA/stdexec / pop

Method pop

include/exec/static_thread_pool.hpp:1116–1171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1114 }
1115
1116 inline auto _static_thread_pool::thread_state::pop() //
1117 -> _static_thread_pool::thread_state::pop_result
1118 {
1119 pop_result result = try_pop();
1120 while (!result.task)
1121 {
1122 set_stealing();
1123 for (std::size_t i = 0; i < pool_->max_steals_; ++i)
1124 {
1125 result = try_steal_near();
1126 if (result.task)
1127 {
1128 clear_stealing();
1129 return result;
1130 }
1131 }
1132
1133 for (std::size_t i = 0; i < pool_->max_steals_; ++i)
1134 {
1135 result = try_steal_any();
1136 if (result.task)
1137 {
1138 clear_stealing();
1139 return result;
1140 }
1141 }
1142 std::this_thread::yield();
1143 clear_stealing();
1144
1145 std::unique_lock lock{mut_};
1146 if (stop_requested_)
1147 {
1148 return result;
1149 }
1150 state expected = state::running;
1151 if (state_.compare_exchange_weak(expected, state::sleeping, __std::memory_order_relaxed))
1152 {
1153 result = try_remote();
1154 if (result.task)
1155 {
1156 return result;
1157 }
1158 set_sleeping();
1159 cv_.wait(lock);
1160 lock.unlock();
1161 clear_sleeping();
1162 }
1163 if (lock.owns_lock())
1164 {
1165 lock.unlock();
1166 }
1167 state_.store(state::running, __std::memory_order_relaxed);
1168 result = try_pop();
1169 }
1170 return result;
1171 }
1172
1173 inline auto _static_thread_pool::thread_state::notify() -> bool

Callers 1

runMethod · 0.80

Calls 2

compare_exchange_weakMethod · 0.80
storeMethod · 0.45

Tested by

no test coverage detected