Example #1
0
int terminate()
{
	int retCode = 0;	
	atomic(ON);	
	retCode = k_terminate();	
	atomic(OFF);	
	return retCode;
}
Example #2
0
void k_process_init(int num_processes, proc_cfg_t init_table[])
{
    jmp_buf init_buf;
    int i;
    _num_processes = num_processes;
    ready_pq = proc_pq_create(NUM_PRIORITIES+NULL_PRIORITY);
	//initalize all the data for the pcb
    for (i = 0; i < num_processes; i++)
    {
        pcb_t *pcb = &p_table[i];
        proc_cfg_t *cfg = &init_table[i];
        pcb->pid = cfg->pid;
        pcb->priority = cfg->priority;
        pcb->name = cfg->name;
        pcb->is_i_process = cfg->is_i_process;
        pcb->start = cfg->start;
        pcb->recv_msgs = msg_env_queue_create();
        pcb->next = NULL;
        pcb->status = P_READY;
        pcb->stack_end = malloc(STACK_SIZE);
        pcb->atomic_count = pcb->is_i_process ? 0 : 1;

        // If the process is not an i process place it on the ready queue
        if (!pcb->is_i_process)
        {
            assert(proc_pq_enqueue(ready_pq, pcb) == CODE_SUCCESS);
        }

        // Initialize the stack and start pc
        if (setjmp(init_buf) ==  0)
        {
            char * stack_top = pcb->stack_end + STACK_SIZE - STACK_OFFSET;
            __asm__("movl %0, %%esp":"=g" (stack_top));
            if (setjmp(pcb->context) == 0)
            {
                longjmp(init_buf, 1);
            }
            else
            {
                if (!current_process->is_i_process)
                    atomic(OFF);
                current_process->start();
#ifdef DEBUG_KERN
                printf("FATAL ERROR: Process <%s> stopped executing! \n", 
                        current_process->name);
#endif
                k_terminate();
            }
        }
    }