code: func (fm *filesManager) trySwitchState(file *file, newState int32) (bool, error) {
  	wasOpened := false
  	wasClosed := false
  	for i := 0; i < 10000; i++ {
  		if atomic.CompareAndSwapInt32(&file.state, fileOpened, newState) {
  			wasOpened = true
  			break
  		}
  		if atomic.CompareAndSwapInt32(&file.state, fileClosed, newState) {
  			wasClosed = true
  			break
  		}
  		if i%1000 == 1 {
  			time.Sleep(time.Millisecond)
  		}
  	}
  	if !wasOpened && !wasClosed {
  		return false, fmt.Errorf("file %q is still probably locked", file.name)
  	}
  	return wasOpened, nil
  }
docs: // trySwitchState attempts to switch an initial state of `fileOpened`
  // or `fileClosed` to the given newState. If it can't it will return an
  // error, otherwise, returned a boolean to indicate if the initial state
  // was `fileOpened`.