SDC C-Project CF Review 프로그램
LYW
2021-11-15 4139a71f5c0b72f88813a15d7112fdac76756fe4
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
61
62
63
64
65
66
67
#include "StdAfx.h"
#include "WaitThreadPools.h"
 
CWaitThreadPools::CWaitThreadPools(int nThreadCount) : CThreadPools(nThreadCount)
{
    m_pWait                = NULL;
    m_pWaitCallback        = WaitCallback;
 
    m_hEvent            = CreateEvent(NULL, FALSE, FALSE, NULL);
}
 
CWaitThreadPools::~CWaitThreadPools(void)
{
    CloseWaitThread();
 
    CloseHandle(m_hEvent);
}
 
VOID CALLBACK CWaitThreadPools::WaitCallback(PTP_CALLBACK_INSTANCE pInstance, PVOID pParameter, PTP_WAIT pWait, TP_WAIT_RESULT WaitResult)
{
    // Instance, Parameter, and Work not used in this example.
    UNREFERENCED_PARAMETER(pInstance);
    UNREFERENCED_PARAMETER(pParameter);
    UNREFERENCED_PARAMETER(pWait);
    UNREFERENCED_PARAMETER(WaitResult);
 
    return;
}
 
BOOL CWaitThreadPools::CreateWaitThread(PVOID pParameter)
{
    if (NULL==m_pPool || NULL==m_pCleanupGroup) return FALSE;
 
    TP_CALLBACK_ENVIRON* pCallBackEnviron = (TP_CALLBACK_ENVIRON*)&m_CallBackEnviron;
 
    PTP_WAIT pWait = CreateThreadpoolWait((PTP_WAIT_CALLBACK)WaitCallback, pParameter, pCallBackEnviron);
    if (NULL==pWait) return FALSE;
 
    SetThreadpoolWait(pWait, m_hEvent, NULL);
 
    return TRUE;
}
 
void CWaitThreadPools::CloseWaitThread()
{
    if (NULL==m_pWait) return;
 
    WaitForThreadpoolWaitCallbacks(m_pWait, TRUE);
 
    CloseThreadpoolWait(m_pWait);
 
    m_pWait = NULL;
}
 
BOOL CWaitThreadPools::SetEvent1()
{
    if (m_hEvent==NULL) return FALSE;
 
    return SetEvent(m_hEvent);
}
 
BOOL CWaitThreadPools::ResetEvent1()
{
    if (m_hEvent==NULL) return FALSE;
 
    return ResetEvent(m_hEvent);
}