common: add the ability to pass an arg to spawned threads

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-08-20 19:27:40 +09:30
parent 6ddb109dde
commit d0617760f5
5 changed files with 10 additions and 10 deletions

View File

@ -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");
}

View File

@ -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);

View File

@ -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;

View File

@ -497,5 +497,5 @@ BasePortalThread(void *dummy)
void
BasePortalVis(void)
{
RunThreadsOn(0, numportals * 2, BasePortalThread);
RunThreadsOn(0, numportals * 2, BasePortalThread, NULL);
}

View File

@ -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",