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