80 typedef shared_ptr<class GThread>
Ref;
89 static GThreadRef
create(
const std::string&
name,
void (*proc)(
void*),
void* param =
NULL);
162 template<
class Class>
167 void (Class::*method)(
int x,
int y),
176 template<
class Class>
181 void (Class::*method)(
int x,
int y,
int threadID),
194 template<
class Class>
210 void (Class::*
method1)(
int x,
int y),
211 void (Class::*
method2)(
int x,
int y,
int threadID),
213 GThread(
"runConcurrently2D worker"),
223 for (
int y = start.y; y < upTo.y; y += stride.y) {
226 for (
int x = start.x; x < upTo.x; x += stride.x) {
230 for (
int x = start.x; x < upTo.x; x += stride.x) {
231 (
object->*
method2)(x, y, threadID);
239 template<
class Class>
244 void (Class::*method1)(
int x,
int y),
245 void (Class::*method2)(
int x,
int y,
int threadID),
253 const int numRows = upTo.y - start.y;
254 const int numThreads =
min(maxThreads, numRows);
257 for (
int t = 0; t < numThreads; ++t) {
263 threadSet.
start(USE_CURRENT_THREAD);
270 #endif //G3D_GTHREAD_H
Definition: GThread.h:195
std::string m_name
Definition: GThread.h:68
static const SpawnBehavior USE_CURRENT_THREAD
Definition: GThread.h:126
void(Class::* method1)(int x, int y)
Definition: GThread.h:203
void(Class::* method2)(int x, int y, int threadID)
Definition: GThread.h:204
void * HANDLE
Definition: CascPort.h:146
void terminate()
Definition: GThread.cpp:153
void _internal_runConcurrently2DHelper(const Vector2int32 &start, const Vector2int32 &upTo, Class *object, void(Class::*method1)(int x, int y), void(Class::*method2)(int x, int y, int threadID), int maxThreads)
Definition: GThread.h:241
volatile GStatus m_status
Definition: GThread.h:58
bool operator==(const GThread &)
pthread_t m_handle
Definition: GThread.h:65
SpawnBehavior
Definition: SpawnBehavior.h:4
static int numCores()
Definition: GThread.cpp:77
bool start(SpawnBehavior behavior=USE_NEW_THREAD)
Definition: GThread.cpp:108
arena_t NULL
Definition: jemalloc_internal.h:624
static const SpawnBehavior USE_NEW_THREAD
Definition: GThread.h:128
void start(SpawnBehavior lastThreadBehavior=USE_NEW_THREAD) const
Definition: ThreadSet.cpp:29
shared_ptr< class GThread > Ref
Definition: GThread.h:80
const std::string & name()
Definition: GThread.h:121
#define WINAPI
Definition: CascPort.h:163
void waitForCompletion() const
Definition: ThreadSet.cpp:74
shared_ptr< class GThread > GThreadRef
Definition: GThread.h:27
Definition: ReferenceCount.h:24
T min(const T &x, const T &y)
Definition: g3dmath.h:305
int insert(const ThreadRef &t)
Definition: ThreadSet.cpp:109
virtual ~GThread()
Definition: GThread.cpp:49
const Vector2int32 start
Definition: GThread.h:199
static void * internalThreadProc(void *param)
Definition: GThread.cpp:203
bool started() const
Definition: GThread.cpp:72
static GThreadRef create(const std::string &name, void(*proc)(void *), void *param=NULL)
Definition: GThread.cpp:67
const int threadID
Definition: GThread.h:198
Definition: GThread.h:133
G3D::int16 y
Definition: Vector2int16.h:38
GStatus
Definition: GThread.h:45
Class * object
Definition: GThread.h:202
Vector2int32
Definition: Vector2int32.h:27
unsigned int DWORD
Definition: CascPort.h:139
virtual void threadMain()=0
bool running() const
Definition: GThread.cpp:166
const Vector2int32 upTo
Definition: GThread.h:200
virtual void threadMain()
Definition: GThread.h:222
void waitForCompletion()
Definition: GThread.cpp:176
Definition: SpawnBehavior.h:4
G3D::int16 x
Definition: Vector2int16.h:37
Definition: ThreadSet.h:18
GThread & operator=(const GThread &)
_internalGThreadWorker(int threadID, const Vector2int32 &start, const Vector2int32 &upTo, Class *object, void(Class::*method1)(int x, int y), void(Class::*method2)(int x, int y, int threadID), const Vector2int32 &stride)
Definition: GThread.h:206
static void runConcurrently2D(const Vector2int32 &start, const Vector2int32 &upTo, Class *object, void(Class::*method)(int x, int y), int maxThreads=NUM_CORES)
Iterates over a 2D region using multiple threads and blocks until all threads have completed...
Definition: GThread.h:164
bool completed() const
Definition: GThread.cpp:171
Definition: SpawnBehavior.h:4
const Vector2int32 stride
Definition: GThread.h:201