Skip to content

Commit 392337b

Browse files
committed
Wrap the cache in a critical section
Git's error messages were being truncated. Turns out git used two threads, one writing to the console and one to file. This caused a conflict in `IsConsoleHandle` when the cache was updated. Making it a critical section solves the issue.
1 parent 0366daa commit 392337b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

ANSI.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,6 +3189,8 @@ BOOL IsConsoleHandle( HANDLE h )
31893189
{
31903190
int c;
31913191

3192+
EnterCriticalSection( &CritSect );
3193+
31923194
for (c = 0; c < CACHE; ++c)
31933195
if (cache[c].h == h)
31943196
{
@@ -3198,7 +3200,9 @@ BOOL IsConsoleHandle( HANDLE h )
31983200
do cache[c] = cache[c-1]; while (--c > 0);
31993201
cache[0] = tc;
32003202
}
3201-
return (cache[0].mode & ENABLE_PROCESSED_OUTPUT);
3203+
c = (cache[0].mode & ENABLE_PROCESSED_OUTPUT);
3204+
LeaveCriticalSection( &CritSect );
3205+
return c;
32023206
}
32033207

32043208
while (--c > 0)
@@ -3216,7 +3220,11 @@ BOOL IsConsoleHandle( HANDLE h )
32163220
cache[0].mode = ENABLE_PROCESSED_OUTPUT;
32173221
}
32183222

3219-
return (cache[0].mode & ENABLE_PROCESSED_OUTPUT);
3223+
c = (cache[0].mode & ENABLE_PROCESSED_OUTPUT);
3224+
3225+
LeaveCriticalSection( &CritSect );
3226+
3227+
return c;
32203228
}
32213229

32223230
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)