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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
struct SYS_THREAD_POOL_DATA
{
SYS_THREAD_POOL_DATA();
class SYS_THREAD_POOL* m_0;
DWORD m_4;
} ;
inline SYS_THREAD_POOL_DATA::SYS_THREAD_POOL_DATA() { (*(SYS_D3D_VDECL**)&m_0)->SYS_D3D_VDECL::SYS_D3D_VDECL(); }
SYS_ERROR SYS_THREAD_POOL::Create(unsigned long (__cdecl *a0)(void *),void *a1,int a2)
{
Clear();
DWORD ProcessAffinityMask;
DWORD SystemAffinityMask;
GetProcessAffinityMask(GetCurrentProcess(), &ProcessAffinityMask, &SystemAffinityMask);
DWORD v4 = ProcessAffinityMask;
DWORD v5 = 0;
DWORD v40 = 0;
if(v4) //Calculate Number Cores Used
{
do
{
v5 += (v4 & 1) == 1;
v4 >>= 1;
}
while(v4);
v40 = v5;
}
DWORD v9 = 4 * v5;
m_32 = new HANDLE[v5];
memset(m_32, 0, 4 * (v9 / 4));
if((v9 % 4) != 0)
memset(&m_32[4 * (v9 / 4)], 0, 3);
m_48 = new SYS_THREAD_POOL_DATA[v40];
m_36 = new HANDLE[v9];
memset(m_36, 0, 4 * (v9 / 4));
if((v9 % 4) != 0)
memset(&m_36[v9 / 4], 0, 3);
m_60 = a0;
m_64 = a1;
try {
m_40 = CreateEventA(0, 1, 1, 0);
if(!m_40)
throw SYS_ERROR_THREAD;
m_44 = CreateEventA(0, 1, 0, 0);
if(!m_44)
throw SYS_ERROR_THREAD;
DWORD v21 = ProcessAffinityMask;
for(int i = 0; v21; v21 /= 2, --i)
{
HANDLE & v_14 = m_32[m_24];
m_48[m_24].m_4 = m_24;
m_48[m_24].m_0 = this;
++m_24;
m_36[m_24] = CreateEventA(NULL, true, false, NULL);
if(!m_36[m_24])
throw SYS_ERROR_THREAD;
unsigned int ThreadId;
v_14 = (HANDLE)_beginthreadex(0, 0, (unsigned int (__stdcall *)(void*))&ThreadProc, (void*)&m_48[m_24], 4u, &ThreadId);
if(!v_14)
throw SYS_ERROR_THREAD;
if(!SetThreadPriority(v_14, a2))
throw SYS_ERROR_THREAD;
ResumeThread(v_14);
}
}
catch(SYS_ERROR tmp)
{
Clear();
return tmp;
}
return SYS_ERROR_NO;
}
|