/**
 * down - acquire the semaphore
 * @sem: the semaphore to be acquired
 *
 * Acquires the semaphore.  If no more tasks are allowed to acquire the
 * semaphore, calling this function will put the task to sleep until the
 * semaphore is released.
 *
 * Use of this function is deprecated, please use down_interruptible() or
 * down_killable() instead.
 */
void down(struct semaphore *sem)
{
	unsigned long flags;

	spin_lock_irqsave(&sem->lock, flags);
	if (likely(sem->count > 0)){
		sem->count--;
	}else{
#ifdef CONFIG_MT_LOCK_DEBUG
        if(sem->owner == current){
	        char aee_str[40];
            printk("[Warning!Recursive Semaphore!][%d:%s], down:%s(0x%x)\n", current->pid, current->comm, sem->sem_name, sem);
            sprintf( aee_str, "Recursive SemLock:%s\n", current->comm);
            aee_kernel_warning( aee_str,"mtlock debugger\n");
            dump_stack();
        }
#endif
		__down(sem);
    }
#ifdef CONFIG_MT_LOCK_DEBUG
    if(0 == sem->count)
        sem_set_owner(sem);
#endif
	spin_unlock_irqrestore(&sem->lock, flags);
}
Example #2
0
void down(struct semaphore *sem)
{
	unsigned long flags;

	spin_lock_irqsave(&sem->lock, flags);
	if (likely(sem->count > 0))
		sem->count--;
	else
		__down(sem);
	spin_unlock_irqrestore(&sem->lock, flags);
}
Example #3
0
File: sem.c Project: 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);
}
Example #4
0
/**
 * down: 获取信号量 
 * @sem: the semaphore to be acquired
 *
 * Acquires the semaphore.  If no more tasks are allowed to acquire the
 * semaphore, calling this function will put the task to sleep until the
 * semaphore is released.
 *
 * Use of this function is deprecated, please use down_interruptible() or
 * down_killable() instead.
 */
void down(struct semaphore *sem)
{
	unsigned long flags;

	spin_lock_irqsave(&sem->lock, flags);
	/*count > 0 :进程直接获得信号量,减1返回*/
	if (likely(sem->count > 0))
		sem->count--;
	else
		__down(sem); /*count < 0,进程无法获得信号量,需要加入到等到队列中*/
	spin_unlock_irqrestore(&sem->lock, flags);
}
Example #5
0
void __sched
down(struct semaphore *sem)
{
#ifdef WAITQUEUE_DEBUG
	CHECK_MAGIC(sem->__magic);
#endif
#ifdef CONFIG_DEBUG_SEMAPHORE
	printk("%s(%d): down(%p) <count=%d> from %p\n",
	       current->comm, current->pid, sem,
	       atomic_read(&sem->count), __builtin_return_address(0));
#endif
	__down(sem);
}
/**
 * down - acquire the semaphore
 * @sem: the semaphore to be acquired
 *
 * Acquires the semaphore.  If no more tasks are allowed to acquire the
 * semaphore, calling this function will put the task to sleep until the
 * semaphore is released.
 *
 * Use of this function is deprecated, please use down_interruptible() or
 * down_killable() instead.
 */
void down(struct semaphore *sem)
{
	unsigned long flags;

	raw_spin_lock_irqsave(&sem->lock, flags);
#ifdef CONFIG_ILOCKDEP
	ilockdep_acquire(&sem->idep_map, _RET_IP_, (void *)sem);
#endif
	if (likely(sem->count > 0))
		sem->count--;
	else
		__down(sem);
#ifdef CONFIG_ILOCKDEP
	ilockdep_acquired(&sem->idep_map, _RET_IP_, (void *)sem);
#endif
	raw_spin_unlock_irqrestore(&sem->lock, flags);
}
Example #7
0
File: sem.c Project: spinlock/ucore
static void
usem_down(semaphore_t *sem) {
    uint32_t flags = __down(sem, WT_USEM);
    assert(flags == 0 || flags == WT_INTERRUPTED);
}
Example #8
0
File: sem.c Project: spinlock/ucore
void
down(semaphore_t *sem) {
    uint32_t flags = __down(sem, WT_KSEM);
    assert(flags == 0);
}