CThread.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \author Sebastien Grange
41  \version 3.2.0 $Rev: 1869 $
42 */
43 //==============================================================================
44 
45 //------------------------------------------------------------------------------
46 #ifndef CThreadH
47 #define CThreadH
48 //------------------------------------------------------------------------------
49 #include "system/CGlobals.h"
50 //------------------------------------------------------------------------------
51 
52 //------------------------------------------------------------------------------
53 namespace chai3d {
54 //------------------------------------------------------------------------------
55 
56 //==============================================================================
64 //==============================================================================
65 
66 //------------------------------------------------------------------------------
71 //------------------------------------------------------------------------------
73 {
74  CTHREAD_PRIORITY_GRAPHICS, // lower priority
75  CTHREAD_PRIORITY_HAPTICS // higher priority
76 };
77 
78 
79 //==============================================================================
98 //==============================================================================
99 
100 class cThread
101 {
102  //--------------------------------------------------------------------------
103  // CONSTRUCTOR & DESTRUCTOR:
104  //--------------------------------------------------------------------------
105 
106 public:
107 
109  cThread();
110 
112  virtual ~cThread();
113 
114 
115  //--------------------------------------------------------------------------
116  // PUBLIC METHODS:
117  //--------------------------------------------------------------------------
118 
119 public:
120 
122  void start(void(*a_function)(void ), const CThreadPriority a_level);
123 
125  void start(void(*a_function)(void*), const CThreadPriority a_level, void *a_arg);
126 
128  void stop();
129 
131  void setPriority(CThreadPriority a_level);
132 
135 
136 
137  //--------------------------------------------------------------------------
138  // PROTECTED MEMBERS:
139  //--------------------------------------------------------------------------
140 
141 protected:
142 
143 #if defined(WIN32) | defined(WIN64)
144  DWORD m_threadId;
146 #endif
147 
148 #if defined(LINUX) || defined(MACOSX)
149  pthread_t m_handle;
151 #endif
152 
154  void* m_function;
155 
158 };
159 
160 //------------------------------------------------------------------------------
161 } // namespace chai3d
162 //------------------------------------------------------------------------------
163 
164 //------------------------------------------------------------------------------
165 #endif
166 //------------------------------------------------------------------------------
CThreadPriority
Definition: CThread.h:72
Definition: CThread.h:74
DWORD m_threadId
Thread handle.
Definition: CThread.h:145
void setPriority(CThreadPriority a_level)
This method sets the thread priority level.
Definition: CThread.cpp:188
This class implements support for threads.
Definition: CThread.h:100
void * m_function
Pointer to thread function.
Definition: CThread.h:154
virtual ~cThread()
Destructor of cThread.
Definition: CThread.cpp:81
Definition: CThread.h:75
Implements option settings for CHAI3D.
void stop()
This method terminates the thread (not recommended!).
Definition: CThread.cpp:168
CThreadPriority m_priorityLevel
Thread priority level.
Definition: CThread.h:157
cThread()
Constructor of cThread.
Definition: CThread.cpp:58
Definition: CAudioBuffer.cpp:56
void start(void(*a_function)(void), const CThreadPriority a_level)
This method sets the thread parameters (and start it).
Definition: CThread.cpp:96
CThreadPriority getPriority() const
This method returns the current thread priority level.
Definition: CThread.h:134