MCPcopy
hub / github.com/lxn/walk / CreateGroup

Method CreateGroup

windowgroup.go:43–74  ·  view source on GitHub ↗

CreateGroup returns a window group for the given thread ID. If one does not already exist, it will be created. The group will have its counter incremented as a result of this call. It is the caller's responsibility to call Done when finished with the group.

(threadID uint32)

Source from the content-addressed store, hash-verified

41// It is the caller's responsibility to call Done when finished with the
42// group.
43func (m *windowGroupManager) CreateGroup(threadID uint32) *WindowGroup {
44 // Fast path with read lock
45 m.mutex.RLock()
46 if m.groups != nil {
47 if group := m.groups[threadID]; group != nil {
48 m.mutex.RUnlock()
49 group.Add(1)
50 return group
51 }
52 }
53 m.mutex.RUnlock()
54
55 // Slow path with write lock
56 m.mutex.Lock()
57 if m.groups == nil {
58 m.groups = make(map[uint32]*WindowGroup)
59 } else {
60 if group := m.groups[threadID]; group != nil {
61 // Another caller raced with our lock and beat us
62 m.mutex.Unlock()
63 group.Add(1)
64 return group
65 }
66 }
67
68 group := newWindowGroup(threadID, m.removeGroup)
69 group.Add(1)
70 m.groups[threadID] = group
71 m.mutex.Unlock()
72
73 return group
74}
75
76// removeGroup is called by window groups to remove themselves from
77// the manager.

Callers 1

initWindowWithCfgFunction · 0.80

Calls 2

newWindowGroupFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected