From d0617760f59e955fde40b738f9de20ad70ca3e45 Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Tue, 20 Aug 2013 19:27:40 +0930 Subject: [PATCH] common: add the ability to pass an arg to spawned threads Signed-off-by: Kevin Shanahan --- common/threads.c | 12 ++++++------ include/common/threads.h | 2 +- light/light.c | 2 +- vis/flow.c | 2 +- vis/vis.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/common/threads.c b/common/threads.c index 00f2536d..fbf0fc76 100644 --- a/common/threads.c +++ b/common/threads.c @@ -112,7 +112,7 @@ ThreadUnlock(void) * ============= */ void -RunThreadsOn(int start, int workcnt, void *(func)(void *)) +RunThreadsOn(int start, int workcnt, void *(func)(void *), void *arg) { uintptr_t i; /* avoid warning due to cast for the CreateThread API */ DWORD *threadid; @@ -135,7 +135,7 @@ RunThreadsOn(int start, int workcnt, void *(func)(void *)) threadhandle[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, - (LPVOID)i, + (LPVOID)arg, 0, &threadid[i]); } @@ -207,7 +207,7 @@ ThreadUnlock(void) * ============= */ void -RunThreadsOn(int start, int workcnt, void *(func)(void *)) +RunThreadsOn(int start, int workcnt, void *(func)(void *), void *arg) { pthread_t *threads; pthread_mutexattr_t mattrib; @@ -246,7 +246,7 @@ RunThreadsOn(int start, int workcnt, void *(func)(void *)) threads_active = true; for (i = 0; i < numthreads; i++) { - status = pthread_create(&threads[i], &attrib, func, NULL); + status = pthread_create(&threads[i], &attrib, func, arg); if (status) Error("pthread_create failed"); } @@ -291,13 +291,13 @@ void ThreadUnlock(void) {} * ============= */ void -RunThreadsOn(int start, int workcnt, void *(func)(void *)) +RunThreadsOn(int start, int workcnt, void *(func)(void *), void *arg) { dispatch = start; workcount = workcnt; oldpercent = -1; - func(0); + func(arg); logprint("\n"); } diff --git a/include/common/threads.h b/include/common/threads.h index 3ef67375..ef1c7242 100644 --- a/include/common/threads.h +++ b/include/common/threads.h @@ -9,7 +9,7 @@ int GetDefaultThreads(void); int GetMaxThreads(void); /* returns 0 if no limit specified */ int GetThreadWork(void); int GetThreadWork_Locked__(void); /* caller must take care of locking */ -void RunThreadsOn(int start, int workcnt, void *(func)(void *)); +void RunThreadsOn(int start, int workcnt, void *(func)(void *), void *arg); void ThreadLock(void); void ThreadUnlock(void); diff --git a/light/light.c b/light/light.c index 8e5a0131..ddae06e4 100644 --- a/light/light.c +++ b/light/light.c @@ -194,7 +194,7 @@ LightWorld(void) lit_file_p = lit_filebase; lit_file_end = lit_filebase + 3 * (MAX_MAP_LIGHTING / 4); - RunThreadsOn(0, numfaces, LightThread); + RunThreadsOn(0, numfaces, LightThread, NULL); logprint("Lighting Completed.\n\n"); lightdatasize = file_p - filebase; diff --git a/vis/flow.c b/vis/flow.c index a7752b6b..1f4c5ef1 100644 --- a/vis/flow.c +++ b/vis/flow.c @@ -497,5 +497,5 @@ BasePortalThread(void *dummy) void BasePortalVis(void) { - RunThreadsOn(0, numportals * 2, BasePortalThread); + RunThreadsOn(0, numportals * 2, BasePortalThread, NULL); } diff --git a/vis/vis.c b/vis/vis.c index 31f9a6fe..b952f0b0 100644 --- a/vis/vis.c +++ b/vis/vis.c @@ -722,7 +722,7 @@ CalcPortalVis(void) if (p->status == pstat_done) startcount++; } - RunThreadsOn(startcount, numportals * 2, LeafThread); + RunThreadsOn(startcount, numportals * 2, LeafThread, NULL); if (verbose) { logprint("portalcheck: %i portaltest: %i portalpass: %i\n",