blob: 500841dd5b8a56e2e05b5d66d688529abdd2faa6 (
plain) (
blame)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "coro.h"
#include "coro_stack.h"
#include <util/system/tls.h>
#include <util/system/yassert.h>
using namespace NRainCheck;
TContClosure TCoroTaskRunner::ContClosure(TCoroTaskRunner* runner, TArrayRef<char> memRegion) {
TContClosure contClosure;
contClosure.TrampoLine = runner;
contClosure.Stack = memRegion;
return contClosure;
}
TCoroTaskRunner::TCoroTaskRunner(IEnv* env, ISubtaskListener* parent, TAutoPtr<ICoroTask> impl)
: TTaskRunnerBase(env, parent, impl.Release())
, Stack(GetImpl()->StackSize)
, ContMachineContext(ContClosure(this, Stack.MemRegion()))
, CoroDone(false)
{
}
TCoroTaskRunner::~TCoroTaskRunner() {
Y_ASSERT(CoroDone);
}
Y_POD_STATIC_THREAD(TContMachineContext*)
CallerContext;
Y_POD_STATIC_THREAD(TCoroTaskRunner*)
Task;
bool TCoroTaskRunner::ReplyReceived() {
Y_ASSERT(!CoroDone);
TContMachineContext me;
CallerContext = &me;
Task = this;
me.SwitchTo(&ContMachineContext);
Stack.VerifyNoStackOverflow();
Y_ASSERT(CallerContext == &me);
Y_ASSERT(Task == this);
return !CoroDone;
}
void NRainCheck::TCoroTaskRunner::DoRun() {
GetImpl()->Run();
CoroDone = true;
ContMachineContext.SwitchTo(CallerContext);
}
void NRainCheck::ICoroTask::WaitForSubtasks() {
Task->ContMachineContext.SwitchTo(CallerContext);
}
|