/**
 * down_timeout - acquire the semaphore within a specified time
 * @sem: the semaphore to be acquired
 * @jiffies: how long to wait before failing
 *
 * 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 semaphore is not released within the specified number of jiffies,
 * this function returns -ETIME.  It returns 0 if the semaphore was acquired.
 */
int down_timeout(struct semaphore *sem, long jiffies)
{
	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
	    char aee_str[40];
        if(sem->owner == current){
            printk("[Warning!Recursive Semaphore!][%d:%s], down_timeout:%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_timeout(sem, jiffies);
    }
#ifdef CONFIG_MT_LOCK_DEBUG
        if(0 == sem->count)
            sem_set_owner(sem);
#endif
	spin_unlock_irqrestore(&sem->lock, flags);

	return result;
}
Beispiel #2
0
int down_timeout(struct semaphore *sem, long jiffies)
{
	unsigned long flags;
	int result = 0;

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

	return result;
}
/**
 * down_timeout - acquire the semaphore within a specified time
 * @sem: the semaphore to be acquired
 * @jiffies: how long to wait before failing
 *
 * 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 semaphore is not released within the specified number of jiffies,
 * this function returns -ETIME.  It returns 0 if the semaphore was acquired.
 */
int down_timeout(struct semaphore *sem, long jiffies)
{
	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_timeout(sem, jiffies);
#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;
}