library/src/blockclass/BP-BlockClass.cc
// This processor routine will create thread_n (count) threads, with startRoutine as an entry point.  The threads
// will take arguments directly from the thread_params pointer array.  New threads will be created as threads exit
// untill each element of thread_params has been completed.  After this routine has exited, you can check the individual
// parameter structures for information regarding their arbitrary input/output/statuses.
This processor routine will create thread_n (count) threads, with startRoutine as an entry point.  The threads
will take arguments directly from the thread_params pointer array.  New threads will be created as threads exit
untill each element of thread_params has been completed.  After this routine has exited, you can check the individual
parameter structures for information regarding their arbitrary input/output/statuses.
This processor routine will create thread_n ( count ) threads with startRoutine as an entry point . The threads will take arguments directly from the thread_params pointer array . New threads will be created as threads exit untill each element of thread_params has been completed . After this routine has exited you can check the individual parameter structures for information regarding their arbitrary input / output / statuses .
BP_ERROR_T Block::threadedDataProcessor(size_t thread_n, void *(startRoutine)(void*), void ** thread_params, size_t param_n)
{
	if(!this->thread_manager)
		return ERR_FAILURE;
	BP_DestroyThreadManager(this->thread_manager);
	this->thread_manager = BP_CreateThreadManager("block tdp", "block tdp");
	if(!this->thread_manager)
		return ERR_FAILURE;
	if(!thread_params)
	{
		this->AddErrorToStack("Error: Tried to run threaded data processor with no parameters set.");
		return ERR_FAILURE;
	}
	if(!startRoutine)
	{
		this->AddErrorToStack("Error: Tried to run the threaded data processor with no start routine set.");
		return ERR_FAILURE;
	}
	if(!thread_n)
	{
		this->AddErrorToStack("Error: Tried to run the threaded data processor without an arbitrary thread count (count is zero)");
		return ERR_FAILURE;
	}
	if(!param_n)
	{
		printf("\n [+] Error using threaded data dispatcher.  You have a zero parameter count.");
		return ERR_FAILURE;
	}
	if(thread_n > param_n)
		thread_n = param_n;
	size_t n = 0;
	size_t * param_lens = (size_t *) tq_calloc
	(
			this->tq,
			sizeof(void *) * (param_n+10),
			1,
			BPLN
	);
	for(n = 0; n < param_n; n++)
	{
		param_lens[n] = sizeof(void *);
	}
	BP_ERROR_T err_code = ERR_SUCCESS;
	for(n = 0; n < thread_n; n++)
	{
		err_code = BP_CreateThread
		(
			this->thread_manager,
			startRoutine,
			NULL,
			0,
			BP_FALSE
		);
		if(err_code != ERR_SUCCESS)
		{
			printf("\n Failed to create thread");
		}
	}
	BP_ThreadedDataProcessor(this->thread_manager, thread_params, param_lens, param_n);
	tq_free(this->tq, param_lens);
	return ERR_SUCCESS;
}
BP_ERROR_T Block :: threadedDataProcessor ( size_t thread_n , void * ( startRoutine ) ( void * ) , void * * thread_params , size_t param_n ) { if ( ! this -> thread_manager ) return ERR_FAILURE ; BP_DestroyThreadManager ( this -> thread_manager ) ; this -> thread_manager = BP_CreateThreadManager ( " " , " " ) ; if ( ! this -> thread_manager ) return ERR_FAILURE ; if ( ! thread_params ) { this -> AddErrorToStack ( " " ) ; return ERR_FAILURE ; } if ( ! startRoutine ) { this -> AddErrorToStack ( " " ) ; return ERR_FAILURE ; } if ( ! thread_n ) { this -> AddErrorToStack ( " " ) ; return ERR_FAILURE ; } if ( ! param_n ) { printf ( " \n " ) ; return ERR_FAILURE ; } if ( thread_n > param_n ) thread_n = param_n ; size_t n = 0 ; size_t * param_lens = ( size_t * ) tq_calloc ( this -> tq , sizeof ( void * ) * ( param_n + 10 ) , 1 , BPLN ) ; for ( n = 0 ; n < param_n ; n ++ ) { param_lens [ n ] = sizeof ( void * ) ; } BP_ERROR_T err_code = ERR_SUCCESS ; for ( n = 0 ; n < thread_n ; n ++ ) { err_code = BP_CreateThread ( this -> thread_manager , startRoutine , NULL , 0 , BP_FALSE ) ; if ( err_code != ERR_SUCCESS ) { printf ( " \n " ) ; } } BP_ThreadedDataProcessor ( this -> thread_manager , thread_params , param_lens , param_n ) ; tq_free ( this -> tq , param_lens ) ; return ERR_SUCCESS ; }
This processor routine will create thread_n (count) threads, with startRoutine as an entry point.
This processor routine will create thread_n ( count ) threads with startRoutine as an entry point .
// the class should already have a thread manager, it's created // by the class constructor.  If no manager is set, exit immediately. // destroy the thread manager // create a new thread manager // ensure we can create the new thread manager // ensure we have thread parameters // ensure we have a start routine // ensure we have a thread count // ensure we have a prameter count // should never try to start more threads than the parameters we already have // general purpose iterator // create param lens // set parameter lengths (seems useless, perhaps i had grand designs) // error code // create the desired number of threads (don't start them initially) // create threads (don't start them immediately) // asm("int3"); // start the threaded data processor (runs all, rejoins all, quick and easy, no contentions) // destroy the parameters // return indicating success