Esempio n. 1
0
/////将消息加入线程池
int thpool_add_work(thpool_t* tp_p, void* (*function_p)(void*), void* arg_p)
{
	thpool_job_t* newjob;
	newjob = (thpool_job_t*) malloc(sizeof(thpool_job_t));
	
	if(newjob ==NULL)
	{
		fprintf(stderr, "thpool_add_work(): Could not allocate memory for new job\n");
		exit(1);
	}
	newjob ->function = function_p;
	newjob ->arg      = arg_p;
	pthread_mutex_lock(&mutex);
	thpool_jobqueue_add(tp_p,newjob);
	pthread_mutex_unlock(&mutex);     
	return 0;
}
Esempio n. 2
0
/* Add work to the thread pool */
int thpool_add_work(thpool_t* tp_p, void *(*function_p)(void*), void* arg_p){
	thpool_job_t* newJob;
	
	newJob=(thpool_job_t*)malloc(sizeof(thpool_job_t));                        /* MALLOC job */
	if (newJob==NULL){
		fprintf(stderr, "thpool_add_work(): Could not allocate memory for new job\n");
		exit(1);
	}
	
	/* add function and argument */
	newJob->function=function_p;
	newJob->arg=arg_p;
	
	/* add job to queue */
	pthread_mutex_lock(&mutex);                  /* LOCK */
	thpool_jobqueue_add(tp_p, newJob);
	pthread_mutex_unlock(&mutex);                /* UNLOCK */
	
	return(1);
}
Esempio n. 3
0
/* Add work to the thread pool */
int thpool_add_work(thpool_t *tp_p, int tag, void * (*function_p)(void *), void *arg_p){
	thpool_job_t *newJob = (thpool_job_t *) malloc(sizeof(thpool_job_t));         /* MALLOC job */
	/* printf("newJob's address is %p\n", newJob); */

	if (newJob==NULL){
		fprintf(stderr, "thpool_add_work(): Could not allocate memory for new job\n");
		exit(1);
	}

	/* add function and argument */
	newJob->value.function = function_p;
	newJob->value.arg = arg_p;

	/* choose a queue to add */
	/* To apply advanced task schedule, you need to change your way
	 * to produce tag. */
	int q_num = tag % tp_p->threadsN;

	/* add job to queue */
	thpool_jobqueue_add(tp_p->jobqueue[q_num], newJob);

	return 0;
}