src/mydp/threadwq/threadwq_man_rr.c
static int rr4idle_add_job(struct threadwq_man *man, struct threadwq_job *job)
{
	register unsigned int idx = uatomic_read(&man->rr.twq_idx);

	for (;; idx++)
	{
		struct threadwq *twq;

		if (caa_unlikely(idx >= man->twq_pool_nr))
		{
			idx = 0;
		}

		twq = &man->twq_pool[idx];

		if (caa_likely(pthread_mutex_trylock(&twq->mutex)))
		{
			continue; // lock fail.
		}
		else
		{
			uatomic_set(&man->rr.twq_idx, idx + 1); // Avoid using this index again.

			threadwq_add_job_locked(twq, job);

			pthread_cond_signal(&twq->cond);
			pthread_mutex_unlock(&twq->mutex);
			break;
		}
	} // end for

	return 0;
}
/*
 * Round-robin (RR): Check q one by one, and make sure it's in idle state. Good for few writer.
 *
 * Pros: This can make sure the twq won't get too many tasks in queue.
 * Cons: But if you have multiple-writer, one writer may get longer latency (starvation)
 */
Round-robin (RR): Check q one by one, and make sure it's in idle state. Good for few writer.
Pros: This can make sure the twq won't get too many tasks in queue.
Cons: But if you have multiple-writer, one writer may get longer latency (starvation)
Round - robin ( RR ) : Check q one by one and make sure it ' s in idle state . Good for few writer . Pros : This can make sure the twq won ' t get too many tasks in queue . Cons : But if you have multiple - writer one writer may get longer latency ( starvation )
static int rr4idle_add_job(struct threadwq_man *man, struct threadwq_job *job)
{
	register unsigned int idx = uatomic_read(&man->rr.twq_idx);
	for (;; idx++)
	{
		struct threadwq *twq;
		if (caa_unlikely(idx >= man->twq_pool_nr))
		{
			idx = 0;
		}
		twq = &man->twq_pool[idx];
		if (caa_likely(pthread_mutex_trylock(&twq->mutex)))
		{
			continue; 
		}
		else
		{
			uatomic_set(&man->rr.twq_idx, idx + 1); 
			threadwq_add_job_locked(twq, job);
			pthread_cond_signal(&twq->cond);
			pthread_mutex_unlock(&twq->mutex);
			break;
		}
	} 
	return 0;
}
static int rr4idle_add_job ( struct threadwq_man * man , struct threadwq_job * job ) { register unsigned int idx = uatomic_read ( & man -> rr . twq_idx ) ; for ( ; ; idx ++ ) { struct threadwq * twq ; if ( caa_unlikely ( idx >= man -> twq_pool_nr ) ) { idx = 0 ; } twq = & man -> twq_pool [ idx ] ; if ( caa_likely ( pthread_mutex_trylock ( & twq -> mutex ) ) ) { continue ; } else { uatomic_set ( & man -> rr . twq_idx , idx + 1 ) ; threadwq_add_job_locked ( twq , job ) ; pthread_cond_signal ( & twq -> cond ) ; pthread_mutex_unlock ( & twq -> mutex ) ; break ; } } return 0 ; }
Round-robin (RR): Check q one by one, and make sure it's in idle state.
Round - robin ( RR ) : Check q one by one and make sure it ' s in idle state .
// lock fail. // Avoid using this index again. // end for