📄 pc_locks.c
字号:
/************************************************************************
*
* Copyright (c) 2001 by Accelerated Technology, Inc.
*
* PROPRIETARY RIGHTS of Accelerated Technology are involved in
* the subject matter of this material. All manufacturing,
* reproduction, use, and sales rights pertaining to this subject
* matter are governed by the license agreement. The recipient of
* this software implicitly accepts the terms of the license.
*
*
*************************************************************************
*************************************************************************
* FILE NAME VERSION
*
* PC_LOCKS.C FILE 2.3
*
* COMPONENT
*
* Nucleus File
*
* DESCRIPTION
*
* System specific locking code (user supplied).
*
* DATA STRUCTURES
*
*
* FUNCTIONS
*
* pc_fs_enter Claim exclusive access of
* all RTFS rewsources.
* pc_fs_exit Release exclusive access of
* all RTFS resources.
* fs_suspend_task Suspend a tas for one or
* more ticks.
* fs_lock_task Lock a task so it will not
* be preempted.
* fs_unlock_task Restore a tasks lock state
* to what it was before
* FS_LOCK_TASK was called.
* fs_release Release all RTFS resources
* while we wait for a
* resource to become free or
* we wait for IO completion.
* fs_reclaim Reclaim exclusive access to
* all RTFS resources after
* returning from a resource
* wait or on an io completion.
* pc_alloc_lock Return an event handle which
* may be used as an argument
* to pc_wait_lock and
* pc_wake_lock.
* pc_wait_lock Wait for a message on the
* lock channel.
* pc_wake_lock Wake up anyone waiting on
* the channel.
* pc_drive_enter An API call will use a drive.
* pc_drive_exit An API call has completed
* and is returning.
* pc_inode_enter The file system will be
* touching a file or
* directory at pinode.
* pc_inode_exit The directory entry at
* pinode is not being used.
* pc_fat_enter An API call will use a FAT.
* pc_fat_exit An API call has completed
* using the FAT.
* pc_drive_io_enter We are calling the block io
* routines.
* pc_drive_io_exit IO has completed.
* pc_generic_enter Generic lock routine called
* by others.
* pc_generic_exit Exit a lock
*
* DEPENDENCIES
*
* nucleus.h System definitions
* pcdisk.h File common definitions
*
*************************************************************************/
#include "plus\nucleus.h"
#include "file\pcdisk.h"
/* HAS NUCLEUS Specific changes */
#if (NUM_USERS > 1)
extern NU_SEMAPHORE NUF_FILE_SYSTEM_MUTEX;
/************************************************************************
*
* FUNCTION
*
* pc_fs_enter
*
* DESCRIPTION
*
* This routine is called by the file manager each time an API
* funtion is entered. Its complement function pc_fs_exit is called
* when the API is exitted.
*
* In the reference port we grab a mutex semaphore providing
* exclusive access to RTFS. If LOCK_METHOD is one we will release
* the semaphore when we call pc_fs_exit(). If LOCK_METHOD is two
* we will release the semaphore when we call pc_fs_exit() AND
* also every time we yield waiting for IO completion or for
* another thread to release a resource that we need.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* None.
*
* OUTPUTS
*
* A UINT16 which is later passed into pc_fs_exit() when the API
* call completes. In the reference port we do not use the return
* code.
*
*************************************************************************/
UINT16 pc_fs_enter(VOID) /*__fn__*/
{
/* Note: in a single threaded OS kernel this is not needed */
NU_Obtain_Semaphore(&NUF_FILE_SYSTEM_MUTEX, NU_SUSPEND);
return(1);
}
/************************************************************************
* FUNCTION
*
* pc_fs_exit
*
* DESCRIPTION
*
* This routine is called by the file manager each time an API
* funtion is left. It should provide a complemetary function to
* pc_fs_enter.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* restore_state Not used in reference port
*
* OUTPUTS
*
* None.
*
*************************************************************************/
VOID pc_fs_exit(UINT16 restore_state) /*__fn__*/
{
/* Note in a single threaded OS kernel this is not needed */
restore_state = restore_state; /* Not used in reference port */
NU_Release_Semaphore(&NUF_FILE_SYSTEM_MUTEX);
}
#if (LOCK_METHOD == 2)
/************************************************************************
* FUNCTION
*
* fs_suspend_task
*
* DESCRIPTION
*
* pc_read_block() has a possible race condition when two or more
* tasks are attempting IO on a block which is currently being read
* from the disk by another task. To compensate for this rare race
* condition the tasks NOT performing the IO suspend themselves and
* check the buffer when they resume. They loop this way until the
* task performing the IO set the buffer valid or in error.
*
* This call should suspend the current task for one or more ticks.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* None.
*
* OUTPUTS
*
* None.
*
*************************************************************************/
VOID fs_suspend_task(VOID)
{
/* We can't call NU_Reliquish() here because we need to allow tasks
of even a lower priority to run. */
NU_Sleep(1);
}
/************************************************************************
* FUNCTION
*
* fs_lock_task
*
* DESCRIPTION
*
* This is called by RTFS when a preemption would cause a race
* condition. The call should signal to the kernel that the current
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -