From 31d232d74a66e6dbc8f19f03d9f12e969ba35448 Mon Sep 17 00:00:00 2001 From: aoki_ryoma Date: Thu, 28 Aug 2008 01:21:56 +0000 Subject: [PATCH] =?UTF-8?q?mutex=E3=81=A7write()=E3=81=A8printf()=E3=82=92?= =?UTF-8?q?=E6=8E=92=E4=BB=96=E5=88=B6=E5=BE=A1=E3=81=AB=E3=80=82=20?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=AA=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=83=B3=E3=81=AE=E3=82=BF=E3=82=A4=E3=83=9F=E3=83=B3=E3=82=B0?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=9B=B4=E3=80=82=20write()=E3=81=A8printf?= =?UTF-8?q?=EF=BC=88=EF=BC=89=E3=81=AE=E9=A0=AD=E3=81=A7init=E6=B8=88?= =?UTF-8?q?=E3=81=BF=E3=81=8B=E3=81=A9=E3=81=86=E3=81=8B=E3=81=AE=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E5=85=A5=E3=82=8C=E3=81=9F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@2296 b08762b0-b915-fc4b-9d8c-17b2551a87ff --- .../errorLog/ARM9/src/errorLog.c | 68 ++++++++++++++----- include/sysmenu/errorLog.h | 7 ++ 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/build/libraries_sysmenu/errorLog/ARM9/src/errorLog.c b/build/libraries_sysmenu/errorLog/ARM9/src/errorLog.c index 474fd6ed..a2e9fd99 100644 --- a/build/libraries_sysmenu/errorLog/ARM9/src/errorLog.c +++ b/build/libraries_sysmenu/errorLog/ARM9/src/errorLog.c @@ -61,7 +61,7 @@ typedef enum CheckStatus { /*-- global variables ----------------------*/ ErrorLogWork elWork; - +static BOOL isInitialized = FALSE; /*-- function prototype ----------------------*/ CheckStatus ERRORLOGi_CheckAndCreateDirectory( const char *path ); CheckStatus ERRORLOGi_CheckAndCreateFile( const char *path ); @@ -92,15 +92,28 @@ static char *s_strError[FATAL_ERROR_MAX]; *---------------------------------------------------------------------------*/ BOOL ERRORLOG_Init( void* (*AllocFunc) (u32) , void (*FreeFunc) (void*) ) { + if( isInitialized ) + { + return FALSE ; + } + SDK_POINTER_ASSERT(AllocFunc); SDK_POINTER_ASSERT(FreeFunc); elWork.Alloc = AllocFunc; elWork.Free = FreeFunc; + OS_InitMutex( &elWork.mutex ); + OS_LockMutex( &elWork.mutex ); + // ログ読み出し用のバッファを確保 - elWork.entry = (ErrorLogEntry*) elWork.Alloc ( sizeof (ErrorLogEntry) * ERRORLOG_NUM_ENTRY ); - MI_CpuClear8( elWork.entry, sizeof (ErrorLogEntry) * ERRORLOG_NUM_ENTRY); + if( elWork.entry == NULL ) + { + elWork.entry = (ErrorLogEntry*) elWork.Alloc ( sizeof (ErrorLogEntry) * ERRORLOG_NUM_ENTRY ); + MI_CpuClear8( elWork.entry, sizeof (ErrorLogEntry) * ERRORLOG_NUM_ENTRY); + } + + SDK_ASSERT( elWork.entry ); if( !FS_IsAvailable() ) { @@ -113,12 +126,15 @@ BOOL ERRORLOG_Init( void* (*AllocFunc) (u32) , void (*FreeFunc) (void*) ) // ファイルの存在確認 if( ERRORLOGi_CheckAndCreateDirectory( ERRORLOG_DIRECTORYPATH ) == CHECK_FAILED ) { + OS_UnlockMutex( &elWork.mutex ); return FALSE; } + // ファイルの存在を確認、ついでに中でオープンしてエントリの読み込み switch ( ERRORLOGi_CheckAndCreateFile( ERRORLOG_FILEPATH ) ) { case CHECK_FAILED: + OS_UnlockMutex( &elWork.mutex ); return FALSE; break; @@ -132,6 +148,10 @@ BOOL ERRORLOG_Init( void* (*AllocFunc) (u32) , void (*FreeFunc) (void*) ) break; } + FS_CloseFile( &elWork.file ); + OS_UnlockMutex( &elWork.mutex ); + isInitialized = TRUE; + return TRUE; } @@ -159,10 +179,7 @@ void ERRORLOG_End( void ) elWork.Free( elWork.entry ); - if( !FS_CloseFile( &elWork.file ) ) - { - OS_TPrintf("EL Error: FS_CloseFile() failed.\n" ); - } + isInitialized = FALSE; } /*---------------------------------------------------------------------------* @@ -178,10 +195,18 @@ BOOL ERRORLOG_Printf( const char *fmt, ... ) { BOOL result = TRUE; va_list arglist; + + if( !isInitialized ) + { + return FALSE; + } + + OS_LockMutex( &elWork.mutex ); va_start( arglist, fmt ); result = ERRORLOGi_WriteCommon( FALSE, 0, fmt, arglist ); va_end( arglist ); - + OS_UnlockMutex( &elWork.mutex ); + return result; } @@ -196,7 +221,18 @@ BOOL ERRORLOG_Printf( const char *fmt, ... ) *---------------------------------------------------------------------------*/ BOOL ERRORLOG_Write( u64 errorCode ) { - return ERRORLOGi_WriteCommon( TRUE, errorCode, NULL, NULL ); + BOOL res; + + if( !isInitialized ) + { + return FALSE; + } + + OS_LockMutex( &elWork.mutex ); + res = ERRORLOGi_WriteCommon( TRUE, errorCode, NULL, NULL ); + OS_UnlockMutex( &elWork.mutex ); + + return res; } /*---------------------------------------------------------------------------* @@ -673,9 +709,6 @@ void ERRORLOGi_WriteLogToBuf( char *buf ) int counter; int counterMax = elWork.numEntry <= ERRORLOG_NUM_ENTRY ? elWork.numEntry : ERRORLOG_NUM_ENTRY ; - // ファイルの頭に戻って書き込みなおす - FS_SeekFileToBegin( &elWork.file ); - for( counter = 0; counter < counterMax ; counter++ ) { // bufに一エントリずつ文字列化して詰めていく @@ -704,20 +737,23 @@ void ERRORLOGi_WriteLogToBuf( char *buf ) BOOL ERRORLOGi_WriteLogToFile( char *buf ) { - FSResult res; - + // ファイルの頭に戻って書き込みなおす + FS_OpenFileEx( &elWork.file, ERRORLOG_FILEPATH, FS_FILEMODE_W ); FS_SeekFileToBegin( &elWork.file ); + if( FS_WriteFile( &elWork.file, buf, ERRORLOG_SIZE ) != ERRORLOG_SIZE ) { OS_TPrintf("EL Error: FS_WriteFile() failed.\n"); + FS_CloseFile( &elWork.file ); return FALSE; } - if( ( res = FS_FlushFile( &elWork.file )) != FS_RESULT_SUCCESS ) + if( ! FS_CloseFile( &elWork.file ) ) { - OS_TPrintf("EL Error: FS_FlushFile() failed. FSResult: %d\n", res); + OS_TPrintf("EL Error: FS_CloseFile() in WriteLogToFile() failed."); return FALSE; } + return TRUE; } diff --git a/include/sysmenu/errorLog.h b/include/sysmenu/errorLog.h index 9dba31b0..425fe1ec 100644 --- a/include/sysmenu/errorLog.h +++ b/include/sysmenu/errorLog.h @@ -65,12 +65,19 @@ typedef struct ErrorLogWork{ // メモリ確保用関数 void* (*Alloc) ( u32 ) ; void (*Free) ( void* ) ; + // エラーログエントリ保持用変数 ErrorLogEntry *entry; + // エラーログのエントリ数 int numEntry; + // エラーログのファイルポインタ FSFile file; + + // 排他制御用Mutex + OSMutex mutex; + } ErrorLogWork;