You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.7 KiB
49 lines
1.7 KiB
package channels
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"strings"
|
|
"sync"
|
|
|
|
//wrap7 "git.archium.org/archium_Kunden/Wrap7"
|
|
wrap7 "git.archium.org/archium_public/ebkTools/bitmask"
|
|
)
|
|
|
|
type StatusChannelType = int
|
|
|
|
// grazeStatusChannel liest einen Wert aus dem StatusChannel, setzt, löscht oder liest ihn. Danach wird der Channel wieder neu geschrieben, damit alle anderen Jobs, die am Channel lauschen, nicht ins Stocken geraten.
|
|
func GrazeStatusChannel(sc *chan StatusChannelType, mode string, offset StatusChannelType, mtxStatusChannelLock *sync.Mutex) bool {
|
|
defer (*mtxStatusChannelLock).Unlock()
|
|
(*mtxStatusChannelLock).Lock()
|
|
cvalue, cstatus := <-*sc
|
|
if cstatus {
|
|
switch strings.ToLower(mode) {
|
|
case "set":
|
|
*sc <- StatusChannelType(wrap7.SetBit(int(cvalue), uint(offset)))
|
|
return true // Eigentlich wurscht, was ich hier zurückgebe, aber im Zweifel "true" = gesetzt
|
|
case "clear":
|
|
*sc <- StatusChannelType(wrap7.ClearBit(int(cvalue), uint(offset)))
|
|
return false // Eigentlich wurscht, was ich hier zurückgebe, aber im Zweifel "false" = nicht gesetzt
|
|
default: //case "has":
|
|
*sc <- cvalue
|
|
return wrap7.HasBit(int(cvalue), uint(offset))
|
|
}
|
|
} else {
|
|
_, fn, line, _ := runtime.Caller(2)
|
|
panic(fmt.Sprintf("Kein statusChannel? Eigentlich hätte der Programmzeiger niemals hier sein dürfen. %s:%d\n", fn, line))
|
|
}
|
|
}
|
|
|
|
func GetStatusChannel(sc *chan StatusChannelType, mtxStatusChannelLock *sync.Mutex) StatusChannelType {
|
|
defer (*mtxStatusChannelLock).Unlock()
|
|
(*mtxStatusChannelLock).Lock()
|
|
cvalue, cstatus := <-*sc
|
|
if cstatus {
|
|
*sc <- cvalue
|
|
return cvalue
|
|
} else {
|
|
_, fn, line, _ := runtime.Caller(2)
|
|
panic(fmt.Sprintf("Kein statusChannel? Eigentlich hätte der Programmzeiger niemals hier sein dürfen. %s:%d\n", fn, line))
|
|
}
|
|
}
|
|
|