Files
fs2open.github.com/code/executor/IExecutionContext.cpp
T
asarium 614a636ed5 Fix clang-tidy issues
Not sure why travis saw these since I didn't change anything there but
fixing these is also good.
2020-06-06 23:24:08 +02:00

31 lines
1.0 KiB
C++

#include "IExecutionContext.h"
namespace executor {
Executor::Callback runInContext(const std::shared_ptr<IExecutionContext>& context,
const IExecutionContext::Callback& func)
{
return [context, func]() {
const auto ctxState = context->determineContextState();
switch (ctxState) {
case IExecutionContext::State::Valid:
// We are in a valid state so execute our wrapped function
return func(IExecutionContext::State::Valid);
case IExecutionContext::State::Suspended:
// The state is not valid but my return so keep this function alive
return Executor::CallbackResult::Reschedule;
case IExecutionContext::State::Invalid:
// Call the function once more to let it know that the state became invalid
func(IExecutionContext::State::Invalid);
// This state will not become valid again so we do not need to be rescheduled
return Executor::CallbackResult::Done;
default:
UNREACHABLE("Unhandled context state %d", static_cast<int>(ctxState));
return Executor::CallbackResult::Done;
}
};
}
} // namespace executor