示例#1
0
int
ipc_event_recv(int *pid_store, int *event_store, unsigned int timeout) {
    if (event_store == NULL) {
        return -E_INVAL;
    }

    struct mm_struct *mm = current->mm;
    if (pid_store != NULL) {
        if (!user_mem_check(mm, (uintptr_t)pid_store, sizeof(int), 1)) {
            return -E_INVAL;
        }
    }
    if (!user_mem_check(mm, (uintptr_t)event_store, sizeof(int), 1)) {
        return -E_INVAL;
    }

    unsigned long saved_ticks;
    timer_t __timer, *timer = ipc_timer_init(timeout, &saved_ticks, &__timer);

    int pid, event, ret;
    if ((ret = recv_event(&pid, &event, timer)) == 0) {
        lock_mm(mm);
        {
            ret = -E_INVAL;
            if (pid_store == NULL || copy_to_user(mm, pid_store, &pid, sizeof(int))) {
                if (copy_to_user(mm, event_store, &event, sizeof(int))) {
                    ret = 0;
                }
            }
        }
        unlock_mm(mm);
        return ret;
    }
    return ipc_check_timeout(timeout, saved_ticks);
}
示例#2
0
int ipc_event_send(int pid, int event, unsigned int timeout)
{
	struct proc_struct *proc;
	if ((proc = find_proc(pid)) == NULL || proc->state == PROC_ZOMBIE) {
		return -E_INVAL;
	}
	if (proc == current || proc == idleproc || proc == initproc) {
		return -E_INVAL;
	}
#ifdef UCONFIG_SWAP
	if(proc == kswapd)
		return -E_INVAL;
#endif
	if (proc->wait_state == WT_EVENT_RECV) {
		wakeup_proc(proc);
	}
	current->event_box.event = event;

	unsigned long saved_ticks;
	timer_t __timer, *timer =
	    ipc_timer_init(timeout, &saved_ticks, &__timer);

	uint32_t flags;
	if ((flags = send_event(proc, timer)) == 0) {
		return 0;
	}
	assert(flags == WT_INTERRUPTED);
	return ipc_check_timeout(timeout, saved_ticks);
}
示例#3
0
文件: sem.c 项目: spinlock/ucore
static int
usem_down(semaphore_t *sem, unsigned int timeout) {
    unsigned long saved_ticks;
    timer_t __timer, *timer = ipc_timer_init(timeout, &saved_ticks, &__timer);

    uint32_t flags;
    if ((flags = __down(sem, WT_USEM, timer)) == 0) {
        return 0;
    }
    assert(flags == WT_INTERRUPTED);
    return ipc_check_timeout(timeout, saved_ticks);
}