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

📄 pc_locks.c

📁 基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7的BSP,操作系统
💻 C
📖 第 1 页 / 共 4 页
字号:
*       driveno                             Drive number                
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID pc_fat_enter(INT16 driveno)                                /*__fn__*/
{
extern LOCKOBJ fat_locks[];


    pc_generic_enter(&fat_locks[driveno], YES);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_fat_exit                                                     
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       The file manager is leaving code which touched the FAT driveno. 
*       Makes sure any process waiting for FAT is awake.                
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       driveno                             Drive number                
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID  pc_fat_exit(INT16 driveno)                                /*__fn__*/
{
extern LOCKOBJ fat_locks[];


    pc_generic_exit(&fat_locks[driveno]);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_drive_io_enter                                               
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       The file manager is entering a block read/write call. Others may
*       wait for the IO to complete. This routine is called to establish
*       a channel which others may wait on. pc_drive_io_exit will wake  
*       the others up.                                                  
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       driveno                             Drive number                
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID pc_drive_io_enter(INT16 driveno)                           /*__fn__*/
{
extern LOCKOBJ drive_io_locks[];


    /* convert driveno to lockno. When a non re-entrant driver shares more
       then one drive the locks will be the same for each drive */    
    pc_generic_enter(&drive_io_locks[pc_bdevsw[driveno].lock_no], YES);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_drive_io_exit                                                
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       The file manager completed a read/write call. We call here wake 
*       anyone blocked.                                                 
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       driveno                             Drive number                
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID pc_drive_io_exit(INT16 driveno)                            /*__fn__*/
{
extern LOCKOBJ drive_io_locks[];


    pc_generic_exit(&drive_io_locks[pc_bdevsw[driveno].lock_no]);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_generic_enter                                                
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       Two locking operations are provided.                            
*       One, exclusive access to the lock is needed                     
*       Two, Non exclusive access is needed. But we must not return if  
*            someone has exclusive access.                              
*                                                                       
*       Two accomplish this we observe the following.                   
*       For case one the access count of the lock must be zero before we
*       may claim exclusive access.                                     
*       For case two the exclusive flag may not be set.                 
*       We OR these conditions to get our wait condition. Then we up the
*       access count and set the exclusive flag if we are seeking       
*       exclusive access.                                               
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       *plock                              Lock object structure       
*       exclusive                           If exclusive is YES wait for
*                                            access and lock the drive. 
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID pc_generic_enter(LOCKOBJ *plock, INT exclusive)            /*__fn__*/
{
INT         lock_state;


    lock_state =  fs_lock_task();
    while ( plock->exclusive || (plock->opencount && exclusive) )
    {
        pc_wait_lock(plock->wait_handle);
    }
    plock->exclusive = exclusive;
    plock->opencount += 1;
    fs_unlock_task(lock_state);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_generic_exit                                                 
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       We are releasing an object which we had already locked. We      
*       decrement the access count. If the Access count drops to zero we
*       clear the exclusive flag.                                       
*       Then we issue a wakeup on the channel to see if any calls to    
*       pc_generic_enter may return.                                    
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       *plock                              Lock object structure       
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID pc_generic_exit(LOCKOBJ *plock)                            /*__fn__*/
{
INT         lock_state;


    lock_state =  fs_lock_task();

    plock->opencount -= 1;
    if (!plock->opencount)
        plock->exclusive = NO;
    pc_wake_lock(plock->wait_handle);
    fs_unlock_task(lock_state);
    NU_Relinquish();
}

#endif /*  (LOCK_METHOD == 2) */
#endif /* NUM_USERS > 1 */

⌨️ 快捷键说明

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