Author: tretiakov
Date: Thu Jun 29 21:36:04 2006
New Revision: 22691
URL:
http://svn.reactos.org/svn/reactos?rev=22691&view=rev
Log:
Fix thread synchronization, use critical sections.
Rewrite some functions (optimize).
Modified:
trunk/reactos/base/services/eventlog/eventlog.c
trunk/reactos/base/services/eventlog/file.c
Modified: trunk/reactos/base/services/eventlog/eventlog.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eve…
==============================================================================
--- trunk/reactos/base/services/eventlog/eventlog.c (original)
+++ trunk/reactos/base/services/eventlog/eventlog.c Thu Jun 29 21:36:04 2006
@@ -22,7 +22,10 @@
HANDLE MyHeap = NULL;
PLOGFILE SystemLog = NULL;
PLOGFILE ApplicationLog = NULL;
+PLOGFILE SecurityLog = NULL;
BOOL onLiveCD = FALSE; // On livecd events will go to debug output only
+
+extern CRITICAL_SECTION LogListCs;
VOID CALLBACK ServiceMain(DWORD argc, LPTSTR *argv)
{
@@ -65,6 +68,8 @@
return 1;
}
+ InitializeCriticalSection(&LogListCs);
+
/*
This will be fixed in near future
*/
@@ -103,7 +108,9 @@
StartServiceCtrlDispatcher(ServiceTable);
+
LogfClose(SystemLog);
+ DeleteCriticalSection(&LogListCs);
HeapDestroy(MyHeap);
return 0;
Modified: trunk/reactos/base/services/eventlog/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/fil…
==============================================================================
--- trunk/reactos/base/services/eventlog/file.c (original)
+++ trunk/reactos/base/services/eventlog/file.c Thu Jun 29 21:36:04 2006
@@ -8,7 +8,8 @@
#include "eventlog.h"
-PLOGFILE _LogListHead = NULL;
+PLOGFILE LogListHead = NULL;
+CRITICAL_SECTION LogListCs;
extern HANDLE MyHeap;
BOOL LogfInitializeNew(PLOGFILE LogFile)
@@ -292,107 +293,118 @@
return;
}
-PLOGFILE LogfListHead()
-{
- return _LogListHead;
-}
-
PLOGFILE LogfListItemByName(WCHAR *Name)
{
- PLOGFILE Item;
- Item = LogfListHead();
- while(Item)
- {
+ PLOGFILE Item, Ret = NULL;
+
+ EnterCriticalSection(&LogListCs);
+
+ for(Item = LogListHead; Item; Item = (PLOGFILE)Item->Next)
if(Item->LogName && lstrcmpW(Item->LogName, Name)==0)
- return Item;
- Item = (PLOGFILE)Item->Next;
- }
- return NULL;
+ {
+ Ret = Item;
+ break;
+ }
+
+ LeaveCriticalSection(&LogListCs);
+ return Ret;
}
/* index starting from 1 */
INT LogfListItemIndexByName(WCHAR *Name)
{
PLOGFILE Item;
- INT i = 1;
-
- Item = LogfListHead();
-
- while(Item)
- {
+ INT ret = 0, i = 1;
+
+ EnterCriticalSection(&LogListCs);
+
+ for(Item = LogListHead; Item; i++, Item = (PLOGFILE)Item->Next)
if(Item->LogName && lstrcmpW(Item->LogName, Name)==0)
- return i;
- Item = (PLOGFILE)Item->Next;
- i++;
- }
-
- return 0;
+ {
+ ret = i;
+ break;
+ }
+
+ LeaveCriticalSection(&LogListCs);
+ return ret;
}
/* index starting from 1 */
PLOGFILE LogfListItemByIndex(INT Index)
{
INT i = 1;
- PLOGFILE Item;
- Item = LogfListHead();
- while(Item)
+ PLOGFILE Item = LogListHead;
+
+ EnterCriticalSection(&LogListCs);
+ for(; Item && i<Index; Item = (PLOGFILE)Item->Next, i++);
+ LeaveCriticalSection(&LogListCs);
+
+ return Item;
+}
+
+INT LogfListItemCount()
+{
+ PLOGFILE Item = LogListHead;
+ INT i = 0;
+
+ EnterCriticalSection(&LogListCs);
+ while(Item)
{
- if(i == Index)
- return Item;
- i++;
- Item = (PLOGFILE)Item->Next;
- }
- return NULL;
-}
-
-INT LogfListItemCount()
-{
- PLOGFILE Item = NULL;
- INT i = 1;
- Item = LogfListHead();
- if(Item)
- {
- while(Item->Next)
- {
- i++;
- Item = (PLOGFILE) Item->Next;
- }
- return i;
- }
- else return 0;
+ i++;
+ Item = (PLOGFILE) Item->Next;
+ }
+ LeaveCriticalSection(&LogListCs);
+
+ return i;
}
VOID LogfListAddItem(PLOGFILE Item)
{
- PLOGFILE List;
-
- List = LogfListHead();
-
- if(List)
+ EnterCriticalSection(&LogListCs);
+
+ if(LogListHead)
{
+ PLOGFILE List = LogListHead;
+
while(List->Next)
List = (PLOGFILE)List->Next;
+
Item->Prev = (PVOID)List;
Item->Next = NULL;
- InterlockedExchange((PLONG)&List->Next, (LONG)Item);
- }
- else {
+ List->Next = Item;
+ }
+ else
+ {
Item->Next = NULL;
Item->Prev = NULL;
- InterlockedExchange((PLONG)&_LogListHead, (LONG)Item);
- }
+ LogListHead = Item;
+ }
+
+ LeaveCriticalSection(&LogListCs);
}
VOID LogfListRemoveItem(PLOGFILE Item)
{
- if(Item->Prev)
+ PLOGFILE prev = (PLOGFILE)Item->Prev;
+ PLOGFILE next = (PLOGFILE)Item->Next;
+
+ EnterCriticalSection(&LogListCs);
+
+ if(prev && next)
{
- InterlockedExchange((PLONG)&((PLOGFILE)Item->Prev)->Next,
- (LONG)Item->Next);
- }
- else {
- InterlockedExchange((PLONG)&_LogListHead, (LONG)Item->Next);
- }
+ prev->Next = next;
+ next->Prev = prev;
+ }
+ else if(next)
+ {
+ LogListHead = next;
+ next->Prev = NULL;
+ }
+ else if(prev) prev->Next = NULL;
+ else LogListHead = NULL;
+
+ LeaveCriticalSection(&LogListCs);
+
}
BOOL LogfReadEvent(PLOGFILE LogFile,
@@ -562,7 +574,7 @@
ULONG LogfOffsetByNumber(PLOGFILE LogFile,
DWORD RecordNumber)
-/* Returns NULL if nothing found. */
+/* Returns 0 if nothing found. */
{
DWORD i;
for(i = 0; i < LogFile->OffsetInfoNext; i++)