Line data Source code
1 : #include "source/extensions/common/async_files/async_file_action.h" 2 : 3 : #include <thread> 4 : 5 : namespace Envoy { 6 : namespace Extensions { 7 : namespace Common { 8 : namespace AsyncFiles { 9 : 10 0 : void AsyncFileAction::cancel() { 11 0 : auto previousState = state_.exchange(State::Cancelled); 12 0 : if (previousState == State::InCallback) { 13 : // A gentle spin-lock. This situation should be rare, and callbacks are 14 : // supposed to be quick, so we don't need a real lock here. 15 0 : while (state_.load() != State::Done) { 16 0 : std::this_thread::yield(); 17 0 : } 18 0 : } else if (previousState == State::Done) { 19 0 : state_.store(State::Done); 20 0 : } 21 0 : } 22 : 23 : } // namespace AsyncFiles 24 : } // namespace Common 25 : } // namespace Extensions 26 : } // namespace Envoy