本文整理汇总了Golang中github.com/ubuntu-core/snappy/overlord/state.State.Unlock方法的典型用法代码示例。如果您正苦于以下问题:Golang State.Unlock方法的具体用法?Golang State.Unlock怎么用?Golang State.Unlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ubuntu-core/snappy/overlord/state.State
的用法示例。
在下文中一共展示了State.Unlock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: allLocalSnapInfos
// allLocalSnapInfos returns the information about the all current snaps and their SnapStates.
func allLocalSnapInfos(st *state.State) ([]aboutSnap, error) {
st.Lock()
defer st.Unlock()
snapStates, err := snapstate.All(st)
if err != nil {
return nil, err
}
about := make([]aboutSnap, 0, len(snapStates))
var firstErr error
for name, snapState := range snapStates {
info, err := snap.ReadInfo(name, snapState.Current())
if err != nil {
// XXX: aggregate instead?
if firstErr == nil {
firstErr = err
}
continue
}
about = append(about, aboutSnap{info, snapState})
}
return about, firstErr
}
示例2: newRunnerManager
func newRunnerManager(s *state.State) *runnerManager {
rm := &runnerManager{
runner: state.NewTaskRunner(s),
}
rm.runner.AddHandler("runMgr1", func(t *state.Task, _ *tomb.Tomb) error {
s := t.State()
s.Lock()
defer s.Unlock()
s.Set("runMgr1Mark", 1)
return nil
}, nil)
rm.runner.AddHandler("runMgr2", func(t *state.Task, _ *tomb.Tomb) error {
s := t.State()
s.Lock()
defer s.Unlock()
s.Set("runMgr2Mark", 1)
return nil
}, nil)
rm.runner.AddHandler("runMgrEnsureBefore", func(t *state.Task, _ *tomb.Tomb) error {
s := t.State()
s.Lock()
defer s.Unlock()
s.EnsureBefore(20 * time.Millisecond)
return nil
}, nil)
return rm
}
示例3: localSnapInfo
// localSnapInfo returns the information about the current snap for the given name plus the SnapState with the active flag and other snap revisions.
func localSnapInfo(st *state.State, name string) (info *snap.Info, active bool, err error) {
st.Lock()
defer st.Unlock()
var snapst snapstate.SnapState
err = snapstate.Get(st, name, &snapst)
if err != nil && err != state.ErrNoState {
return nil, false, fmt.Errorf("cannot consult state: %v", err)
}
cur := snapst.Current()
if cur == nil {
return nil, false, nil
}
info, err = snap.ReadInfo(name, cur)
if err != nil {
return nil, false, fmt.Errorf("cannot read snap details: %v", err)
}
return info, snapst.Active, nil
}