⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ixosalossemaphore.c

📁 intel ixp425的驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        if (down_trylock (*mutex))        {            return IX_FAIL;        }    }    else if (timeout > IX_OSAL_MAX_TIMEOUT_MS)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,            IX_OSAL_LOG_DEV_STDOUT,            "ixOsalMutexLock(): use a smaller timeout value to avoid overflow \n",            0, 0, 0, 0, 0, 0);        return IX_FAIL;    }    else    {        timeoutTime = jiffies + (timeout * HZ) / 1000;        while (1)        {            if (!down_trylock (*mutex))            {                break;            }            else            {                if (time_after(jiffies, timeoutTime))                {                    return IX_FAIL;                }            }			/* Switch to next running process if not in atomic state  */           if (!in_atomic())           {                  set_current_state(TASK_INTERRUPTIBLE);						schedule_timeout(1);           }        }                       /* End of while loop */    }                           /* End of if */    return IX_SUCCESS;}PUBLIC IX_STATUSixOsalMutexUnlock (IxOsalMutex * mutex){    if (mutex == NULL)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,            IX_OSAL_LOG_DEV_STDOUT,            "ixOsalMutexUnlock(): NULL mutex handle \n", 0, 0, 0, 0, 0, 0);        return IX_FAIL;    }    up (*mutex);    return IX_SUCCESS;}/* * Attempt to get mutex, return immediately, * no error info because users expect some failures * when using this API. */PUBLIC IX_STATUSixOsalMutexTryLock (IxOsalMutex * mutex){    if (mutex == NULL)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,            IX_OSAL_LOG_DEV_STDOUT,            "ixOsalMutexTryLock(): NULL mutex handle \n", 0, 0, 0, 0, 0, 0);        return IX_FAIL;    }    if (down_trylock (*mutex))    {        return IX_FAIL;    }    return IX_SUCCESS;}PUBLIC IX_STATUSixOsalMutexDestroy (IxOsalMutex * mutex){    if (mutex == NULL)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,            IX_OSAL_LOG_DEV_STDOUT,            "ixOsalMutexDestroy(): NULL mutex handle \n", 0, 0, 0, 0, 0, 0);        return IX_FAIL;    }    kfree (*mutex);    return IX_SUCCESS;}#ifdef IX_OSAL_OEM_FAST_MUTEXPUBLIC IX_STATUSixOsalFastMutexInit (IxOsalFastMutex * mutex){	return IX_OSAL_OEM_FAST_MUTEX_INIT (mutex);}PUBLIC IX_STATUSixOsalFastMutexTryLock(IxOsalFastMutex *mutex){    return IX_OSAL_OEM_FAST_MUTEX_TRYLOCK(mutex);}PUBLIC IX_STATUSixOsalFastMutexUnlock (IxOsalFastMutex * mutex){    if (mutex == NULL)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,            IX_OSAL_LOG_DEV_STDOUT,            "ixOsalFastMutexUnlock(): NULL mutex handle \n",            0, 0, 0, 0, 0, 0);        return IX_FAIL;    }	return IX_OSAL_OEM_FAST_MUTEX_UNLOCK(mutex);}PUBLIC IX_STATUSixOsalFastMutexDestroy (IxOsalFastMutex * mutex){    if (mutex == NULL)    {        ixOsalLog (IX_OSAL_LOG_LVL_ERROR,            IX_OSAL_LOG_DEV_STDOUT,            "ixOsalFastMutexDestroy(): NULL mutex handle \n",            0, 0, 0, 0, 0, 0);        return IX_FAIL;    }		return IX_OSAL_OEM_FAST_MUTEX_DESTROY(mutex);}#else /* ! OEM_FAST_MUTEX */PUBLIC IX_STATUS ixOsalFastMutexInit (IxOsalFastMutex * mutex){    return mutex ? atomic_set(mutex,1), IX_SUCCESS : IX_FAIL;}PUBLIC IX_STATUS  ixOsalFastMutexTryLock(IxOsalFastMutex *mutex){    if (atomic_dec_and_test(mutex))    {	    return IX_SUCCESS;    }    else    {	    atomic_inc(mutex);	    return IX_FAIL;    }} PUBLIC IX_STATUSixOsalFastMutexUnlock (IxOsalFastMutex * mutex){    return mutex ? atomic_inc(mutex),IX_SUCCESS : IX_FAIL;}PUBLIC IX_STATUSixOsalFastMutexDestroy (IxOsalFastMutex * mutex){    atomic_set(mutex,1);	return IX_SUCCESS;}#endif /* IX_OSAL_OEM_FAST_MUTEX *//**** End of generic code ****//** *********************************************************** * End of code cleanup section  *********************************************************** */#ifdef IX_OSAL_OSSL_SHIMLAYER_SUPPORT/* Newly added OSAL Semaphore Functions */PUBLICIX_STATUS _ixOsalSemaphoreDownTimeout(                  IxOsalSemaphore *sid,              UINT32           timeout){    struct task_struct *pTask = current;    wait_queue_t aWait;    init_waitqueue_entry(&aWait, pTask);    /* add this task to the wait queue of the semaphore in order to be awaken       when the semahore becomes available */    pTask->state = TASK_INTERRUPTIBLE;    add_wait_queue_exclusive(&((*sid)->wait), &aWait);    while (timeout > 0 && !signal_pending(current))    {        /* try to lock the semaphore */        if(down_trylock(*sid) == 0)            break;        /* set the task interruptible to allow it be awaken if signals are set */        pTask->state = TASK_INTERRUPTIBLE;                /* wait for the specified timeout */        timeout = schedule_timeout(timeout);    }    /* set the task to running state */    pTask->state = TASK_RUNNING;    /* remove the thread from the wait queue of the semaphore */    remove_wait_queue(&((*sid)->wait), &aWait);    wake_up(&((*sid)->wait));    /* in the case we did not timed out awaken the waiting threads */    if (timeout != 0)    {        if (signal_pending(current))        {            return IX_FAIL;        }        return IX_SUCCESS;    }    return IX_FAIL;} /* _ixOsalSemaphoreDownTimeout */PUBLICIX_STATUS ixOsalSemaphoreWaitInterruptible(              IxOsalSemaphore *sid,              UINT32           timeout){    /* Here just wait for the semaphore to be signalled */    if(timeout == IX_OSAL_WAIT_FOREVER)    {        if (down_interruptible(*sid))            return IX_FAIL;    }    else if(timeout == IX_OSAL_WAIT_NONE)    {        if(down_trylock(*sid) != 0)            return IX_FAIL;    }    else    {        /* Try to acquire the semaphore */        if(down_trylock(*sid) != 0)        {            struct timespec value;            value.tv_sec = timeout/1000;            value.tv_nsec = (timeout%1000) * 1000000;            timeout = timespec_to_jiffies(&value);            return _ixOsalSemaphoreDownTimeout(sid, timeout);        }    }    return IX_SUCCESS;} /* ixOsalSemaphoreWaitInterruptible */PUBLICIX_STATUS ixOsalSemaphorePostWakeup(IxOsalSemaphore *sid){        if (sid == NULL)    {           ixOsalLog(IX_OSAL_LOG_LVL_ERROR,                     IX_OSAL_LOG_DEV_STDOUT,                     "ixOsalSemaphorePost(): NULL semaphore handle \n",                     0, 0, 0, 0, 0, 0);           return IX_FAIL;    }    if( atomic_read(&((*sid)->count)) < 1)        up(*sid);    wake_up(&((*sid)->wait));    return IX_SUCCESS;} /* ixOsalSemaphorePostWakeup */PUBLICIX_STATUS ixOsalSemaphoreFlush(IxOsalSemaphore *sid){    atomic_set(&((*sid)->count), 0);    wake_up_all(&((*sid)->wait));    return IX_SUCCESS;} /* ixOsalSemaphoreFlush */#endif /* IX_OSAL_OSSL_SHIMLAYER_SUPPORT */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -