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