summaryrefslogtreecommitdiff
path: root/source/utilities/CaptiveThreadObject.cpp
blob: e9eb472415b06fc5a0c218baf4ceeb8932977bc8 (plain)
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
/*******************************************************************************
*
*    File name: CaptiveThreadObject.cpp
*     Language: Visual C++
*  Description: Captive Thread Object class definitions
*
*
* Copyright (C) ST-Ericsson SA 2011
* License terms: 3-clause BSD license
*
*******************************************************************************/

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                          File CaptiveThreadObject.cpp

#include "CaptiveThreadObject.h"

CCaptiveThreadObject::CCaptiveThreadObject()
    : IsDying(0),
#pragma warning(disable: 4355) // 'this' used before initialized but ok as thread starts in inactive state
      Thread(ThreadEntry, this)
{
}
#pragma warning(default: 4355)

CCaptiveThreadObject::~CCaptiveThreadObject()
{
}

void CCaptiveThreadObject::EndCaptiveThread()
{
    IsDying++;
    SignalDeath();
    Thread.WaitToDie();
}


// ThreadEntry - Entry point, executed by captive thread
#ifdef _WIN32
unsigned int WINAPI CCaptiveThreadObject::ThreadEntry(void *arg)
#else
void *CCaptiveThreadObject::ThreadEntry(void *arg)
#endif
{
    CCaptiveThreadObject *pThis = static_cast<CCaptiveThreadObject *>(arg);
    pThis->InitializeCaptiveThreadObject();
    pThis->MainExecutionLoop();
    return 0;
}
//                                                                                   End of file CaptiveThreadObject.cpp
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////