// TryLockTimeout tries to acquires the lock returning true on success.
// Attempt to acquire the lock will timeout after the caller defined interval.
340677
func (tm TryMutex) TryLockTimeout(timeout time.Duration) bool {
	select {
	case tm.c <- struct{}{}:
		return true
	case <-time.After(timeout):
		return false
	}
}
54340
func (sem *boundedSemaphore) TryAcquire(timeout time.Duration) bool {
	if timeout > 0 {
		// Wait until we get a slot or timeout expires.
		tm := time.NewTimer(timeout)
		defer tm.Stop()
		select {
		case <-sem.slots:
			return true
		case <-tm.C:
			// Timeout expired. In very rare cases this might happen even if
			// there is a slot available, e.g. GC pause after we create the timer
			// and select randomly picked this one out of the two available channels.
			// We should do one final immediate check below.
		}
	}

	// Return true if we have a slot available immediately and false otherwise.
	select {
	case <-sem.slots:
		return true
	default:
		return false
	}
}
521227
func (s *NodesStatsService) Timeout(timeout string) *NodesStatsService {
	s.timeout = timeout
	return s
}
600399
func (b *UpdateService) Timeout(timeout string) *UpdateService {
	b.timeout = timeout
	return b
}
227926
func StopTimeout(timeout time.Duration) Option {
	return func(o *Options) {
		o.StopTimeout = timeout
	}
}
321996
func (b *BaseKvdb) SetLockTimeout(timeout time.Duration) {
	b.lock.Lock()
	defer b.lock.Unlock()
	logrus.Infof("Setting lock timeout to: %v", timeout)
	b.LockTimeout = timeout
}
504588
func (s *UpdateByQueryService) Timeout(timeout string) *UpdateByQueryService {
	s.timeout = timeout
	return s
}
8463
func (s *DeleteByQueryService) Timeout(timeout string) *DeleteByQueryService {
	s.timeout = timeout
	return s
}
249086
func (s *IndicesCreateService) MasterTimeout(masterTimeout string) *IndicesCreateService {
	s.masterTimeout = masterTimeout
	return s
}
222903
func (l *Lock) attemptLock(stopCh <-chan struct{}) (bool, error) {
	ticker := time.NewTicker(l.retryInterval)
	defer ticker.Stop()

	for {
		select {
		case <-ticker.C:
			acquired, err := l.writeLock()
			if err != nil {
				return false, errwrap.Wrapf("attempt lock: {{err}}", err)
			}
			if !acquired {
				continue
			}

			return true, nil
		case <-stopCh:
			return false, nil
		}
	}
}
460533
func (s *PutMappingService) Timeout(timeout string) *PutMappingService {
	s.timeout = timeout
	return s
}
784779
func (s *SearchSource) Timeout(timeout string) *SearchSource {
	s.timeout = timeout
	return s
}
234900
func (cond *Cond) WaitTimeout(mutex *Mutex, ms uint32) error {
	ret := int(C.SDL_CondWaitTimeout(cond.cptr(), mutex.cptr(), C.Uint32(ms)))
	if ret != 0 {
		return GetError()
	}
	return nil
}
362562
func (nm *NamedMutex) TryLock(name string) bool {
	nm.localMutex.Lock()
	mc, ok := nm.mutexMap[name]
	if !ok {
		mc = make(chan struct{}, 1)
		nm.mutexMap[name] = mc
	}
	nm.localMutex.Unlock()
	select {
	case mc <- struct{}{}:
		return true
	default:
		return false
	}
}
999366
func (s *IndicesPutTemplateService) Timeout(timeout string) *IndicesPutTemplateService {
	s.timeout = timeout
	return s
}
895721
func (s *OpenIndexService) Timeout(timeout string) *OpenIndexService {
	s.timeout = timeout
	return s
}
340066
func (b *BaseKvdb) GetLockTimeout() time.Duration {
	b.lock.Lock()
	defer b.lock.Unlock()
	return b.LockTimeout
}