File: IExecutionContext.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (30 lines) | stat: -rw-r--r-- 1,054 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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