Ejemplo n.º 1
0
static  int get_prio_m1( void )
{
    if( !coper ) {
        return( 0 );
    }
    return( get_prio( oper_stack[coper - 1] ) );
}
Ejemplo n.º 2
0
static  void push_op( char op )
{
    if( !get_prio( op ) ) {
        nparens++;
    }
    oper_stack[coper++] = op;
}
Ejemplo n.º 3
0
unsigned mt_task_queue::get_default_prio() {
    if (g_current_task && get_imp(*g_current_task)) {
        return get_prio(*g_current_task);
    } else {
        return 0;
    }
}
Ejemplo n.º 4
0
bool mt_task_queue::check_deps(gtask const & t) {
    check_stack("mt_task_queue::check_deps");
    lean_always_assert(get_data(t));

    buffer<gtask> deps;
    try {
        get_data(t)->m_imp->get_dependencies(deps);
    } catch (...) {}

    auto prio = get_prio(t);
    for (auto & dep : deps) {
        if (dep) {
            submit_core(dep, prio);
            bump_prio(dep, prio);
        }
    }

    for (auto & dep : deps) {
        if (!dep) continue;
        switch (get_state(dep).load()) {
            case task_state::Waiting: case task_state::Queued: case task_state::Running:
                lean_always_assert(get_imp(dep));
                get_sched_info(dep).m_reverse_deps.push_back(t);
                return false;
            case task_state::Success:
                break;
            case task_state::Failed:
                break;
            default: lean_unreachable();
        }
    }
    return true;
}
Ejemplo n.º 5
0
char get_operator( char op )
{
	/* if op is right op, then return op */
	if( get_prio(op) >= 0 )
		return op;
	
	return -1;
}
Ejemplo n.º 6
0
void mt_task_queue::bump_prio(gtask const & t, unsigned new_prio) {
    switch (get_state(t).load()) {
        case task_state::Queued:
            if (new_prio < get_prio(t)) {
                auto prio = get_prio(t);
                auto &q = m_queue[prio];
                auto it = std::find(q.begin(), q.end(), t);
                lean_always_assert(it != q.end());
                q.erase(it);
                if (q.empty()) m_queue.erase(prio);

                get_prio(t) = std::min(get_prio(t), new_prio);
                check_deps(t);
                enqueue(t);
            }
            break;
        case task_state::Waiting:
            if (new_prio < get_prio(t)) {
                get_prio(t) = std::min(get_prio(t), new_prio);
                check_deps(t);
            }
            break;
        case task_state::Running: case task_state::Failed: case task_state::Success:
            break;
        default: lean_unreachable();
    }
}
Ejemplo n.º 7
0
void mt_task_queue::enqueue(gtask const & t) {
    lean_always_assert(get_state(t).load() < task_state::Running);
    lean_always_assert(get_imp(t));
    get_state(t) = task_state::Queued;
    m_queue[get_prio(t)].push_back(t);
    if (m_required_workers > 0) {
        spawn_worker();
    } else {
        m_queue_added.notify_one();
    }
    notify_queue_changed();
}
Ejemplo n.º 8
0
static int do_paren( void )
{
    int op;

    if( 1 > nparens-- ) {
        return( not_ok );
    }

    do {
        op = do_expr();
        if( op < ok ) {
            break;
        }
    } while( get_prio( (char)op ) );

    return( op );
}
Ejemplo n.º 9
0
Archivo: 1-6.c Proyecto: 1587/ltp
int main(void)
{
	pthread_attr_t attr;
	pthread_t th;
	struct params p;
	int ret;
	unsigned int i;

	ret = set_affinity_single();
	if (ret) {
		n_threads = get_ncpu();
		if (n_threads == -1) {
			printf("Cannot get number of CPUs\n");
			return PTS_UNRESOLVED;
		}
		printf("INFO: Affinity not supported, running %i threads.\n",
		       n_threads);
	} else {
		printf("INFO: Affinity works, will use only one thread.\n");
		n_threads = 1;
	}

	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
		p.sched_policy = tcases[i].sched_policy;
		p.sched_priority = get_prio(&tcases[i]);

		init_attr(&attr, p.sched_policy, p.sched_priority);

		printf("INFO: Testing %s prio %i\n",
		       sched_policy_name(p.sched_policy), p.sched_priority);

		ret = pthread_create(&th, &attr, do_test, &p);
		if (ret) {
			fprintf(stderr, "pthread_create(): %s\n", strerror(ret));
			return PTS_UNRESOLVED;
		}

		pthread_join(th, NULL);

		pthread_attr_destroy(&attr);
	}

	printf("Test PASSED\n");
	return 0;
}
Ejemplo n.º 10
0
t_tree			*split_prio(char *cmd)
{
	t_tree	*p_tree;
	t_tree	*tmp;
	short	n_node;
	char	*current_prio;

	p_tree = NULL;
	n_node = get_total_node(cmd, 0, -1, 0);
	while (n_node > 0)
	{
		get_current_id_prio(1);
		current_prio = cmd;
		cmd += get_prio(&cmd, 0, -1, 0);
		tmp = get_end_null_tree(p_tree);
		tmp = create_tree(get_end_tree(p_tree), current_prio, \
			get_current_id_prio(0));
		if (!p_tree)
			p_tree = tmp;
		n_node--;
	}
	return (p_tree);
}
Ejemplo n.º 11
0
void pfunction::compile_infix(const std::vector<pstring> &inputs, const pstring &expr)
{
	// Shunting-yard infix parsing
	std::vector<pstring> sep = {"(", ")", ",", "*", "/", "+", "-", "^"};
	std::vector<pstring> sexpr(plib::psplit(expr.replace_all(" ",""), sep));
	std::stack<pstring> opstk;
	std::vector<pstring> postfix;

	//printf("dbg: %s\n", expr.c_str());
	for (unsigned i = 0; i < sexpr.size(); i++)
	{
		pstring &s = sexpr[i];
		if (s=="(")
			opstk.push(s);
		else if (s==")")
		{
			pstring x = pop_check(opstk, expr);
			while (x != "(")
			{
				postfix.push_back(x);
				x = pop_check(opstk, expr);
			}
			if (opstk.size() > 0 && get_prio(opstk.top()) == 0)
				postfix.push_back(pop_check(opstk, expr));
		}
		else if (s==",")
		{
			pstring x = pop_check(opstk, expr);
			while (x != "(")
			{
				postfix.push_back(x);
				x = pop_check(opstk, expr);
			}
			opstk.push(x);
		}
		else {
			int p = get_prio(s);
			if (p>0)
			{
				if (opstk.size() == 0)
					opstk.push(s);
				else
				{
					if (get_prio(opstk.top()) >= get_prio(s))
						postfix.push_back(pop_check(opstk, expr));
					opstk.push(s);
				}
			}
			else if (p == 0) // Function or variable
			{
				if (sexpr[i+1] == "(")
					opstk.push(s);
				else
					postfix.push_back(s);
			}
			else
				postfix.push_back(s);
		}
	}
	while (opstk.size() > 0)
	{
		postfix.push_back(opstk.top());
		opstk.pop();
	}
	compile_postfix(inputs, postfix, expr);
}
Ejemplo n.º 12
0
int main( int argc, char * argv[] )
{
	int tmp;
	int i = 0;
	int num1;
	int num2;
	int new_num;
	char op;

	char * src; 

	char cur_op;
	char top_op;

	printf( "expression value demo begin !\n" );
#if 0
	push_int( 100 );

	push_int( 200 );

	tmp = pop_int();
	printf( "pop is %d \n", tmp );
	
	tmp = pop_int();
	printf( "pop is %d \n", tmp );
#endif
	if( argc > 1 )
		printf( "input expression string is %s \n", argv[1] );
	else 
		exit(0);

	src = argv[1];

	push_char( '\0');

	while( 1 )
	{
		printf( "src[%d] = %c \n", i, src[i] );	
get_num:		
		/* get a number */
		num1 = get_number( src[i] );
		if( num1 >= 0 )
			printf( "get a number : %d \n", num1 );	
		else
			break;

		/* push this number */
		printf( "push current int : %d \n", num1 );
		push_int( num1 );

		/* get the next op */
		i++;

		cur_op = get_operator( src[i] );
		if( cur_op > 0 )
			printf( "get a operator: %c \n", cur_op );	
		else if( cur_op == '\0' )
		{
			printf( "get a operator == 0: %c \n", cur_op );	
		}

cmp_op:
		top_op = get_top_char();
		printf( "get top stack operator: %c \n", top_op );	
		
		/* if current op > stack top op, then push current op */
		if( get_prio( cur_op ) > get_prio( top_op ) )
		{
			printf( "<push> push current op : %c \n", cur_op );
			push_char( cur_op );
			
			printf( "<push> push ok!\n" );
		}
		else
		{
			op = pop_char();
			num2 = pop_int();
			if( op == '\0' )
			{ 
				printf( "op == 0, last result = %d \n", num2 );
				exit( 0 );
			}

			num1 = pop_int();
			
			printf( "<calc> pop 2 num and 1 op, do calc: %d %c %d \n", num1, op, num2 );
			new_num = calc( num1, num2, op );
			printf( "get calc result: %d \n", new_num );
		
			/* push this new number */
			printf( "push new int : %d \n", new_num );
			push_int( new_num );

			goto cmp_op;
		}

		/* get the next op */
		i++;		
	} 

	return 0;
}