kernel/sys/process.c
/**
 * @brief Pop the next available process from the queue.
 *
 * Gets the next available process from the round-robin scheduling
 * queue. If there is no process to run, the idle task is returned.
 *
 * TODO This needs more locking for SMP...
 */
@brief Pop the next available process from the queue.
Gets the next available process from the round-robin scheduling
queue. If there is no process to run, the idle task is returned.


@brief Pop the next available process from the queue . Gets the next available process from the round - robin scheduling queue . If there is no process to run the idle task is returned .
volatile process_t * next_ready_process(void) {
	spin_lock(process_queue_lock);
	if (!process_queue->head) {
		if (process_queue->length) {
			arch_fatal_prepare();
			printf("Queue has a length but head is NULL\n");
			arch_dump_traceback();
			arch_fatal();
		}
		spin_unlock(process_queue_lock);
		return this_core->kernel_idle_task;
	}
	node_t * np = list_dequeue(process_queue);
	if ((uintptr_t)np < 0xFFFFff0000000000UL || (uintptr_t)np > 0xFFFFfff000000000UL) {
		arch_fatal_prepare();
		printf("Suspicious pointer in queue: %#zx\n", (uintptr_t)np);
		arch_dump_traceback();
		arch_fatal();
	}
	volatile process_t * next = np->value;
	if ((next->flags & PROC_FLAG_RUNNING) && (next->owner != this_core->cpu_id)) {
		list_append(process_queue, (node_t*)&next->sched_node);
		spin_unlock(process_queue_lock);
		return this_core->kernel_idle_task;
	}
	spin_unlock(process_queue_lock);
	__sync_or_and_fetch(&next->flags, PROC_FLAG_RUNNING);
	next->owner = this_core->cpu_id;
	return next;
}
volatile process_t * next_ready_process ( void ) { spin_lock ( process_queue_lock ) ; if ( ! process_queue -> head ) { if ( process_queue -> length ) { arch_fatal_prepare ( ) ; printf ( " \n " ) ; arch_dump_traceback ( ) ; arch_fatal ( ) ; } spin_unlock ( process_queue_lock ) ; return this_core -> kernel_idle_task ; } node_t * np = list_dequeue ( process_queue ) ; if ( ( uintptr_t ) np < 0xFFFFff0000000000UL || ( uintptr_t ) np > 0xFFFFfff000000000UL ) { arch_fatal_prepare ( ) ; printf ( " \n " , ( uintptr_t ) np ) ; arch_dump_traceback ( ) ; arch_fatal ( ) ; } volatile process_t * next = np -> value ; if ( ( next -> flags & PROC_FLAG_RUNNING ) && ( next -> owner != this_core -> cpu_id ) ) { list_append ( process_queue , ( node_t * ) & next -> sched_node ) ; spin_unlock ( process_queue_lock ) ; return this_core -> kernel_idle_task ; } spin_unlock ( process_queue_lock ) ; __sync_or_and_fetch ( & next -> flags , PROC_FLAG_RUNNING ) ; next -> owner = this_core -> cpu_id ; return next ; }
@brief Pop the next available process from the queue.
@brief Pop the next available process from the queue .
/* We pulled a process too soon, switch to idle for a bit so the
		 * core that marked this process as ready can finish switching away from it. */