Exemplo n.º 1
0
void
setalarm(int lck)
{
    struct varent *vp;
    Char   *cp;
    unsigned alrm_time = 0, logout_time, lock_time;
    time_t cl, nl, sched_dif;

    if ((vp = adrof(STRautologout)) != NULL && vp->vec != NULL) {
	if ((cp = vp->vec[0]) != 0) {
	    if ((logout_time = (unsigned) atoi(short2str(cp)) * 60) > 0) {
#ifdef SOLARIS2
		/*
		 * Solaris alarm(2) uses a timer based in clock ticks
		 * internally so it multiplies our value with CLK_TCK...
		 * Of course that can overflow leading to unexpected
		 * results, so we clip it here. Grr. Where is that
		 * documented folks?
		 */
		if (logout_time >= 0x7fffffff / CLK_TCK)
			logout_time = 0x7fffffff / CLK_TCK;
#endif /* SOLARIS2 */
		alrm_time = logout_time;
		alm_fun = auto_logout;
	    }
	}
	if ((cp = vp->vec[1]) != 0) {
	    if ((lock_time = (unsigned) atoi(short2str(cp)) * 60) > 0) {
		if (lck) {
		    if (alrm_time == 0 || lock_time < alrm_time) {
			alrm_time = lock_time;
			alm_fun = auto_lock;
		    }
		}
		else /* lock_time always < alrm_time */
		    if (alrm_time)
			alrm_time -= lock_time;
	    }
	}
    }
    if ((nl = sched_next()) != -1) {
	(void) time(&cl);
	sched_dif = nl > cl ? nl - cl : 0;
	if ((alrm_time == 0) || ((unsigned) sched_dif < alrm_time)) {
	    alrm_time = ((unsigned) sched_dif) + 1;
	    alm_fun = sched_run;
	}
    }
    alrmcatch_disabled = 0;
    (void) alarm(alrm_time);	/* Autologout ON */
}
Exemplo n.º 2
0
Arquivo: sched.c Projeto: giszo/urubu
// =====================================================================================================================
int sched_irq(int irq, void* data, struct irq_context* ctx)
{
    // We need to send EOI on the PIC here because this function will not return to the common IRQ handler path ...
    pic_send_eoi(0);

    struct cpu* curr_cpu = cpu_get_current();
    struct thread* curr = curr_cpu->thread_current;
    struct amd64_thread* t_arch;

    // Save the kernel stack pointer of the previous thread.
    if (curr)
    {
        t_arch = (struct amd64_thread*)curr->arch_data;
        t_arch->rsp = (uint64_t)ctx;
    }

    // Select the next thread to run.
    struct thread* next = sched_next(curr_cpu, curr);

    // upadte the TSS structure of the current CPU for the new thread
    struct amd64_cpu* arch_cpu = (struct amd64_cpu*)curr_cpu->arch_data;
    arch_cpu->tss.rsp0 = (ptr_t)next->kernel_stack + next->kernel_stack_size;

    // switch to the address space of the new process
    if (next->proc)
    {
	struct amd64_process* proc_arch = (struct amd64_process*)next->proc->arch_data;
	cpu_set_cr3(proc_arch->cr3);
    }

    // Switch to the next thread.
    t_arch = (struct amd64_thread*)next->arch_data;
    sched_arch_switch_to(t_arch->rsp);

    return 0;
}