CPLMutexHolder::CPLMutexHolder( void **phMutex, double dfWaitInSeconds, const char *pszFileIn, int nLineIn ) { #ifndef MUTEX_NONE pszFile = pszFileIn; nLine = nLineIn; #ifdef DEBUG_MUTEX CPLDebug( "MH", "Request %p for pid %ld at %d/%s", *phMutex, (long) CPLGetPID(), nLine, pszFile ); #endif if( !CPLCreateOrAcquireMutex( phMutex, dfWaitInSeconds ) ) { CPLDebug( "CPLMutexHolder", "failed to acquire mutex!" ); hMutex = NULL; } else { #ifdef DEBUG_MUTEX CPLDebug( "MH", "Acquired %p for pid %ld at %d/%s", *phMutex, (long) CPLGetPID(), nLine, pszFile ); #endif hMutex = *phMutex; } #endif /* ndef MUTEX_NONE */ }
CPLMutexHolder::CPLMutexHolder( void **phMutex, double dfWaitInSeconds, const char *pszFileIn, int nLineIn ) { #ifndef MUTEX_NONE pszFile = pszFileIn; nLine = nLineIn; #ifdef DEBUG_MUTEX /* * XXX: There is no way to use CPLDebug() here because it works with * mutexes itself so we will fall in infinite recursion. Good old * fprintf() will do the job right. */ fprintf( stderr, "CPLMutexHolder: Request %p for pid %ld at %d/%s.\n", *phMutex, (long) CPLGetPID(), nLine, pszFile ); #endif if( !CPLCreateOrAcquireMutex( phMutex, dfWaitInSeconds ) ) { fprintf( stderr, "CPLMutexHolder: Failed to acquire mutex!\n" ); hMutex = NULL; } else { #ifdef DEBUG_MUTEX fprintf( stderr, "CPLMutexHolder: Acquired %p for pid %ld at %d/%s.\n", *phMutex, (long) CPLGetPID(), nLine, pszFile ); #endif hMutex = *phMutex; } #endif /* ndef MUTEX_NONE */ }