-updated tests:
*updated build scripts *removed tls variables from code (needed to support WebAssembly) *some mmutils tweaks *some fixes *pthread TLS thread ID implementation -added Atomic file (reimplementation of atomics templates for emscripten) -added emscripten support to ecs.std
This commit is contained in:
parent
46de0f6adb
commit
946fbf2934
18 changed files with 443 additions and 229 deletions
|
|
@ -2,6 +2,7 @@ module game_core.job_updater;
|
|||
|
||||
import ecs.std;
|
||||
import ecs.vector;
|
||||
import ecs.atomic;
|
||||
|
||||
import ecs_utils.utils;
|
||||
|
||||
|
|
@ -9,6 +10,17 @@ import ecs_utils.utils;
|
|||
import ecs.manager;
|
||||
import mmutils.thread_pool;
|
||||
|
||||
version(LDC)
|
||||
{
|
||||
import ldc.attributes;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct optStrategy {
|
||||
string strategy;
|
||||
}
|
||||
}
|
||||
|
||||
//import supre.core.call_graph_generator;
|
||||
|
||||
struct ECSJobUpdater
|
||||
|
|
@ -24,14 +36,21 @@ struct ECSJobUpdater
|
|||
pool.waitThreads();
|
||||
//pool.unregistExternalThread(thread_data);
|
||||
if(jobs)Mallocator.dispose(jobs);
|
||||
version(WebAssembly)pthread_key_delete(tls_key);
|
||||
}
|
||||
|
||||
version(WebAssembly)
|
||||
{
|
||||
__gshared pthread_key_t tls_key;
|
||||
}
|
||||
else static uint thread_id = 0;
|
||||
|
||||
ThreadPool pool;
|
||||
ThreadData* thread_data;
|
||||
|
||||
int job_id = 0;
|
||||
int no_dep_count = 0;
|
||||
static uint thread_id = 0;
|
||||
//static uint thread_id = 0;
|
||||
|
||||
struct Group
|
||||
{
|
||||
|
|
@ -78,21 +97,25 @@ struct ECSJobUpdater
|
|||
Group[] jobs;
|
||||
Vector!(Group*) call_jobs;
|
||||
Group last_job;
|
||||
JobData[1] groupEndJobs;
|
||||
|
||||
//TrackData[32] trackers;
|
||||
|
||||
void onCreate(uint threads_count)
|
||||
{
|
||||
version(WebAssembly)pthread_key_create(&tls_key, null);
|
||||
|
||||
pool.initialize();
|
||||
//thread_data = pool.registerExternalThread();
|
||||
thread_data = pool.registerExternalThread();
|
||||
pool.setThreadsNum(threads_count);
|
||||
|
||||
jobs = Mallocator.makeArray!Group(256);
|
||||
}
|
||||
|
||||
uint getThreadID() nothrow
|
||||
uint getThreadID() @nogc nothrow
|
||||
{
|
||||
return thread_id;
|
||||
version(WebAssembly)return cast(int)pthread_getspecific(tls_key);
|
||||
else return thread_id;
|
||||
}
|
||||
|
||||
void begin()
|
||||
|
|
@ -113,36 +136,44 @@ struct ECSJobUpdater
|
|||
//foreach(ref tracker;trackers)tracker.clear();
|
||||
}
|
||||
|
||||
@optStrategy("none")
|
||||
void nop()
|
||||
{
|
||||
int i;
|
||||
i++;
|
||||
}
|
||||
|
||||
//@optStrategy("none")
|
||||
void call()
|
||||
{
|
||||
if(last_job.group.getDependenciesWaitCount() == 0)return;
|
||||
if(call_jobs.length == 0)return;
|
||||
|
||||
JobData[1] groupEndJobs;
|
||||
groupEndJobs[0] = JobData(&releaseMainThread, "Stop Threads");
|
||||
//JobData[1] groupEndJobs;
|
||||
groupEndJobs[0] = JobData(&releaseMainThread, "Stop Threads", null, null);
|
||||
|
||||
last_job.group.jobs = groupEndJobs;
|
||||
last_job.group.thPool = &pool;
|
||||
last_job.group.executeOnThreadNum = 0;
|
||||
|
||||
foreach(job;call_jobs)
|
||||
{
|
||||
job.start();
|
||||
}
|
||||
ret = false;
|
||||
while(!ret)
|
||||
|
||||
/*while(atomicLoad(ret) == 1)//!cas(&ret,0,1))
|
||||
{
|
||||
printf("SDL\n");
|
||||
}
|
||||
printf("NonSDL\n");
|
||||
//thread_data.threadStartFunc();
|
||||
nop();
|
||||
version(WebAssembly)//emscripten_main_thread_process_queued_calls();
|
||||
}//*/
|
||||
|
||||
int i = 10;
|
||||
thread_data.threadStartFunc();
|
||||
}
|
||||
shared bool ret = false;
|
||||
|
||||
void releaseMainThread(ThreadData* th_data, JobData* data)
|
||||
{
|
||||
//pool.releaseExternalThreads();
|
||||
ret = true;
|
||||
//atomicStore(ret,0);
|
||||
pool.releaseExternalThreads();
|
||||
}
|
||||
|
||||
static struct JobCaller
|
||||
|
|
@ -153,10 +184,27 @@ shared bool ret = false;
|
|||
|
||||
void callJob(ThreadData* th_data, JobData* data)
|
||||
{
|
||||
updater.thread_id = th_data.threadId;
|
||||
uint job_id = updater.getThreadID();
|
||||
|
||||
//uint job_id = updater.getThreadID();
|
||||
//updater.trackers[job_id].begin(id);
|
||||
job.execute();
|
||||
version(WebAssembly)
|
||||
{
|
||||
//updater.thread_id = th_data.threadId;
|
||||
pthread_setspecific(tls_key, cast(void*)th_data.threadId);
|
||||
if(th_data.threadId == 0)
|
||||
{
|
||||
emscripten_main_thread_process_queued_calls();
|
||||
job.execute();
|
||||
emscripten_main_thread_process_queued_calls();
|
||||
}
|
||||
else job.execute();
|
||||
}
|
||||
else
|
||||
{
|
||||
updater.thread_id = th_data.threadId;
|
||||
job.execute();
|
||||
}
|
||||
//atomicOp!"-="(updater.jobs_count,1);
|
||||
//updater.trackers[job_id].end();
|
||||
}
|
||||
}
|
||||
|
|
@ -178,7 +226,7 @@ shared bool ret = false;
|
|||
caller.id = index;
|
||||
jobs[group.id].add(caller);
|
||||
}
|
||||
|
||||
|
||||
jobs[group.id].build(&pool);
|
||||
|
||||
uint deps = cast(uint)group.dependencies.length;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue