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.
@@ -392,8 +392,8 @@ int fscache_enable(size_t initial_size)
392
392
* opendir and lstat function pointers are redirected if
393
393
* any threads are using the fscache.
394
394
*/
395
+ EnterCriticalSection (& fscache_cs );
395
396
if (!initialized ) {
396
- InitializeCriticalSection (& mutex );
397
397
if (!dwTlsIndex ) {
398
398
dwTlsIndex = TlsAlloc ();
399
399
if (dwTlsIndex == TLS_OUT_OF_INDEXES )
@@ -404,12 +404,13 @@ int fscache_enable(size_t initial_size)
404
404
opendir = fscache_opendir ;
405
405
lstat = fscache_lstat ;
406
406
}
407
- InterlockedIncrement (& initialized );
407
+ initialized ++ ;
408
+ LeaveCriticalSection (& fscache_cs );
408
409
409
410
/* refcount the thread specific initialization */
410
411
cache = fscache_getcache ();
411
412
if (cache ) {
412
- InterlockedIncrement ( & cache -> enabled ) ;
413
+ cache -> enabled ++ ;
413
414
} else {
414
415
cache = (struct fscache * )xcalloc (1 , sizeof (* cache ));
415
416
cache -> enabled = 1 ;
@@ -443,7 +444,7 @@ void fscache_disable(void)
443
444
BUG ("fscache_disable() called on a thread where fscache has not been initialized" );
444
445
if (!cache -> enabled )
445
446
BUG ("fscache_disable() called on an fscache that is already disabled" );
446
- InterlockedDecrement ( & cache -> enabled ) ;
447
+ cache -> enabled -- ;
447
448
if (!cache -> enabled ) {
448
449
TlsSetValue (dwTlsIndex , NULL );
449
450
trace_printf_key (& trace_fscache , "fscache_disable: lstat %u, opendir %u, "
@@ -456,12 +457,14 @@ void fscache_disable(void)
456
457
}
457
458
458
459
/* update the global fscache initialization */
459
- InterlockedDecrement (& initialized );
460
+ EnterCriticalSection (& fscache_cs );
461
+ initialized -- ;
460
462
if (!initialized ) {
461
463
/* reset opendir and lstat to the original implementations */
462
464
opendir = dirent_opendir ;
463
465
lstat = mingw_lstat ;
464
466
}
467
+ LeaveCriticalSection (& fscache_cs );
465
468
466
469
trace_printf_key (& trace_fscache , "fscache: disable\n" );
467
470
return ;
@@ -628,7 +631,7 @@ void fscache_merge(struct fscache *dest)
628
631
* isn't being used so the critical section only needs to prevent
629
632
* the the child threads from stomping on each other.
630
633
*/
631
- EnterCriticalSection (& mutex );
634
+ EnterCriticalSection (& fscache_cs );
632
635
633
636
hashmap_iter_init (& cache -> map , & iter );
634
637
while ((e = hashmap_iter_next (& iter )))
@@ -640,9 +643,9 @@ void fscache_merge(struct fscache *dest)
640
643
dest -> opendir_requests += cache -> opendir_requests ;
641
644
dest -> fscache_requests += cache -> fscache_requests ;
642
645
dest -> fscache_misses += cache -> fscache_misses ;
643
- LeaveCriticalSection (& mutex );
646
+ initialized -- ;
647
+ LeaveCriticalSection (& fscache_cs );
644
648
645
649
free (cache );
646
650
647
- InterlockedDecrement (& initialized );
648
651
}
0 commit comments