misc/libphysfs/lzma/CPP/7zip/Common/VirtThread.cpp
author antonc27 <antonc27@mail.ru>
Sun, 18 Mar 2018 18:47:03 +0100
branchios-develop
changeset 13250 195208deff1d
parent 12218 bb5522e88ab2
permissions -rw-r--r--
- Correct initialisation of TeamsGameOver (on mobile it doesn't get reset between plays, so ones set to true, prevents game to be finished next time)

// VirtThread.cpp

#include "StdAfx.h"

#include "VirtThread.h"

static THREAD_FUNC_DECL CoderThread(void *p)
{
  for (;;)
  {
    CVirtThread *t = (CVirtThread *)p;
    t->StartEvent.Lock();
    if (t->ExitEvent)
      return 0;
    t->Execute();
    t->FinishedEvent.Set();
  }
}

HRes CVirtThread::Create()
{
  RINOK(StartEvent.CreateIfNotCreated());
  RINOK(FinishedEvent.CreateIfNotCreated());
  StartEvent.Reset();
  FinishedEvent.Reset();
  ExitEvent = false;
  if (Thread.IsCreated())
    return S_OK;
  return Thread.Create(CoderThread, this);
}

void CVirtThread::Start()
{
  ExitEvent = false;
  StartEvent.Set();
}

CVirtThread::~CVirtThread()
{
  ExitEvent = true;
  if (StartEvent.IsCreated())
    StartEvent.Set();
  Thread.Wait();
}