• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2009-2015, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  *
32  * \file    WelsThread.h
33  *
34  * \brief   Interfaces introduced in threads
35  *
36  * \date    5/09/2012 Created
37  *
38  *************************************************************************************
39  */
40 
41 
42 #ifndef _WELS_THREAD_H_
43 #define _WELS_THREAD_H_
44 
45 
46 #include "macros.h"
47 #include "WelsLock.h"
48 #include "WelsThreadLib.h"
49 
50 namespace WelsCommon {
51 
52 class CWelsThread {
53  public:
54   CWelsThread();
55   virtual ~CWelsThread();
56 
57   virtual void Thread();
58   virtual void ExecuteTask() = 0;
59   virtual WELS_THREAD_ERROR_CODE Start();
60   virtual void Kill();
61   WELS_MUTEX          m_hMutex;
62  protected:
63   static WELS_THREAD_ROUTINE_TYPE  TheThread (void* pParam);
64 
SetRunning(bool bRunning)65   void SetRunning (bool bRunning) {
66     CWelsAutoLock  cLock (m_cLockStatus);
67 
68     m_bRunning = bRunning;
69   }
SetEndFlag(bool bEndFlag)70   void SetEndFlag (bool bEndFlag) {
71     CWelsAutoLock  cLock (m_cLockStatus);
72 
73     m_bEndFlag = bEndFlag;
74   }
75 
GetRunning()76   bool GetRunning() const {
77     return m_bRunning;
78   }
79 
GetEndFlag()80   bool GetEndFlag() const {
81     return m_bEndFlag;
82   }
83 
SignalThread()84   void SignalThread() {
85     WelsEventSignal (&m_hEvent, &m_hMutex, &m_iConVar);
86   }
87 
88  private:
89   WELS_THREAD_HANDLE  m_hThread;
90   WELS_EVENT          m_hEvent;
91   CWelsLock           m_cLockStatus;
92   bool                m_bRunning;
93   bool                m_bEndFlag;
94   int                 m_iConVar;
95 
96   DISALLOW_COPY_AND_ASSIGN (CWelsThread);
97 };
98 
99 
100 }
101 
102 
103 
104 #endif
105 
106 
107