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.
@@ -383,8 +383,8 @@ int fscache_enable(size_t initial_size)
383
383
* opendir and lstat function pointers are redirected if
384
384
* any threads are using the fscache.
385
385
*/
386
+ EnterCriticalSection (& fscache_cs );
386
387
if (!initialized ) {
387
- InitializeCriticalSection (& mutex );
388
388
if (!dwTlsIndex ) {
389
389
dwTlsIndex = TlsAlloc ();
390
390
if (dwTlsIndex == TLS_OUT_OF_INDEXES )
@@ -395,12 +395,13 @@ int fscache_enable(size_t initial_size)
395
395
opendir = fscache_opendir ;
396
396
lstat = fscache_lstat ;
397
397
}
398
- InterlockedIncrement (& initialized );
398
+ initialized ++ ;
399
+ LeaveCriticalSection (& fscache_cs );
399
400
400
401
/* refcount the thread specific initialization */
401
402
cache = fscache_getcache ();
402
403
if (cache ) {
403
- InterlockedIncrement ( & cache -> enabled ) ;
404
+ cache -> enabled ++ ;
404
405
} else {
405
406
cache = (struct fscache * )xcalloc (1 , sizeof (* cache ));
406
407
cache -> enabled = 1 ;
@@ -434,7 +435,7 @@ void fscache_disable(void)
434
435
BUG ("fscache_disable() called on a thread where fscache has not been initialized" );
435
436
if (!cache -> enabled )
436
437
BUG ("fscache_disable() called on an fscache that is already disabled" );
437
- InterlockedDecrement ( & cache -> enabled ) ;
438
+ cache -> enabled -- ;
438
439
if (!cache -> enabled ) {
439
440
TlsSetValue (dwTlsIndex , NULL );
440
441
trace_printf_key (& trace_fscache , "fscache_disable: lstat %u, opendir %u, "
@@ -447,12 +448,14 @@ void fscache_disable(void)
447
448
}
448
449
449
450
/* update the global fscache initialization */
450
- InterlockedDecrement (& initialized );
451
+ EnterCriticalSection (& fscache_cs );
452
+ initialized -- ;
451
453
if (!initialized ) {
452
454
/* reset opendir and lstat to the original implementations */
453
455
opendir = dirent_opendir ;
454
456
lstat = mingw_lstat ;
455
457
}
458
+ LeaveCriticalSection (& fscache_cs );
456
459
457
460
trace_printf_key (& trace_fscache , "fscache: disable\n" );
458
461
return ;
@@ -619,7 +622,7 @@ void fscache_merge(struct fscache *dest)
619
622
* isn't being used so the critical section only needs to prevent
620
623
* the the child threads from stomping on each other.
621
624
*/
622
- EnterCriticalSection (& mutex );
625
+ EnterCriticalSection (& fscache_cs );
623
626
624
627
hashmap_iter_init (& cache -> map , & iter );
625
628
while ((e = hashmap_iter_next (& iter )))
@@ -631,9 +634,9 @@ void fscache_merge(struct fscache *dest)
631
634
dest -> opendir_requests += cache -> opendir_requests ;
632
635
dest -> fscache_requests += cache -> fscache_requests ;
633
636
dest -> fscache_misses += cache -> fscache_misses ;
634
- LeaveCriticalSection (& mutex );
637
+ initialized -- ;
638
+ LeaveCriticalSection (& fscache_cs );
635
639
636
640
free (cache );
637
641
638
- InterlockedDecrement (& initialized );
639
642
}
0 commit comments