andlabs-ui/sysdatacache_windows.go

47 lines
870 B
Go
Raw Normal View History

// 11 february 2014
package main
import (
"fmt"
"sync"
)
// I need a way to get a sysData for a given HWND or a given HWND/control ID. So, this.
var (
sysDatas = map[_HWND]*sysData{}
sysDatasLock sync.Mutex
sysDataIDs = map[_HMENU]*sysData{}
2014-02-12 09:35:15 -06:00
sysDataIDsLock sync.Mutex
)
func addSysData(hwnd _HWND, s *sysData) {
sysDatasLock.Lock()
defer sysDatasLock.Unlock()
2014-02-12 09:35:15 -06:00
sysDatas[hwnd] = s
}
func addSysDataID(id _HMENU, s *sysData) {
2014-02-12 09:35:15 -06:00
sysDataIDsLock.Lock()
defer sysDataIDsLock.Unlock()
sysDataIDs[id] = s
}
func getSysData(hwnd _HWND) *sysData {
sysDatasLock.Lock()
defer sysDatasLock.Unlock()
if ss, ok := sysDatas[hwnd]; ok {
2014-02-12 09:35:15 -06:00
return ss
}
return nil
}
func getSysDataID(id _HMENU) *sysData {
2014-02-12 09:35:15 -06:00
sysDataIDsLock.Lock()
defer sysDataIDsLock.Unlock()
if ss, ok := sysDataIDs[id]; ok {
return ss
}
panic(fmt.Sprintf("getting nonexistent ID %d\n", id))
}