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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once
 
#define MAX_THREAD        1
 
class CInspectThread;
 
class IThreadWorker
{
public:
    virtual BOOL OnThreadRun(int iThread, CInspectThread *pInspectThread)= 0;
    virtual BOOL OnThreadEnd(int iThread, CInspectThread *pInspectThread)= 0;
    virtual BOOL OnThreadEndAll()= 0;// must be calculated by the Function (OnThreadEnd())
};
 
class CInspectThread : public CWinThread
{
    DECLARE_DYNCREATE(CInspectThread)
protected:
    BOOL            m_bThreadRunning;
    CRITICAL_SECTION        m_csExit;
    volatile    BOOL        m_bRunning;
    BOOL            m_bWorking;
 
    int                m_iThread;
    int                m_iCamera;
 
    IThreadWorker    *m_pWorker;
 
public:
    CInspectThread();
    virtual ~CInspectThread();
    void SetWorker(IThreadWorker *pWorker){m_pWorker= pWorker;}
 
    BOOL StartThreadLoop(int iThread);    // Ãʱâ 
    void StartThreadWork(){m_bWorking= TRUE;}
 
    void StopThread();
    BOOL WaitThreadEnd(int ms= 0);
 
    BOOL IsRunning(){return m_bRunning;}
 
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CInspectionThread)
public:
    virtual BOOL InitInstance();
    virtual int ExitInstance();
    virtual int Run();
    //}}AFX_VIRTUAL
 
protected:
 
    // Generated message map functions
    //{{AFX_MSG(CInspectThread)
    // NOTE - the ClassWizard will add and remove member functions here.
    //}}AFX_MSG
 
    DECLARE_MESSAGE_MAP()
};
 
class CThreadControl : IThreadWorker
{
    int                m_nThreadLoop;        // »ý¼ºµÈ Thread Count
    int                m_nWorkingThread;    // µ¿ÀÛ[ÀÛ¾÷]À» ½ÃÀÛÇÑ Thread Count
    CInspectThread    *m_pThread;
 
    IThreadWorker    *m_pThreadWorker;
    CRITICAL_SECTION    m_csWorkingEnd;
 
public:
    CThreadControl(void);
    ~CThreadControl(void);
 
 
 
public:
 
    // 1. Thread ÀÚüÀÇ »ý¼º°ú ¼Ò¸ê¿¡ °ü¿©.
    int    InitThreadControl(int nThread, IThreadWorker* pThreadWorker);
    BOOL ReleaseThreadControl();
 
    // 2. Thread Loop ¾È¿¡¼­ ÀÛ¾÷ÀÇ Áö½Ã ¿©ºÎ¸¸ ÄÁÆ®·Ñ
    int    StartThreadControl();
    void StopThreadControl();
 
    // 
    int    GetThreadLoopCount(){return m_nThreadLoop;}
    int GetThreadWorkingCount(){return m_nWorkingThread;}
 
    // Implementation for Interface[IthreadWorker]
    BOOL OnThreadRun(int iThread, CInspectThread *pInspectThread);
    BOOL OnThreadEnd(int iThread, CInspectThread *pInspectThread);
    BOOL OnThreadEndAll();
 
};