common: add the ability to pass an arg to spawned threads
Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
parent
6ddb109dde
commit
d0617760f5
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -497,5 +497,5 @@ BasePortalThread(void *dummy)
|
|||
void
|
||||
BasePortalVis(void)
|
||||
{
|
||||
RunThreadsOn(0, numportals * 2, BasePortalThread);
|
||||
RunThreadsOn(0, numportals * 2, BasePortalThread, NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue