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