mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 13:15:04 -06:00
4.48 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
0b33f700a6
commit
fd8b1d78b4
45
CPP/7zip/Common/VirtThread.cpp
Executable file
45
CPP/7zip/Common/VirtThread.cpp
Executable file
@@ -0,0 +1,45 @@
|
||||
// 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user