📄 fs_x_win32.c
字号:
/*
**********************************************************************
* Micrium, Inc.
* 949 Crestview Circle
* Weston, FL 33327-1848
*
* uC/FS
*
* (c) Copyright 2001 - 2006, Micrium, Inc.
* All rights reserved.
*
***********************************************************************
----------------------------------------------------------------------
----------------------------------------------------------------------
File : FS_X_Win32.c
Purpose : Win32 API OS Layer for the file system
----------------------------------------------------------------------
Known problems or limitations with current version
----------------------------------------------------------------------
None.
---------------------------END-OF-HEADER------------------------------
*/
/*********************************************************************
*
* #include Section
*
**********************************************************************
*/
#include "FS_Int.h"
#include "FS_OS.h"
#include "FS_Conf.h"
#include <time.h>
#include <windows.h>
#include <stdio.h>
/*********************************************************************
*
* Local types
*
**********************************************************************
*/
typedef struct {
HANDLE hSema;
char acName[60];
int OpenCnt;
} LOCK_INST;
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static LOCK_INST * _paInst;
static char _IsInited;
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _CheckInit
*
*/
static void _CheckInit(void) {
if (_IsInited == 0) {
timeBeginPeriod(1);
_IsInited = 1;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* FS_X_OS_Lock
*
*/
void FS_X_OS_Lock(unsigned LockIndex) {
HANDLE hSema;
LOCK_INST * pInst;
pInst = (_paInst + LockIndex);
hSema = pInst->hSema;
if (hSema == NULL) {
return;
}
pInst->OpenCnt++;
// FS_X_Logf("Locking: Index: 0x%.8x, Name: %s\n", LockIndex, pInst->acName);
WaitForSingleObject(hSema, INFINITE);
}
/*********************************************************************
*
* FS_X_OS_Unlock
*
*/
void FS_X_OS_Unlock(unsigned LockIndex) {
HANDLE hSema;
LOCK_INST * pInst;
pInst = (_paInst + LockIndex);
hSema = pInst->hSema;
if (hSema == NULL) {
return;
}
// FS_X_Logf("Unlocking: Index: 0x%.8x, Name: %s\n", LockIndex, pInst->acName);
ReleaseSemaphore(hSema, 1, NULL);
pInst->OpenCnt--;
}
/*********************************************************************
*
* FS_X_OS_Init
*
* Description:
* Initializes the OS resources. Specifically, you will need to
* create FS_NUM_LOCKS binary semaphores/mutexs. This function is
* called by FS_Init(). You should create all resources required
* by the OS to support multithreading of the file system.
*
* Parameters:
* None.
*
* Return value:
* 0 - on success
* -1 - on failure.
*/
void FS_X_OS_Init(unsigned NumLocks) {
unsigned i;
LOCK_INST * pInst;
_paInst = FS_AllocZeroed(NumLocks * sizeof(LOCK_INST));
pInst = &_paInst[0];
for (i = 0; i < NumLocks; i++) {
sprintf(pInst->acName, "Filesystem Semaphore %.3d", i);
pInst->hSema = CreateSemaphore(NULL, 1, 1, pInst->acName);
if (pInst->hSema == NULL) {
FS_DEBUG_ERROROUT("FS_X_OS_Init: Could not create semaphore.");
return;
}
pInst++;
}
}
/*********************************************************************
*
* FS_X_OS_Delay
*
*/
void FS_X_OS_Delay (int ms) {
_CheckInit();
Sleep(ms);
}
/*********************************************************************
*
* FS_X_OS_GetTime
*
*/
U32 FS_X_OS_GetTime(void) {
_CheckInit();
return timeGetTime();
}
/*************************** End of file ****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -