7
7
8
8
static volatile long initialized ;
9
9
static DWORD dwTlsIndex ;
10
- static CRITICAL_SECTION mutex ;
10
+ CRITICAL_SECTION fscache_cs ;
11
11
12
12
/*
13
13
* Store one fscache per thread to avoid thread contention and locking.
@@ -385,12 +385,12 @@ int fscache_enable(size_t initial_size)
385
385
* opendir and lstat function pointers are redirected if
386
386
* any threads are using the fscache.
387
387
*/
388
+ EnterCriticalSection (& fscache_cs );
388
389
if (!initialized ) {
389
- InitializeCriticalSection (& mutex );
390
390
if (!dwTlsIndex ) {
391
391
dwTlsIndex = TlsAlloc ();
392
392
if (dwTlsIndex == TLS_OUT_OF_INDEXES ) {
393
- LeaveCriticalSection (& mutex );
393
+ LeaveCriticalSection (& fscache_cs );
394
394
return 0 ;
395
395
}
396
396
}
@@ -399,12 +399,13 @@ int fscache_enable(size_t initial_size)
399
399
opendir = fscache_opendir ;
400
400
lstat = fscache_lstat ;
401
401
}
402
- InterlockedIncrement (& initialized );
402
+ initialized ++ ;
403
+ LeaveCriticalSection (& fscache_cs );
403
404
404
405
/* refcount the thread specific initialization */
405
406
cache = fscache_getcache ();
406
407
if (cache ) {
407
- InterlockedIncrement ( & cache -> enabled ) ;
408
+ cache -> enabled ++ ;
408
409
} else {
409
410
cache = (struct fscache * )xcalloc (1 , sizeof (* cache ));
410
411
cache -> enabled = 1 ;
@@ -438,7 +439,7 @@ void fscache_disable(void)
438
439
BUG ("fscache_disable() called on a thread where fscache has not been initialized" );
439
440
if (!cache -> enabled )
440
441
BUG ("fscache_disable() called on an fscache that is already disabled" );
441
- InterlockedDecrement ( & cache -> enabled ) ;
442
+ cache -> enabled -- ;
442
443
if (!cache -> enabled ) {
443
444
TlsSetValue (dwTlsIndex , NULL );
444
445
trace_printf_key (& trace_fscache , "fscache_disable: lstat %u, opendir %u, "
@@ -451,12 +452,14 @@ void fscache_disable(void)
451
452
}
452
453
453
454
/* update the global fscache initialization */
454
- InterlockedDecrement (& initialized );
455
+ EnterCriticalSection (& fscache_cs );
456
+ initialized -- ;
455
457
if (!initialized ) {
456
458
/* reset opendir and lstat to the original implementations */
457
459
opendir = dirent_opendir ;
458
460
lstat = mingw_lstat ;
459
461
}
462
+ LeaveCriticalSection (& fscache_cs );
460
463
461
464
trace_printf_key (& trace_fscache , "fscache: disable\n" );
462
465
return ;
@@ -623,7 +626,7 @@ void fscache_merge(struct fscache *dest)
623
626
* isn't being used so the critical section only needs to prevent
624
627
* the the child threads from stomping on each other.
625
628
*/
626
- EnterCriticalSection (& mutex );
629
+ EnterCriticalSection (& fscache_cs );
627
630
628
631
hashmap_iter_init (& cache -> map , & iter );
629
632
while ((e = hashmap_iter_next (& iter )))
@@ -635,9 +638,9 @@ void fscache_merge(struct fscache *dest)
635
638
dest -> opendir_requests += cache -> opendir_requests ;
636
639
dest -> fscache_requests += cache -> fscache_requests ;
637
640
dest -> fscache_misses += cache -> fscache_misses ;
638
- LeaveCriticalSection (& mutex );
641
+ initialized -- ;
642
+ LeaveCriticalSection (& fscache_cs );
639
643
640
644
free (cache );
641
645
642
- InterlockedDecrement (& initialized );
643
646
}
0 commit comments