10
10
11
11
static volatile long initialized ;
12
12
static DWORD dwTlsIndex ;
13
- static CRITICAL_SECTION mutex ;
13
+ CRITICAL_SECTION fscache_cs ;
14
14
15
15
/*
16
16
* Store one fscache per thread to avoid thread contention and locking.
@@ -393,12 +393,12 @@ int fscache_enable(size_t initial_size)
393
393
* opendir and lstat function pointers are redirected if
394
394
* any threads are using the fscache.
395
395
*/
396
+ EnterCriticalSection (& fscache_cs );
396
397
if (!initialized ) {
397
- InitializeCriticalSection (& mutex );
398
398
if (!dwTlsIndex ) {
399
399
dwTlsIndex = TlsAlloc ();
400
400
if (dwTlsIndex == TLS_OUT_OF_INDEXES ) {
401
- LeaveCriticalSection (& mutex );
401
+ LeaveCriticalSection (& fscache_cs );
402
402
return 0 ;
403
403
}
404
404
}
@@ -407,12 +407,13 @@ int fscache_enable(size_t initial_size)
407
407
opendir = fscache_opendir ;
408
408
lstat = fscache_lstat ;
409
409
}
410
- InterlockedIncrement (& initialized );
410
+ initialized ++ ;
411
+ LeaveCriticalSection (& fscache_cs );
411
412
412
413
/* refcount the thread specific initialization */
413
414
cache = fscache_getcache ();
414
415
if (cache ) {
415
- InterlockedIncrement ( & cache -> enabled ) ;
416
+ cache -> enabled ++ ;
416
417
} else {
417
418
cache = (struct fscache * )xcalloc (1 , sizeof (* cache ));
418
419
cache -> enabled = 1 ;
@@ -446,7 +447,7 @@ void fscache_disable(void)
446
447
BUG ("fscache_disable() called on a thread where fscache has not been initialized" );
447
448
if (!cache -> enabled )
448
449
BUG ("fscache_disable() called on an fscache that is already disabled" );
449
- InterlockedDecrement ( & cache -> enabled ) ;
450
+ cache -> enabled -- ;
450
451
if (!cache -> enabled ) {
451
452
TlsSetValue (dwTlsIndex , NULL );
452
453
trace_printf_key (& trace_fscache , "fscache_disable: lstat %u, opendir %u, "
@@ -459,12 +460,14 @@ void fscache_disable(void)
459
460
}
460
461
461
462
/* update the global fscache initialization */
462
- InterlockedDecrement (& initialized );
463
+ EnterCriticalSection (& fscache_cs );
464
+ initialized -- ;
463
465
if (!initialized ) {
464
466
/* reset opendir and lstat to the original implementations */
465
467
opendir = dirent_opendir ;
466
468
lstat = mingw_lstat ;
467
469
}
470
+ LeaveCriticalSection (& fscache_cs );
468
471
469
472
trace_printf_key (& trace_fscache , "fscache: disable\n" );
470
473
return ;
@@ -638,7 +641,7 @@ void fscache_merge(struct fscache *dest)
638
641
* isn't being used so the critical section only needs to prevent
639
642
* the the child threads from stomping on each other.
640
643
*/
641
- EnterCriticalSection (& mutex );
644
+ EnterCriticalSection (& fscache_cs );
642
645
643
646
hashmap_iter_init (& cache -> map , & iter );
644
647
while ((e = hashmap_iter_next (& iter )))
@@ -650,9 +653,9 @@ void fscache_merge(struct fscache *dest)
650
653
dest -> opendir_requests += cache -> opendir_requests ;
651
654
dest -> fscache_requests += cache -> fscache_requests ;
652
655
dest -> fscache_misses += cache -> fscache_misses ;
653
- LeaveCriticalSection (& mutex );
656
+ initialized -- ;
657
+ LeaveCriticalSection (& fscache_cs );
654
658
655
659
free (cache );
656
660
657
- InterlockedDecrement (& initialized );
658
661
}
0 commit comments