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.
@@ -370,12 +370,12 @@ int fscache_enable(size_t initial_size)
370
370
* opendir and lstat function pointers are redirected if
371
371
* any threads are using the fscache.
372
372
*/
373
+ EnterCriticalSection (& fscache_cs );
373
374
if (!initialized ) {
374
- InitializeCriticalSection (& mutex );
375
375
if (!dwTlsIndex ) {
376
376
dwTlsIndex = TlsAlloc ();
377
377
if (dwTlsIndex == TLS_OUT_OF_INDEXES ) {
378
- LeaveCriticalSection (& mutex );
378
+ LeaveCriticalSection (& fscache_cs );
379
379
return 0 ;
380
380
}
381
381
}
@@ -384,12 +384,13 @@ int fscache_enable(size_t initial_size)
384
384
opendir = fscache_opendir ;
385
385
lstat = fscache_lstat ;
386
386
}
387
- InterlockedIncrement (& initialized );
387
+ initialized ++ ;
388
+ LeaveCriticalSection (& fscache_cs );
388
389
389
390
/* refcount the thread specific initialization */
390
391
cache = fscache_getcache ();
391
392
if (cache ) {
392
- InterlockedIncrement ( & cache -> enabled ) ;
393
+ cache -> enabled ++ ;
393
394
} else {
394
395
cache = (struct fscache * )xcalloc (1 , sizeof (* cache ));
395
396
cache -> enabled = 1 ;
@@ -423,7 +424,7 @@ void fscache_disable(void)
423
424
BUG ("fscache_disable() called on a thread where fscache has not been initialized" );
424
425
if (!cache -> enabled )
425
426
BUG ("fscache_disable() called on an fscache that is already disabled" );
426
- InterlockedDecrement ( & cache -> enabled ) ;
427
+ cache -> enabled -- ;
427
428
if (!cache -> enabled ) {
428
429
TlsSetValue (dwTlsIndex , NULL );
429
430
trace_printf_key (& trace_fscache , "fscache_disable: lstat %u, opendir %u, "
@@ -436,12 +437,14 @@ void fscache_disable(void)
436
437
}
437
438
438
439
/* update the global fscache initialization */
439
- InterlockedDecrement (& initialized );
440
+ EnterCriticalSection (& fscache_cs );
441
+ initialized -- ;
440
442
if (!initialized ) {
441
443
/* reset opendir and lstat to the original implementations */
442
444
opendir = dirent_opendir ;
443
445
lstat = mingw_lstat ;
444
446
}
447
+ LeaveCriticalSection (& fscache_cs );
445
448
446
449
trace_printf_key (& trace_fscache , "fscache: disable\n" );
447
450
return ;
@@ -608,7 +611,7 @@ void fscache_merge(struct fscache *dest)
608
611
* isn't being used so the critical section only needs to prevent
609
612
* the the child threads from stomping on each other.
610
613
*/
611
- EnterCriticalSection (& mutex );
614
+ EnterCriticalSection (& fscache_cs );
612
615
613
616
hashmap_iter_init (& cache -> map , & iter );
614
617
while ((e = hashmap_iter_next (& iter )))
@@ -620,9 +623,9 @@ void fscache_merge(struct fscache *dest)
620
623
dest -> opendir_requests += cache -> opendir_requests ;
621
624
dest -> fscache_requests += cache -> fscache_requests ;
622
625
dest -> fscache_misses += cache -> fscache_misses ;
623
- LeaveCriticalSection (& mutex );
626
+ initialized -- ;
627
+ LeaveCriticalSection (& fscache_cs );
624
628
625
629
free (cache );
626
630
627
- InterlockedDecrement (& initialized );
628
631
}
0 commit comments