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