int Misc::file_Unlink(const char* path, int32_t maxAttempts ) { int32_t i; if( ! path || ! * path ) return -1; if( maxAttempts == 0 ) maxAttempts = 1; while( maxAttempts != 0 ) { if( _unlink( path ) != 0 ) return -1; i = 0; while( i < 100 ) { if( ! Misc::dir_Exists( path ) ) return 1; if( ++i > 50 ) // if it still doesn't show up, then we do some sleeping for the last 50ms _LUCENE_SLEEP( 1 ); } if( maxAttempts > 0 ) maxAttempts--; } return 0; }
bool LuceneLock::obtain(int64_t lockWaitTimeout) { bool locked = obtain(); if ( lockWaitTimeout < 0 && lockWaitTimeout != LOCK_OBTAIN_WAIT_FOREVER ) { _CLTHROWA(CL_ERR_IllegalArgument,"lockWaitTimeout should be LOCK_OBTAIN_WAIT_FOREVER or a non-negative number"); } int64_t maxSleepCount = lockWaitTimeout / LOCK_POLL_INTERVAL; int64_t sleepCount = 0; while (!locked) { if ( lockWaitTimeout != LOCK_OBTAIN_WAIT_FOREVER && sleepCount++ == maxSleepCount ) { _CLTHROWA(CL_ERR_IO,"Lock obtain timed out"); } _LUCENE_SLEEP(LOCK_POLL_INTERVAL); locked = obtain(); } return locked; }