/**
 * down_killable - acquire the semaphore unless killed
 * @sem: the semaphore to be acquired
 *
 * Attempts to acquire the semaphore.  If no more tasks are allowed to
 * acquire the semaphore, calling this function will put the task to sleep.
 * If the sleep is interrupted by a fatal signal, this function will return
 * -EINTR.  If the semaphore is successfully acquired, this function returns
 * 0.
 */
int down_killable(struct semaphore *sem)
{
	unsigned long flags;
	int result = 0;

	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_killable:%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
		result = __down_killable(sem);
    }
#ifdef CONFIG_MT_LOCK_DEBUG
    if(0 == sem->count)
        sem_set_owner(sem);
#endif
	spin_unlock_irqrestore(&sem->lock, flags);

	return result;
}
Example #2
0
int down_killable(struct semaphore *sem)
{
	unsigned long flags;
	int result = 0;

	spin_lock_irqsave(&sem->lock, flags);
	if (likely(sem->count > 0))
		sem->count--;
	else
		result = __down_killable(sem);
	spin_unlock_irqrestore(&sem->lock, flags);

	return result;
}
/**
 * down_killable - acquire the semaphore unless killed
 * @sem: the semaphore to be acquired
 *
 * Attempts to acquire the semaphore.  If no more tasks are allowed to
 * acquire the semaphore, calling this function will put the task to sleep.
 * If the sleep is interrupted by a fatal signal, this function will return
 * -EINTR.  If the semaphore is successfully acquired, this function returns
 * 0.
 */
int down_killable(struct semaphore *sem)
{
	unsigned long flags;
	int result = 0;

	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
		result = __down_killable(sem);

#ifdef CONFIG_ILOCKDEP
	if (result)
		ilockdep_clear_locking(current);
	else
		ilockdep_acquired(&sem->idep_map, _RET_IP_, (void *)sem);
#endif
	raw_spin_unlock_irqrestore(&sem->lock, flags);

	return result;
}