legacy_sources/v1/libparallel.c
/*----------------------------------------------------------*/
/* the scheduler set threads states : stop, idle, wait, run */
/*----------------------------------------------------------*/
the scheduler set threads states : stop, idle, wait, run
the scheduler set threads states : stop idle wait run
static void *PthSch(void *arg)
{
	int i, j, sta;
	WrkSct *wrk;
	PthSct *pth = (PthSct *)arg;
	do
	{
		pthread_mutex_lock(par->mtx);
		sta = pth->sta;
		if(sta == ParLok)
		{
			wrk = NULL;
			for(i=0;i<par->typ1->NmbWrk;i++)
			{
				wrk = &par->typ1->WrkTab[i];
				if(wrk->flg)
				{
					wrk = NULL;
					continue;
				}
				if(par->typ2)
					for(j=0;j<par->NmbCpu;j++)
					{
						if(j == pth->idx)
							continue;
						if(par->PthTab[j].wrk && AndBit(par->PthTab[j].wrk->dep, wrk->dep))
						{
							wrk = NULL;
							break;
						}
					}
				if(wrk)
					break;
			}
			if(wrk)
			{
				sta = pth->sta = ParRun;
				pth->wrk = wrk;
				wrk->flg = 1;
				par->WrkCpt++;
				par->sta[0]++;
				for(i=0;i<par->NmbCpu;i++)
					if(par->PthTab[i].wrk)
						par->sta[1]++;
			}
			else if(par->WrkCpt == par->typ1->NmbWrk)
				sta = pth->sta = ParIdl;
		}
		pthread_mutex_unlock(par->mtx);
		if( (sta == ParIdl) || (sta == ParLok) )
			usleep(IdlTim);
		else if(sta == ParRun)
		{
			par->prc(wrk->BegIdx, wrk->EndIdx, pth->idx, par->arg);
			pth->sta = ParLok;
			pth->wrk = NULL;
		}
	}while(sta != ParEnd);
	return(NULL);
}
static void * PthSch ( void * arg ) { int i , j , sta ; WrkSct * wrk ; PthSct * pth = ( PthSct * ) arg ; do { pthread_mutex_lock ( par -> mtx ) ; sta = pth -> sta ; if ( sta == ParLok ) { wrk = NULL ; for ( i = 0 ; i < par -> typ1 -> NmbWrk ; i ++ ) { wrk = & par -> typ1 -> WrkTab [ i ] ; if ( wrk -> flg ) { wrk = NULL ; continue ; } if ( par -> typ2 ) for ( j = 0 ; j < par -> NmbCpu ; j ++ ) { if ( j == pth -> idx ) continue ; if ( par -> PthTab [ j ] . wrk && AndBit ( par -> PthTab [ j ] . wrk -> dep , wrk -> dep ) ) { wrk = NULL ; break ; } } if ( wrk ) break ; } if ( wrk ) { sta = pth -> sta = ParRun ; pth -> wrk = wrk ; wrk -> flg = 1 ; par -> WrkCpt ++ ; par -> sta [ 0 ] ++ ; for ( i = 0 ; i < par -> NmbCpu ; i ++ ) if ( par -> PthTab [ i ] . wrk ) par -> sta [ 1 ] ++ ; } else if ( par -> WrkCpt == par -> typ1 -> NmbWrk ) sta = pth -> sta = ParIdl ; } pthread_mutex_unlock ( par -> mtx ) ; if ( ( sta == ParIdl ) || ( sta == ParLok ) ) usleep ( IdlTim ) ; else if ( sta == ParRun ) { par -> prc ( wrk -> BegIdx , wrk -> EndIdx , pth -> idx , par -> arg ) ; pth -> sta = ParLok ; pth -> wrk = NULL ; } } while ( sta != ParEnd ) ; return ( NULL ) ; }
the scheduler set threads states : stop, idle, wait, run
the scheduler set threads states : stop idle wait run