// The mutex MUST be acquired before calling this function!
553727
func (p *IB) closeMatchedRequestWithoutMutex(id int64) {
	rep, ok := p.active[id]
	if ok {
	outer:
		for {
			// Drain the channel, if it needs it.
			select {
			case <-rep.dataChan:
			default:
				break outer
			}
		}

		delete(p.active, id)
		if rep.dataChan != nil {
			close(rep.dataChan)
		}
	}
}
258128
func CallFunc(receiver interface{}, methodName string, args ...interface{}) interface{} {
	var ptr reflect.Value
	var value reflect.Value

	value, ok := receiver.(reflect.Value)

	if !ok {
		value = reflect.ValueOf(receiver)
	}

	funcArgs := WrapArguments(args...)

	ptr, value = getReflectPtrAndValue(value, receiver)

	method := value.MethodByName(methodName)

	if method.IsValid() {
		return UnwrapReflectValues(method.Call(funcArgs))
	}

	method = ptr.MethodByName(methodName)

	if method.IsValid() {
		return UnwrapReflectValues(method.Call(funcArgs))
	}

	panic(fmt.Sprintf("%T type objects don't have %s method.", value.Interface(), methodName))
}
379887
func (c *Canceller) Cancel() {
	c.mutex.Lock()
	defer c.mutex.Unlock()
	c.cancel()
}
812628
func (m *RWMutex) Unlock() {
	m.mutex.Unlock()
	atomic.AddInt64(&m.writers, -1)
}
612756
func (rw LeveledRWMutex) AssertRLocked(lockState *LockState) {
	et := lockState.getExclusionType(rw.level)
	if et != readExclusion {
		panic(unexpectedExclusionTypeError{
			levelToString:         lockState.levelToString,
			level:                 rw.level,
			expectedExclusionType: readExclusion,
			exclusionType:         et,
		})
	}
}
96864
func (m *Mutex) Lock() error {
	m.nodem.Lock()
	defer m.nodem.Unlock()

	b := make([]byte, 16)
	_, err := rand.Read(b)
	if err != nil {
		return err
	}
	value := base64.StdEncoding.EncodeToString(b)

	expiry := m.Expiry
	if expiry == 0 {
		expiry = DefaultExpiry
	}

	retries := m.Tries
	if retries == 0 {
		retries = DefaultTries
	}

	for i := 0; i < retries; i++ {
		n := 0
		start := time.Now()
		for _, node := range m.nodes {
			if node == nil {
				continue
			}

			conn := node.Get()
			reply, err := redis.String(conn.Do("set", m.Name, value, "nx", "px", int(expiry/time.Millisecond)))
			conn.Close()
			if err != nil {
				continue
			}
			if reply != "OK" {
				continue
			}
			n++
		}

		factor := m.Factor
		if factor == 0 {
			factor = DefaultFactor
		}

		until := time.Now().Add(expiry - time.Now().Sub(start) - time.Duration(int64(float64(expiry)*factor)) + 2*time.Millisecond)
		if n >= m.Quorum && time.Now().Before(until) {
			m.value = value
			m.until = until
			return nil
		}
		for _, node := range m.nodes {
			if node == nil {
				continue
			}

			conn := node.Get()
			_, err := delScript.Do(conn, m.Name, value)
			conn.Close()
			if err != nil {
				continue
			}
		}

		// Have no delay on the last try so we can return ErrFailed sooner.
		if i == retries-1 {
			continue
		}

		delay := m.Delay
		if delay == 0 {
			delay = DefaultDelay
		}
		time.Sleep(delay)
	}

	return ErrFailed
}
842014
func (lk *etcdLock) Acquire(timeout uint64) error {
	lk.mutex.Lock()
	defer lk.mutex.Unlock()
	lk.timeout = timeout

	// Acquire in background
	go lk.acquireLock()

	return nil
}
552401
func (e *CElement) PrevWait() *CElement {
	for {
		e.mtx.RLock()
		prev := e.prev
		prevWg := e.prevWg
		removed := e.removed
		e.mtx.RUnlock()

		if prev != nil || removed {
			return prev
		}

		prevWg.Wait()
	}
}
550631
func (h *syncHandler) Init() error {
	defer h.mutex.Unlock()
	h.mutex.Lock()

	switch {
	case h.loaded:
		return nil
	default:
		if err := h.handler.Init(); err != nil {
			return err
		}
	}

	h.loaded = true
	return nil
}
765964
func (f *fragment) handleMutex(rowID, columnID uint64) error {
	if existingRowID, found, err := f.mutexVector.Get(columnID); err != nil {
		return errors.Wrap(err, "getting mutex vector data")
	} else if found && existingRowID != rowID {
		if _, err := f.unprotectedClearBit(existingRowID, columnID); err != nil {
			return errors.Wrap(err, "clearing mutex value")
		}
	}
	return nil
}
272027
func (mux *ServeMux) HandleFunc(m Matcher, h HandlerFunc) {
	mux.Handle(m, h)
}
338087
func (k *keyMutex) get(key string) *sync.Mutex {
	k.mu.Lock()
	mu, ok := k.mus[key]
	if !ok {
		mu = &sync.Mutex{}
		k.mus[key] = mu
	}
	k.mu.Unlock()
	return mu
}
256448
func noiseDial(idPriv *btcec.PrivateKey) func(net.Addr) (net.Conn, error) {
	return func(a net.Addr) (net.Conn, error) {
		lnAddr := a.(*lnwire.NetAddress)
		return brontide.Dial(idPriv, lnAddr, cfg.net.Dial)
	}
}
437408
func (mutex *Mutex) Lock() error {
	ret := int(C.SDL_LockMutex(mutex.cptr()))
	if ret != 0 {
		return GetError()
	}
	return nil
}
582585
func (m *RWMutex) Lock() {
	var caller string
	if _, file, line, ok := runtime.Caller(1); ok {
		caller = fmt.Sprintf("%s:%d", file, line)
	}
	if m.log {
		astilog.Debugf("Requesting lock for %s at %s", m.name, caller)
	}
	m.mutex.Lock()
	if m.log {
		astilog.Debugf("Lock acquired for %s at %s", m.name, caller)
	}
	m.lastSuccessfulLockCaller = caller
}
828525
func (mutex *Mutex) Unlock() error {
	ret := int(C.SDL_UnlockMutex(mutex.cptr()))
	if ret != 0 {
		return GetError()
	}
	return nil
}
74977
func (nm *NamedMutex) TryLockTimeout(name string, timeout time.Duration) 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
	case <-time.After(timeout):
		return false
	}
}