本文整理汇总了C++中Thread::RunAfter方法的典型用法代码示例。如果您正苦于以下问题:C++ Thread::RunAfter方法的具体用法?C++ Thread::RunAfter怎么用?C++ Thread::RunAfter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread::RunAfter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OpenStateMachine
void MDT::OpenStateMachine(ThreadLocalData *tld)
{
Processor *p = tld->p;
Message *msg = tld->m;
FileObject *obj = (FileObject *)msg->req;
Thread *t = tld->t;
switch (tld->state) {
case mdt_OpenFileState:
/* It will take 5ms to open/create a new file. Very simple... */
t->RunAfter(params.io.OpenTicks + SignRand(params.io.OpenTicks / 10));
tld->state = mdt_OpenCompleteState;
break;
case mdt_OpenCompleteState:
Print(NOW "%s Finished OPEN for [email protected]%llu.\n",
now, name, obj->GetId());
msg->SetLength(1024);
Send(msg);
p->TaskCompletion(tld);
msg->phase = RPC_PHASE_COMPLETE;
break;
}
}
示例2: OneRun
void PIOS:: OneRun(run_arg *args)
{
Thread *t;
ThreadLocalData *tld;
args->fs = new FileSystem;
t = new Thread;
tld = new ThreadLocalData;
memset(tld, 0, sizeof(*tld));
tld->v = args;
tld->t = t;
Event::SetClock(0);
args->fs->Start();
t->CreateThread(do_one_run, tld);
t->RunAfter(1);
Event::Schedule();
delete args->fs;
delete tld;
delete t;
}
示例3: do_one_run
void PIOS::do_one_run(void *data)
{
ThreadLocalData *tld = (ThreadLocalData *) data;
run_arg *args = (run_arg *)tld->v;
switch (tld->state) {
case pios_RunOneStartState: {
int i;
args->startime = Event::Clock();
Print(NOW "Start run: T %lu N %llu C %llu S %llu O %llu\n",
args->startime, args->threadcount, args->regioncount,
args->chunksize, args->regionsize, args->offset);
/* Setup stream */
args->streams = new pios_stream [args->regioncount];
for (i = 0; i < args->regioncount; i++) {
if (args->fpp) {
args->streams[i].fid = i;
args->streams[i].offset = args->offset;
args->streams[i].max_offset = args->offset + args->regionsize;
args->num_open_files++;
} else {
args->streams[i].fid = 0;
args->streams[i].offset = args->offset * i;
args->streams[i].max_offset = args->offset * i + args->regionsize;
}
args->streams[i].iotime = 0;
}
/* Setup pios thread data */
args->ptds = new pios_thdata [args->threadcount];
args->tlds = new ThreadLocalData [args->threadcount];
memset(args->ptds, 0, sizeof(pios_thdata) * args->threadcount);
memset(args->tlds, 0, sizeof(ThreadLocalData) * args->threadcount);
for (i = 0; i < args->threadcount; i++) {
Thread *t;
t = new Thread;
args->ptds[i].parent = tld->t;
args->ptds[i].args = args;
args->ptds[i].io.cmd = WRITE;
args->ptds[i].io.count = 0;
args->ptds[i].io.fid = 0;
args->ptds[i].io.off = 0;
args->ptds[i].io.waiter = t;
args->ptds[i].io.left = 0;
args->ptds[i].io.parent = NULL;
args->ptds[i].io.ref = 0;
args->tlds[i].t = t;
args->tlds[i].id = i;
args->tlds[i].f = do_one_thread;
args->tlds[i].v = &args->ptds[i];
args->tlds[i].flags |= TLD_CTX_SWITCH;
t->CreateThread(do_one_thread, &args->tlds[i]);
t->RunAfter(/*Event::Rand(args->threadcount * 10)*/1);
}
tld->state = pios_RunOneAllFinishState;
break;
}
case pios_RunOneAllFinishState:
args->iotime = Event::Clock() - args->startime;
print_stats(args);
case pios_RunOneLastState:
/* cleanup all resource. */
delete [] args->streams;
delete [] args->ptds;
delete [] args->tlds;
break;
}
}