Beispiel #1
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void AddThread(void (*func)(int))
{
	thread_t *thread;

	if (numthreads == 1)
	{
		if (currentnumthreads >= numthreads)
		{
			return;
		}
		currentnumthreads++;
		func(-1);
		currentnumthreads--;
	} //end if
	else
	{
		ThreadLock();
		if (currentnumthreads >= numthreads)
		{
			ThreadUnlock();
			return;
		} //end if
		  //allocate new thread
		thread = GetMemory(sizeof(thread_t));
		if (!thread)
		{
			Error("can't allocate memory for thread\n");
		}
		//
		thread->threadid = currentthreadid;

		thread->id = sprocsp((void (*)(void *, size_t))func, PR_SALL, (void *)thread->threadid, NULL, 0x100000);
		if (thread->id == -1)
		{
			perror("sproc");
			Error("sproc failed");
		}

		//add the thread to the end of the list
		thread->next = NULL;
		if (lastthread)
		{
			lastthread->next = thread;
		}
		else
		{
			firstthread = thread;
		}
		lastthread = thread;
		//
#ifdef THREAD_DEBUG
		qprintf("added thread with id %d\n", thread->threadid);
#endif //THREAD_DEBUG
		//
		currentnumthreads++;
		currentthreadid++;
		//
		ThreadUnlock();
	} //end else
} //end of the function AddThread
Beispiel #2
0
/*
=============
RunThreadsOn
=============
*/
void RunThreadsOn (threadfunc_t func)
{
	pid_t		pid[MAX_THREADS];
	long		i;

	if (numthreads <= 1)
	{
		func (NULL);
		return;
	}

	init_lock (&lck);
	workfunc = func;

	for (i = 0; i < numthreads - 1; i++)
	{
		pid[i] = sprocsp (ThreadWorkerFunc, PR_SALL, (void *)i,
				  NULL, stacksiz);
		if (pid[i] == -1)
		{
			perror ("sproc");
			COM_Error ("sproc failed");
		}
	}

	func ((void *)i);

	for (i = 0; i < numthreads - 1; i++)
		wait (NULL);
}
Beispiel #3
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void RunThreadsOn(int workcnt, qboolean showpacifier, void (*func)(int))
{
	int i;
	int pid[MAX_THREADS];
	int start, end;

	start     = I_FloatTime();
	dispatch  = 0;
	workcount = workcnt;
	oldf      = -1;
	pacifier  = showpacifier;
	threaded  = true;

	if (numthreads < 1 || numthreads > MAX_THREADS)
	{
		numthreads = 1;
	}

	if (pacifier)
	{
		setbuf(stdout, NULL);
	}

	init_lock(&lck);

	for (i = 0 ; i < numthreads - 1 ; i++)
	{
		pid[i] = sprocsp((void (*)(void *, size_t))func, PR_SALL, (void *)i
		                 , NULL, 0x100000);
//		pid[i] = sprocsp ( (void (*)(void *, size_t))func, PR_SALL, (void *)i
//			, NULL, 0x80000);
		if (pid[i] == -1)
		{
			perror("sproc");
			Error("sproc failed");
		}
	}

	func(i);

	for (i = 0 ; i < numthreads - 1 ; i++)
		wait(NULL);

	threaded = false;

	end = I_FloatTime();
	if (pacifier)
	{
		printf(" (%i)\n", end - start);
	}
} //end of the function RunThreadsOn
Beispiel #4
0
/*
=============
RunThreadsOn
=============
*/
void RunThreadsOn (int workcnt, qboolean showpacifier, void(*func)(int))
{
	int		i;
	int		pid[MAX_THREADS];
	int		start, end;

	start = I_FloatTime ();
	dispatch = 0;
	workcount = workcnt;
	oldf = -1;
	pacifier = showpacifier;
	threaded = qtrue;

	if (pacifier)
		setbuf (stdout, NULL);

	init_lock (&lck);

	for (i=0 ; i<numthreads-1 ; i++)
	{
		pid[i] = sprocsp ( (void (*)(void *, size_t))func, PR_SALL, (void *)i
			, NULL, 0x200000);		// 2 meg stacks
		if (pid[i] == -1)
		{
			perror ("sproc");
			Error ("sproc failed");
		}
	}
		
	func(i);
			
	for (i=0 ; i<numthreads-1 ; i++)
		wait (NULL);

	threaded = qfalse;

	end = I_FloatTime ();
	if (pacifier)
		Sys_Printf (" (%i)\n", end-start);
}