20#include "sched_affinity_win32_wrapper.h"
31template <
class S,
class T>
36 template <
class S,
class T>
42 for (int32_t
i = 0;
i < 2;
i++) {
51 for (int32_t
i = 0;
i < 2;
i++) {
74 template <
class SS,
class TT>
82template <
class S,
class T>
83static void* qThreadWrapperCls(
void* arg);
85template <
class S,
class T>
90 qThreadCls(
S* pCls,
void (
S::*pFunc)(T*), int32_t threadNum = 0, int32_t pinCPU = -1) : threadParam()
96 void SpawnThread(
S* pCls,
void (
S::*pFunc)(T*), int32_t threadNum = 0, int32_t pinCPU = -1, bool wait = true)
100 XthreadParam.pCls = pCls;
101 XthreadParam.pFunc = (
void (
S::*)(
void*))pFunc;
103 XthreadParam.
pinCPU = pinCPU;
105 pthread_create(&thr,
nullptr, (
void* (*)(
void*)) & qThreadWrapperCls, &XthreadParam);
131 void Start() { threadParam.threadMutex[0].Unlock(); }
133 void Sync() { threadParam.threadMutex[1].Lock(); }
139 static void* qThreadWrapperCls(T* arg);
142template <
class S,
class T>
146 if (arg_A->
pinCPU != -1) {
149 CPU_SET(arg_A->
pinCPU, &tmp_mask);
150 sched_setaffinity(0,
sizeof(tmp_mask), &tmp_mask);
154 (arg_A->pCls->*pFunc)(arg);
157 pthread_exit(
nullptr);
161template <
class S,
class T>
170 qThreadClsArray(int32_t
n,
S* pCls,
void (
S::*pFunc)(T*), int32_t threadNumOffset = 0, int32_t* pinCPU = nullptr)
177 void SetNumberOfThreads(int32_t
n,
S* pCls,
void (
S::*pFunc)(T*), int32_t threadNumOffset = 0, int32_t* pinCPU = nullptr)
179 if (nThreadsRunning) {
180 fprintf(
STD_OUT,
"Threads already started\n");
185 for (int32_t
i = 0;
i <
n;
i++) {
186 pArray[
i].SpawnThread(pCls, pFunc, threadNumOffset +
i, pinCPU ==
nullptr ? -1 : pinCPU[
i],
false);
188 for (int32_t
i = 0;
i <
n;
i++) {
189 pArray[
i].WaitForSpawn();
195 if (nThreadsRunning) {
208 for (int32_t
i = 0;
i < nThreadsRunning;
i++) {
215 for (int32_t
i = 0;
i < nThreadsRunning;
i++) {
222 int32_t nThreadsRunning;
void SetNumberOfThreads(int32_t n, S *pCls, void(S::*pFunc)(T *), int32_t threadNumOffset=0, int32_t *pinCPU=nullptr)
qThreadClsArray(int32_t n, S *pCls, void(S::*pFunc)(T *), int32_t threadNumOffset=0, int32_t *pinCPU=nullptr)
void SpawnThread(S *pCls, void(S::*pFunc)(T *), int32_t threadNum=0, int32_t pinCPU=-1, bool wait=true)
qThreadCls(S *pCls, void(S::*pFunc)(T *), int32_t threadNum=0, int32_t pinCPU=-1)
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)