Skip to content

Commit

Permalink
ecere/sys/File: Only updating openCount in _DEBUG
Browse files Browse the repository at this point in the history
- Also fixed a race condition on modifying openCount
  • Loading branch information
jerstlouis committed Sep 12, 2023
1 parent 152fb12 commit f2cad7a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ecere/src/sys/File.ec
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,20 @@ public class File : IOChannel
{
if(output && output != input)
{
#ifdef _DEBUG
openCountMutex.Wait();
openCount--;
openCountMutex.Release();
#endif
fclose(output);
}
if(input)
{
#ifdef _DEBUG
openCountMutex.Wait();
openCount--;
openCountMutex.Release();
#endif
fclose(input);
}
input = null;
Expand Down Expand Up @@ -843,7 +851,11 @@ public:
if(!input && !output);
else
{
#ifdef _DEBUG
openCountMutex.Wait();
openCount++;
openCountMutex.Release();
#endif
result = true;
// TESTING ENABLING FILE BUFFERING BY DEFAULT... DOCUMENT ANY ISSUE
/*
Expand Down Expand Up @@ -1002,7 +1014,10 @@ public FileAttribs FileExists(const char * fileName)
return FILE_FileExists(fileName);
}

#ifdef _DEBUG
static int openCount;
static Mutex openCountMutex { };
#endif

public File FileOpen(const char * fileName, FileOpenMode mode)
{
Expand Down Expand Up @@ -1054,7 +1069,11 @@ public File FileOpen(const char * fileName, FileOpenMode mode)
if(!file.input && !file.output);
else
{
#ifdef _DEBUG
openCountMutex.Wait();
openCount++;
openCountMutex.Release();
#endif
result = file;
// TESTING ENABLING FILE BUFFERING BY DEFAULT... DOCUMENT ANY ISSUE
/*
Expand Down

0 comments on commit f2cad7a

Please sign in to comment.