int ut_scheduler_add_ready_tcb(ut_tcb_t *tcb)
{
	// Remove any existing nodes before inserting new ones
	ut_scheduler_remove_tcb_readyList(tcb);

	// Only add item if it's in ready state
	if (tcb->state == UT_TCB_STATE_READY)
	{
		int ret = 0;

		if (_ut_scheduler_implementation_scheme == UT_SCHEDULER_IMPLEMENT_LOTTERY)
		{
			int i;
			for (i = 0; i < tcb->scheduler_weight; i++)
			{
				ret = gl_insert(&_ut_scheduler_readyList, tcb);
			}
		}
		else
		{
			ret = gl_insert(&_ut_scheduler_readyList, tcb);
		}

		return ret;
	}
	else
	{
		return -1;
	}
}
Exemplo n.º 2
0
static void gl_read()
{
    int value;
    while (1 == scanf("%d", &value))
        gl_insert(value);
}
int ut_scheduler_add_sleeping_tcb(ut_tcb_t *tcb)
{
	tcb->state = UT_TCB_STATE_SLEEPING;
	ut_scheduler_remove_tcb_sleepingList(tcb);
	return gl_insert(&_ut_scheduler_sleepingList, tcb);
}