// Unlock the specified post by a specific user. An error is returned if the
// post isn't defined or if there are other errors returned by the DBMS
331885
func (user *User) Unlock(post ExistingPost, users ...*User) error {
	if post == nil {
		return errors.New("Unable to unlock undefined post!")
	}

	switch post.(type) {
	case *UserPost:
		userPost := post.(*UserPost)
		if len(users) == 0 {
			return Db().Where(&UserPostLock{User: user.ID(), Hpid: userPost.ID()}).Delete(UserPostLock{})
		}
		for _, other := range users {
			err := Db().Where(&UserPostUserLock{From: user.ID(), To: other.ID(), Hpid: userPost.ID()}).Delete(UserPostUserLock{})
			if err != nil {
				return err
			}
		}
		return nil

	case *ProjectPost:
		projectPost := post.(*ProjectPost)
		if len(users) == 0 {
			return Db().Where(&ProjectPostLock{User: user.ID(), Hpid: projectPost.ID()}).Delete(ProjectPostLock{})
		}
		for _, other := range users {
			err := Db().Where(&ProjectPostUserLock{From: user.ID(), To: other.ID(), Hpid: projectPost.ID()}).Delete(ProjectPostUserLock{})
			if err != nil {
				return err
			}
		}
		return nil
	}

	return errors.New("Invalid post type " + reflect.TypeOf(post).String())
}
366450
func unlockAccounts(ctx *cli.Context, stack *node.Node) {
	var unlocks []string
	inputs := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",")
	for _, input := range inputs {
		if trimmed := strings.TrimSpace(input); trimmed != "" {
			unlocks = append(unlocks, trimmed)
		}
	}
	// Short circuit if there is no account to unlock.
	if len(unlocks) == 0 {
		return
	}
	// If insecure account unlocking is not allowed if node's APIs are exposed to external.
	// Print warning log to user and skip unlocking.
	if !stack.Config().InsecureUnlockAllowed && stack.Config().ExtRPCEnabled() {
		utils.Fatalf("Account unlock with HTTP access is forbidden!")
	}
	ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
	passwords := utils.MakePasswordList(ctx)
	for i, account := range unlocks {
		unlockAccount(ks, account, i, passwords)
	}
}
1238975
func (s *Server) unlock(ctx context.Context, lockPath string) error {
	s.mu.Lock()
	li, ok := s.locks[lockPath]
	s.mu.Unlock()
	if !ok {
		return vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "unlock: lock %v not held", lockPath)
	}

	// Try to unlock our lock. We will clean up our entry anyway.
	unlockErr := li.lock.Unlock()

	s.mu.Lock()
	delete(s.locks, lockPath)
	s.mu.Unlock()
	close(li.done)

	// Then try to remove the lock entirely. This will only work if
	// noone else has the lock.
	if err := li.lock.Destroy(); err != nil {
		// If someone else has the lock, we can't remove it,
		// but we don't need to.
		if err != api.ErrLockInUse {
			log.Warningf("failed to clean up lock file %v: %v", lockPath, err)
		}
	}

	return unlockErr
}
322766
func (sem *Sem) Post() error {
	ret := int(C.SDL_SemPost(sem.cptr()))
	if ret != 0 {
		return GetError()
	}
	return nil
}
1275988
func (dm *DRWMutex) Unlock() {

	// create temp array on stack
	locks := make([]string, dm.clnt.dNodeCount)

	{
		dm.m.Lock()
		defer dm.m.Unlock()

		// Check if minimally a single bool is set in the writeLocks array
		lockFound := false
		for _, uid := range dm.writeLocks {
			if isLocked(uid) {
				lockFound = true
				break
			}
		}
		if !lockFound {
			panic("Trying to Unlock() while no Lock() is active")
		}

		// Copy write locks to stack array
		copy(locks, dm.writeLocks[:])
		// Clear write locks array
		dm.writeLocks = make([]string, dm.clnt.dNodeCount)
	}

	isReadLock := false
	unlock(dm.clnt, locks, dm.Name, isReadLock)
}
1132774
func unlock_notify_wait(db *C.sqlite3) C.int {
	// It has to be a bufferred channel to not block in sqlite_unlock_notify
	// as sqlite_unlock_notify could invoke the callback before it returns.
	c := make(chan struct{}, 1)
	defer close(c)

	h := unt.add(c)
	defer unt.remove(h)

	pargv := C.malloc(C.sizeof_uint)
	defer C.free(pargv)

	argv := (*[1]uint)(pargv)
	argv[0] = h
	if rv := C.sqlite3_unlock_notify(db, (*[0]byte)(C.unlock_notify_callback), unsafe.Pointer(pargv)); rv != C.SQLITE_OK {
		return rv
	}

	<-c

	return C.SQLITE_OK
}
571536
func (t *TxSerializer) lockLocked(ctx context.Context, key, table string) (bool, error) {
	q, ok := t.queues[key]
	if !ok {
		// First transaction in the queue i.e. we don't wait and return immediately.
		t.queues[key] = newQueueForFirstTransaction(t.concurrentTransactions)
		t.globalSize++
		return false, nil
	}

	if t.globalSize >= t.maxGlobalQueueSize {
		if t.dryRun {
			globalQueueExceededDryRun.Add(1)
			t.logGlobalQueueExceededDryRun.Warningf("Would have rejected BeginExecute RPC because there are too many queued transactions (%d >= %d)", t.globalSize, t.maxGlobalQueueSize)
		} else {
			globalQueueExceeded.Add(1)
			return false, vterrors.Errorf(vtrpcpb.Code_RESOURCE_EXHAUSTED,
				"hot row protection: too many queued transactions (%d >= %d)", t.globalSize, t.maxGlobalQueueSize)
		}
	}

	if q.size >= t.maxQueueSize {
		if t.dryRun {
			queueExceededDryRun.Add(table, 1)
			t.logQueueExceededDryRun.Warningf("Would have rejected BeginExecute RPC because there are too many queued transactions (%d >= %d) for the same row (table + WHERE clause: '%v')", q.size, t.maxQueueSize, key)
		} else {
			queueExceeded.Add(table, 1)
			return false, vterrors.Errorf(vtrpcpb.Code_RESOURCE_EXHAUSTED,
				"hot row protection: too many queued transactions (%d >= %d) for the same row (table + WHERE clause: '%v')", q.size, t.maxQueueSize, key)
		}
	}

	if q.availableSlots == nil {
		// Hot row detected: A second, concurrent transaction is seen for the
		// first time.

		// As an optimization, we deferred the creation of the channel until now.
		q.availableSlots = make(chan struct{}, t.concurrentTransactions)
		q.availableSlots <- struct{}{}

		// Include first transaction in the count at /debug/hotrows. (It was not
		// recorded on purpose because it did not wait.)
		t.Record(key)
	}

	t.globalSize++
	q.size++
	q.count++
	if q.size > q.max {
		q.max = q.size
	}
	// Publish the number of waits at /debug/hotrows.
	t.Record(key)

	if t.dryRun {
		waitsDryRun.Add(table, 1)
		t.logWaitsDryRun.Warningf("Would have queued BeginExecute RPC for row (range): '%v' because another transaction to the same range is already in progress.", key)
		return false, nil
	}

	// Unlock before the wait and relock before returning because our caller
	// Wait() holds the lock and assumes it still has it.
	t.mu.Unlock()
	defer t.mu.Lock()

	// Non-blocking write attempt to get a slot.
	select {
	case q.availableSlots <- struct{}{}:
		// Return waited=false because a slot was immediately available.
		return false, nil
	default:
	}

	// Blocking wait for the next available slot.
	waits.Add(table, 1)
	select {
	case q.availableSlots <- struct{}{}:
		return true, nil
	case <-ctx.Done():
		return true, ctx.Err()
	}
}
1193257
func (scheduler *LatchesScheduler) UnLock(lock *Lock) {
	scheduler.RLock()
	defer scheduler.RUnlock()
	if !scheduler.closed {
		scheduler.unlockCh <- lock
	}
}
812628
func (m *RWMutex) Unlock() {
	m.mutex.Unlock()
	atomic.AddInt64(&m.writers, -1)
}
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
}
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
}
828525
func (mutex *Mutex) Unlock() error {
	ret := int(C.SDL_UnlockMutex(mutex.cptr()))
	if ret != 0 {
		return GetError()
	}
	return nil
}
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
}
288705
func (m *Mutex) Unlock() bool {
	n := m.actOnPoolsAsync(func(pool Pool) bool {
		return m.release(pool, m.value)
	})
	return n >= m.quorum
}
919559
func (u *UserPostUserLock) GetTO(users ...*User) *UserPostUserLockTO {
	var fromInfo, toInfo *InfoTO
	if from, e := NewUser(u.From); e == nil {
		fromInfo = from.Info().GetTO()
	}
	if to, e := NewUser(u.To); e == nil {
		toInfo = to.Info().GetTO()
	}
	return &UserPostUserLockTO{
		original:  u,
		FromInfo:  fromInfo,
		ToInfo:    toInfo,
		Hpid:      u.Hpid,
		Time:      u.Time,
		Timestamp: u.Time.Unix(),
		Counter:   u.Counter,
	}
}
485854
func (li *localLockInstance) Unlock() {
	readLock := false
	li.ns.unlock(li.volume, li.path, li.opsID, readLock)
}
1360046
func callPost(apiMethod string, params *apiParams, args P, result interface{}, rules P) (err error) {
	if err = requireAuth(params); err != nil {
		return
	}

	urlParams := url.Values{}
	uri := constructUrl(UriApiSecBase, urlParams)

	//post data
	postData := url.Values{}
	postData.Add("method", apiMethod)
	postData.Add("api_key", params.apikey)
	postData.Add("sk", params.sk)

	tmp := make(map[string]string)
	tmp["method"] = apiMethod
	tmp["api_key"] = params.apikey
	tmp["sk"] = params.sk

	formated, err := formatArgs(args, rules)
	for k, v := range formated {
		tmp[k] = v
		postData.Add(k, v)
	}

	sig := getSignature(tmp, params.secret)
	postData.Add("api_sig", sig)

	client := &http.Client{}
	req, err := http.NewRequest("POST", uri, strings.NewReader(postData.Encode()))
	if err != nil {
		return
	}
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	if params.useragent != "" {
		req.Header.Set("User-Agent", params.useragent)
	}

	res, err := client.Do(req)
	//res, err := http.PostForm(uri, postData)
	if err != nil {
		return
	}
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return
	}
	err = parseResponse(body, result)
	return
}