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.
@@ -388,12 +388,12 @@ int fscache_enable(size_t initial_size)
388
388
* opendir and lstat function pointers are redirected if
389
389
* any threads are using the fscache.
390
390
*/
391
+ EnterCriticalSection (& fscache_cs );
391
392
if (!initialized ) {
392
- InitializeCriticalSection (& mutex );
393
393
if (!dwTlsIndex ) {
394
394
dwTlsIndex = TlsAlloc ();
395
395
if (dwTlsIndex == TLS_OUT_OF_INDEXES ) {
396
- LeaveCriticalSection (& mutex );
396
+ LeaveCriticalSection (& fscache_cs );
397
397
return 0 ;
398
398
}
399
399
}
@@ -402,12 +402,13 @@ int fscache_enable(size_t initial_size)
402
402
opendir = fscache_opendir ;
403
403
lstat = fscache_lstat ;
404
404
}
405
- InterlockedIncrement (& initialized );
405
+ initialized ++ ;
406
+ LeaveCriticalSection (& fscache_cs );
406
407
407
408
/* refcount the thread specific initialization */
408
409
cache = fscache_getcache ();
409
410
if (cache ) {
410
- InterlockedIncrement ( & cache -> enabled ) ;
411
+ cache -> enabled ++ ;
411
412
} else {
412
413
cache = (struct fscache * )xcalloc (1 , sizeof (* cache ));
413
414
cache -> enabled = 1 ;
@@ -441,7 +442,7 @@ void fscache_disable(void)
441
442
BUG ("fscache_disable() called on a thread where fscache has not been initialized" );
442
443
if (!cache -> enabled )
443
444
BUG ("fscache_disable() called on an fscache that is already disabled" );
444
- InterlockedDecrement ( & cache -> enabled ) ;
445
+ cache -> enabled -- ;
445
446
if (!cache -> enabled ) {
446
447
TlsSetValue (dwTlsIndex , NULL );
447
448
trace_printf_key (& trace_fscache , "fscache_disable: lstat %u, opendir %u, "
@@ -454,12 +455,14 @@ void fscache_disable(void)
454
455
}
455
456
456
457
/* update the global fscache initialization */
457
- InterlockedDecrement (& initialized );
458
+ EnterCriticalSection (& fscache_cs );
459
+ initialized -- ;
458
460
if (!initialized ) {
459
461
/* reset opendir and lstat to the original implementations */
460
462
opendir = dirent_opendir ;
461
463
lstat = mingw_lstat ;
462
464
}
465
+ LeaveCriticalSection (& fscache_cs );
463
466
464
467
trace_printf_key (& trace_fscache , "fscache: disable\n" );
465
468
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