// Unlock unlocks a document which was locked with GetAndLock.
961065
func (c *Collection) Unlock(key string, opts *UnlockOptions) (mutOut *MutationResult, errOut error) {
	if opts == nil {
		opts = &UnlockOptions{}
	}

	span := c.startKvOpTrace(opts.ParentSpanContext, "Unlock")
	defer span.Finish()

	ctx, cancel := c.context(opts.Context, opts.Timeout)
	if cancel != nil {
		defer cancel()
	}

	res, err := c.unlock(ctx, span.Context(), key, *opts)
	if err != nil {
		return nil, err
	}

	return res, nil
}
409049
func (f *File) Unlock() (err error) {
	f.lockedLock.Lock()
	defer f.lockedLock.Unlock()
	if !f.locked {
		return nil
	}

	// Send the event only if f.locked == true.
	done := make(chan struct{})
	f.fs.sendEvents(FSEvent{
		EventType: FSEventUnlock,
		File:      f,
		Done:      done,
	})
	defer close(done)

	defer func() {
		if err == nil {
			f.locked = false
		}
	}()

	err = f.fs.SyncAll()
	if err != nil {
		return err
	}
	jManager, err := libkbfs.GetJournalManager(f.fs.config)
	if err != nil {
		return err
	}
	jStatus, _ := jManager.JournalStatus(f.fs.root.GetFolderBranch().Tlf)
	if jStatus.RevisionStart == kbfsmd.RevisionUninitialized {
		// Journal MDs are all flushed and we haven't made any more writes.
		// Calling FinishSingleOp won't make it to the server, so we make a
		// naked request to server just to release the lock.
		return f.fs.config.MDServer().ReleaseLock(f.fs.ctx,
			f.fs.root.GetFolderBranch().Tlf, f.getLockID())
	}

	if f.fs.config.Mode().Type() == libkbfs.InitSingleOp {
		err = jManager.FinishSingleOp(f.fs.ctx,
			f.fs.root.GetFolderBranch().Tlf, &keybase1.LockContext{
				RequireLockID:       f.getLockID(),
				ReleaseAfterSuccess: true,
			}, f.fs.priority)
		if err != nil {
			return err
		}
	} else {
		err = jManager.WaitForCompleteFlush(
			f.fs.ctx, f.fs.root.GetFolderBranch().Tlf)
		if err != nil {
			return err
		}

		f.fs.log.CDebugf(f.fs.ctx, "Releasing the lock")

		// Need to explicitly release the lock from the server. If
		// single-op mode isn't enabled, then the journal will be
		// flushing on its own without waiting for the call to
		// `FinishSingleOp`. That means the journal can already be
		// completely flushed by the time `FinishSingleOp` is called,
		// and it will be a no-op. It won't have made any call to the
		// server to release the lock, so we have to do it explicitly
		// here.
		err = f.fs.config.MDServer().ReleaseLock(
			f.fs.ctx, f.fs.root.GetFolderBranch().Tlf, f.getLockID())
		if err != nil {
			return err
		}
	}
	return nil
}
79219
func (ks *KeyStore) Unlock(account *Account, passphrase string) error {
	return ks.keystore.TimedUnlock(account.account, passphrase, 0)
}
288705
func (m *Mutex) Unlock() bool {
	n := m.actOnPoolsAsync(func(pool Pool) bool {
		return m.release(pool, m.value)
	})
	return n >= m.quorum
}
40919
func (l *Locker) Unlock() error {
	l.mutex.Lock()
	err := l.release()
	l.mutex.Unlock()

	return err
}
1120388
func NewUnlock(g *libkb.GlobalContext) *Unlock {
	return &Unlock{
		Contextified: libkb.NewContextified(g),
	}
}
887058
func lockSandbox(sandboxPath string) (*os.File, error) {
	lockFilePath := filepath.Join(sandboxPath, "sandbox.lock")

	lockFile, err := os.OpenFile(lockFilePath, os.O_RDWR|os.O_CREATE, 0755)
	if err != nil {
		return nil, err
	}

	err = syscall.Flock(int(lockFile.Fd()), syscall.LOCK_EX)
	if err != nil {
		lockFile.Close()
		return nil, err
	}

	return lockFile, nil
}
1316917
func (m *Mutex) Unlock() bool {
	m.nodem.Lock()
	defer m.nodem.Unlock()

	value := m.value
	if value == "" {
		panic("redsync: unlock of unlocked mutex")
	}

	m.value = ""
	m.until = time.Unix(0, 0)

	n := 0
	for _, node := range m.nodes {
		if node == nil {
			continue
		}

		conn := node.Get()
		status, err := delScript.Do(conn, m.Name, value)
		conn.Close()
		if err != nil {
			continue
		}
		if status == 0 {
			continue
		}
		n++
	}
	if n >= m.Quorum {
		return true
	}
	return false
}
791186
func (ks *KeyStore) Unlock(a accounts.Account, passphrase string) error {
	return ks.TimedUnlock(a, passphrase, 0)
}
869215
func (m *Mutex) Lock(ctx context.Context) error {
	lockCtx, cancel := context.WithTimeout(ctx, m.timeout)
	defer cancel()
	return m.mutex.Lock(lockCtx)
}
889169
func (c *Collection) GetAndLock(key string, expiration uint32, opts *GetAndLockOptions) (docOut *GetResult, errOut error) {
	if opts == nil {
		opts = &GetAndLockOptions{}
	}

	span := c.startKvOpTrace(opts.ParentSpanContext, "GetAndLock")
	defer span.Finish()

	ctx, cancel := c.context(opts.Context, opts.Timeout)
	if cancel != nil {
		defer cancel()
	}

	res, err := c.getAndLock(ctx, span.Context(), key, expiration, *opts)
	if err != nil {
		return nil, err
	}

	return res, nil
}
513835
func (c *RemoteClient) unlock(id string) error {
	// this doesn't use the lock id, because the lock is tied to the consul client.
	if c.consulLock == nil || c.lockCh == nil {
		return nil
	}

	// cancel our monitoring goroutine
	c.monitorCancel()

	defer func() {
		c.consulLock = nil

		// The consul session is only used for this single lock, so cancel it
		// after we unlock.
		// The session is only created and replaced holding Client.mu, so the
		// CancelFunc must be non-nil.
		c.sessionCancel()
	}()

	select {
	case <-c.lockCh:
		return lostLockErr
	default:
	}

	kv := c.Client.KV()

	var errs error

	if _, err := kv.Delete(c.Path+lockInfoSuffix, nil); err != nil {
		errs = multierror.Append(errs, err)
	}

	if err := c.consulLock.Unlock(); err != nil {
		errs = multierror.Append(errs, err)
	}

	// the monitoring goroutine may be in a select on the lockCh, so we need to
	// wait for it to return before changing the value.
	c.monitorWG.Wait()
	c.lockCh = nil

	// This is only cleanup, and will fail if the lock was immediately taken by
	// another client, so we don't report an error to the user here.
	c.consulLock.Destroy()

	return errs
}
203447
func (m *timedMutex) Unlock() {
	unlockedTimestamp := m.lockedAt.Load()
	m.lockedAt.Store(time.Time{})
	m.Mutex.Unlock()
	lockedFor := time.Since(unlockedTimestamp.(time.Time))
	storeLockDurationTimer.Update(lockedFor)
}
192277
func (e *defaultStoreEnumerator) Unlock(token interface{}) error {
	v, ok := token.(*kvdb.KVPair)
	if !ok {
		return fmt.Errorf("Invalid token of type %T", token)
	}
	return e.kvdb.Unlock(v)
}
1072162
func (f *Facade) unlockTenant(ctx datastore.Context, tenantID string) (err error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.unlockTenant"))
	mutex := getTenantLock(tenantID)
	var svcs []service.ServiceDetails
	if svcs, err = f.GetServiceDetailsByTenantID(ctx, tenantID); err != nil {
		glog.Errorf("Could not get services for tenant %s: %s", tenantID, err)
		return
	}
	if err = f.zzk.UnlockServices(ctx, svcs); err != nil {
		glog.Errorf("Could not unlock services for tenant %s: %s", tenantID, err)
		return
	}
	mutex.Unlock()
	return
}
915608
func unlock() error {
	lock, err := getLockfile()
	if err != nil {
		return fmt.Errorf("[unlock] cannot init lockfile: %v", err)
	}
	err = lock.Unlock()
	if err != nil {
		return fmt.Errorf("[unlock] error releasing lock: %s", err)
	}
	logrus.Debugf("[unlock] lock released")
	daemonMutex.Unlock()
	return nil
}
636798
func (kl *keyLocker) Lock() Unlocker {
	lockRequest := newLockRequest(kl.key, LOCK)
	lockRequests <- lockRequest
	return <-lockRequest.response
}